Commit af64d14a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

Use vlc_accept()

This should also fix the accept4() ENOSYS infinite loop in httpd
pointed out by Aurélion Nephtali.
parent a2f2d51d
......@@ -83,7 +83,6 @@ extern "C" {
/* Portable networking layer communication */
int net_Socket (vlc_object_t *obj, int family, int socktype, int proto);
int net_SetupSocket (int fd);
VLC_EXPORT( int, net_Connect, (vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol) );
#define net_Connect(a, b, c, d, e) net_Connect(VLC_OBJECT(a), b, c, d, e)
......
......@@ -33,6 +33,7 @@
#include <assert.h>
#include <vlc_network.h>
#include <vlc_fs.h>
#include <vlc_tls.h>
#include <vlc_acl.h>
#include <vlc_strings.h>
......@@ -2515,15 +2516,12 @@ static void* httpd_HostThread( void *data )
continue;
/* */
#ifdef HAVE_ACCEPT4
fd = accept4 (fd, NULL, NULL, SOCK_CLOEXEC);
if (fd == -1 && errno == ENOSYS)
#endif
fd = accept (fd, NULL, NULL);
fd = vlc_accept (fd, NULL, NULL, true);
if (fd == -1)
continue;
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
&(int){ 1 }, sizeof(int));
net_SetupSocket (fd);
if( p_tls != NULL )
{
switch( tls_ServerSessionHandshake( p_tls, fd ) )
......
......@@ -77,20 +77,6 @@
extern int rootwrap_bind (int family, int socktype, int protocol,
const struct sockaddr *addr, size_t alen);
int net_SetupSocket (int fd)
{
#if defined (WIN32) || defined (UNDER_CE)
ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
#else
fcntl (fd, F_SETFD, FD_CLOEXEC);
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
#endif
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
return 0;
}
int net_Socket (vlc_object_t *p_this, int family, int socktype,
int protocol)
{
......
......@@ -43,6 +43,7 @@
#endif
#include <vlc_network.h>
#include <vlc_fs.h>
#if defined (WIN32) || defined (UNDER_CE)
# undef EINPROGRESS
# define EINPROGRESS WSAEWOULDBLOCK
......@@ -244,18 +245,7 @@ next_ai: /* failure */
int net_AcceptSingle (vlc_object_t *obj, int lfd)
{
int fd;
do
{
#ifdef HAVE_ACCEPT4
fd = accept4 (lfd, NULL, NULL, SOCK_CLOEXEC);
if (fd == -1 && errno == ENOSYS)
#endif
fd = accept (lfd, NULL, NULL);
}
while (fd == -1 && errno == EINTR);
int fd = vlc_accept (lfd, NULL, NULL, true);
if (fd == -1)
{
if (net_errno != EAGAIN && net_errno != EWOULDBLOCK)
......@@ -264,7 +254,7 @@ int net_AcceptSingle (vlc_object_t *obj, int lfd)
}
msg_Dbg (obj, "accepted socket %d (from socket %d)", fd, lfd);
net_SetupSocket (fd);
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
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