[vlc-devel] commit: net_Accept: remove timeout parameter ( Rémi Denis-Courmont )
git version control
git at videolan.org
Mon Oct 5 17:44:18 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Oct 5 18:43:26 2009 +0300| [84e1b303e36f5159eab5dce8291a5348837b99f0] | committer: Rémi Denis-Courmont
net_Accept: remove timeout parameter
Only the RC interface still used it, and it was not really needed
(net_Accept() returns -1 when the object is killed).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=84e1b303e36f5159eab5dce8291a5348837b99f0
---
include/vlc_network.h | 6 ++--
modules/access/rtmp/access.c | 2 +-
modules/access_output/rtmp.c | 2 +-
modules/control/rc.c | 3 +-
modules/misc/lua/libs/net.c | 3 +-
modules/stream_out/rtp.c | 2 +-
src/libvlccore.sym | 2 +-
src/network/tcp.c | 71 ++++++++++++++++++++++--------------------
8 files changed, 46 insertions(+), 45 deletions(-)
diff --git a/include/vlc_network.h b/include/vlc_network.h
index c3cc983..f1befae 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -101,9 +101,9 @@ static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int por
VLC_EXPORT( int, net_AcceptSingle, (vlc_object_t *obj, int lfd) );
-VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
-#define net_Accept(a, b, c) \
- __net_Accept(VLC_OBJECT(a), b, (c == -1) ? -1 : (c ? check_delay(c) : 0))
+VLC_EXPORT( int, net_Accept, ( vlc_object_t *, int * ) );
+#define net_Accept(a, b) \
+ net_Accept(VLC_OBJECT(a), b)
#define net_ConnectDgram(a, b, c, d, e ) __net_ConnectDgram(VLC_OBJECT(a), b, c, d, e)
VLC_EXPORT( int, __net_ConnectDgram, ( vlc_object_t *p_this, const char *psz_host, int i_port, int hlim, int proto ) );
diff --git a/modules/access/rtmp/access.c b/modules/access/rtmp/access.c
index c9a076b..910ed53 100644
--- a/modules/access/rtmp/access.c
+++ b/modules/access/rtmp/access.c
@@ -202,7 +202,7 @@ static int Open( vlc_object_t *p_this )
goto error2;
}
- p_sys->p_thread->fd = net_Accept( p_access, p_fd_listen, -1 );
+ p_sys->p_thread->fd = net_Accept( p_access, p_fd_listen );
net_ListenClose( p_fd_listen );
diff --git a/modules/access_output/rtmp.c b/modules/access_output/rtmp.c
index eac532b..b49181a 100644
--- a/modules/access_output/rtmp.c
+++ b/modules/access_output/rtmp.c
@@ -205,7 +205,7 @@ static int Open( vlc_object_t *p_this )
}
do
- p_sys->p_thread->fd = net_Accept( p_access, p_fd_listen, -1 );
+ p_sys->p_thread->fd = net_Accept( p_access, p_fd_listen );
while( p_sys->p_thread->fd == -1 );
net_ListenClose( p_fd_listen );
diff --git a/modules/control/rc.c b/modules/control/rc.c
index 8e61ee9..b42c054 100644
--- a/modules/control/rc.c
+++ b/modules/control/rc.c
@@ -484,8 +484,7 @@ static void Run( intf_thread_t *p_intf )
p_intf->p_sys->i_socket == -1 )
{
p_intf->p_sys->i_socket =
- net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
- INTF_IDLE_SLEEP );
+ net_Accept( p_intf, p_intf->p_sys->pi_socket_listen );
if( p_intf->p_sys->i_socket == -1 ) continue;
}
diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c
index dcf2166..321da9e 100644
--- a/modules/misc/lua/libs/net.c
+++ b/modules/misc/lua/libs/net.c
@@ -121,8 +121,7 @@ static int vlclua_net_accept( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
- mtime_t i_wait = luaL_optint( L, 2, -1 ); /* default to block */
- int i_fd = net_Accept( p_this, *ppi_fd, i_wait );
+ int i_fd = net_Accept( p_this, *ppi_fd );
lua_pushinteger( L, i_fd );
return 1;
}
diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 590e8d0..e54ef06 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -1590,7 +1590,7 @@ static void *rtp_listen_thread( void *data )
for( ;; )
{
- int fd = net_Accept( id, id->listen.fd, -1 );
+ int fd = net_Accept( id, id->listen.fd );
if( fd == -1 )
continue;
int canc = vlc_savecancel( );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 7590fdc..2f39016 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -249,7 +249,7 @@ msg_Unsubscribe
msleep
mstrtime
mwait
-__net_Accept
+net_Accept
net_AcceptSingle
__net_Connect
__net_ConnectDgram
diff --git a/src/network/tcp.c b/src/network/tcp.c
index 537c4f9..4297a20 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -272,49 +272,46 @@ int net_AcceptSingle (vlc_object_t *obj, int lfd)
}
-/*****************************************************************************
- * __net_Accept:
- *****************************************************************************
- * Accept a connection on a set of listening sockets and return it
- *****************************************************************************/
-int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
+#undef net_Accept
+/**
+ * Accepts an new connection on a set of listening sockets.
+ * If there are no pending connections, this function will wait.
+ * @note If the thread needs to handle events other than incoming connections,
+ * you need to use poll() and net_AcceptSingle() instead.
+ *
+ * @param p_this VLC object for logging and object kill signal
+ * @param pi_fd listening socket set
+ * @return -1 on error (may be transient error due to network issues),
+ * a new socket descriptor on success.
+ */
+int net_Accept (vlc_object_t *p_this, int *pi_fd)
{
- int timeout = (i_wait < 0) ? -1 : i_wait / 1000;
int evfd = vlc_object_waitpipe (p_this);
- assert( pi_fd != NULL );
+ assert (pi_fd != NULL);
- for (;;)
- {
- unsigned n = 0;
- while (pi_fd[n] != -1)
- n++;
- struct pollfd ufd[n + 1];
+ unsigned n = 0;
+ while (pi_fd[n] != -1)
+ n++;
+ struct pollfd ufd[n + 1];
- /* Initialize file descriptor set */
- for (unsigned i = 0; i <= n; i++)
- {
- ufd[i].fd = (i < n) ? pi_fd[i] : evfd;
- ufd[i].events = POLLIN;
- ufd[i].revents = 0;
- }
+ /* Initialize file descriptor set */
+ for (unsigned i = 0; i <= n; i++)
+ {
+ ufd[i].fd = (i < n) ? pi_fd[i] : evfd;
+ ufd[i].events = POLLIN;
+ }
+ ufd[n].revents = 0;
- switch (poll (ufd, n + (evfd != -1), timeout))
+ for (;;)
+ {
+ while (poll (ufd, n + (evfd != -1), -1) == -1)
{
- case -1:
- if (net_errno == EINTR)
- continue;
+ if (net_errno != EINTR)
+ {
msg_Err (p_this, "poll error: %m");
return -1;
- case 0:
- errno = ETIMEDOUT;
- return -1;
- }
-
- if (ufd[n].revents)
- {
- errno = EINTR;
- break;
+ }
}
for (unsigned i = 0; i < n; i++)
@@ -335,6 +332,12 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
pi_fd[n - 1] = sfd;
return fd;
}
+
+ if (ufd[n].revents)
+ {
+ errno = EINTR;
+ break;
+ }
}
return -1;
}
More information about the vlc-devel
mailing list