Commit cc227c72 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Set non-blocking mode on accepted sockets

parent 370f789f
...@@ -86,6 +86,9 @@ static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int por ...@@ -86,6 +86,9 @@ static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int por
return __net_Connect (obj, host, port, SOCK_STREAM, IPPROTO_TCP); return __net_Connect (obj, host, port, SOCK_STREAM, IPPROTO_TCP);
} }
VLC_EXPORT( int, net_AcceptSingle, (vlc_object_t *obj, int lfd) );
#define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c) #define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) ); VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
......
...@@ -490,7 +490,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -490,7 +490,7 @@ static void Run( intf_thread_t *p_intf )
if (ufd[ncli + i].revents == 0) if (ufd[ncli + i].revents == 0)
continue; continue;
fd = accept (ufd[ncli + i].fd, NULL, NULL); fd = net_AcceptSingle (VLC_OBJECT(p_intf), ufd[ncli + i].fd);
if (fd == -1) if (fd == -1)
continue; continue;
......
...@@ -2509,17 +2509,19 @@ static void httpd_HostThread( httpd_host_t *host ) ...@@ -2509,17 +2509,19 @@ static void httpd_HostThread( httpd_host_t *host )
{ {
httpd_client_t *cl; httpd_client_t *cl;
int i_state = -1; int i_state = -1;
int fd = ufd[nfd].fd;
assert (ufd[nfd].fd == host->fds[nfd]); assert (fd == host->fds[nfd]);
if( ufd[nfd].revents == 0 ) if( ufd[nfd].revents == 0 )
continue; continue;
/* */ /* */
int fd = accept (ufd[nfd].fd, NULL, NULL); fd = accept (fd, NULL, NULL);
if (fd == -1) if (fd == -1)
continue; continue;
net_SetupSocket (fd);
if( p_tls != NULL ) if( p_tls != NULL )
{ {
switch( tls_ServerSessionHandshake( p_tls, fd ) ) switch( tls_ServerSessionHandshake( p_tls, fd ) )
......
...@@ -258,6 +258,22 @@ next_ai: /* failure */ ...@@ -258,6 +258,22 @@ next_ai: /* failure */
} }
int net_AcceptSingle (vlc_object_t *obj, int lfd)
{
int fd = accept (lfd, NULL, NULL);
if (fd == -1)
{
if (net_errno != EAGAIN)
msg_Err (obj, "accept failed (from socket %d): %m", lfd);
return -1;
}
msg_Dbg (obj, "accepted socket %d (from socket %d)", fd, lfd);
net_SetupSocket (fd);
return 0;
}
/***************************************************************************** /*****************************************************************************
* __net_Accept: * __net_Accept:
***************************************************************************** *****************************************************************************
...@@ -312,13 +328,9 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait ) ...@@ -312,13 +328,9 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
continue; continue;
int sfd = ufd[i].fd; int sfd = ufd[i].fd;
int fd = accept (sfd, NULL, NULL); int fd = net_AcceptSingle (p_this, sfd);
if (fd == -1) if (fd == -1)
{
msg_Err (p_this, "accept failed (%m)");
continue; continue;
}
net_SetupSocket (fd);
/* /*
* Move listening socket to the end to let the others in the * Move listening socket to the end to let the others in the
...@@ -327,7 +339,6 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait ) ...@@ -327,7 +339,6 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1)); memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1));
pi_fd[n - 1] = sfd; pi_fd[n - 1] = sfd;
vlc_object_unlock (p_this); vlc_object_unlock (p_this);
msg_Dbg (p_this, "accepted socket %d (from socket %d)", fd, sfd);
return fd; return fd;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment