/* 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)
#include <assert.h>
#include <vlc_network.h>
+#include <vlc_fs.h>
#include <vlc_tls.h>
#include <vlc_acl.h>
#include <vlc_strings.h>
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 ) )
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)
{
#endif
#include <vlc_network.h>
+#include <vlc_fs.h>
#if defined (WIN32) || defined (UNDER_CE)
# undef EINPROGRESS
# define EINPROGRESS WSAEWOULDBLOCK
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)
}
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;
}