[vlc-commits] commit: Use vlc_accept() ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Wed Mar 31 18:29:51 CEST 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Mar 31 19:28:41 2010 +0300| [af64d14a00bbaca4c17b7f3feb7399d7a0363f23] | committer: Rémi Denis-Courmont
Use vlc_accept()
This should also fix the accept4() ENOSYS infinite loop in httpd
pointed out by Aurélion Nephtali.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=af64d14a00bbaca4c17b7f3feb7399d7a0363f23
---
include/vlc_network.h | 1 -
src/network/httpd.c | 10 ++++------
src/network/io.c | 14 --------------
src/network/tcp.c | 16 +++-------------
4 files changed, 7 insertions(+), 34 deletions(-)
diff --git a/include/vlc_network.h b/include/vlc_network.h
index 19502d2..8f938f6 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -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)
diff --git a/src/network/httpd.c b/src/network/httpd.c
index 8dbdbf5..2a92dce 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -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 ) )
diff --git a/src/network/io.c b/src/network/io.c
index 69b1e0b..fddac63 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -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)
{
diff --git a/src/network/tcp.c b/src/network/tcp.c
index adbd460..9c35f16 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -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;
}
More information about the vlc-commits
mailing list