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

vlc_accept: accept() with close-on-exec

parent eb1988c9
...@@ -54,6 +54,9 @@ VLC_EXPORT( int, vlc_lstat, ( const char *filename, struct stat *buf ) ); ...@@ -54,6 +54,9 @@ VLC_EXPORT( int, vlc_lstat, ( const char *filename, struct stat *buf ) );
VLC_EXPORT( int, vlc_mkstemp, ( char * ) ); VLC_EXPORT( int, vlc_mkstemp, ( char * ) );
VLC_EXPORT( int, vlc_dup, ( int ) ); VLC_EXPORT( int, vlc_dup, ( int ) );
int vlc_socket (int, int, int, bool nonblock); int vlc_socket (int, int, int, bool nonblock) LIBVLC_USED;
struct sockaddr;
VLC_EXPORT( int, vlc_accept, ( int, struct sockaddr *, socklen_t *, bool ) LIBVLC_USED );
#endif #endif
...@@ -445,6 +445,7 @@ vlc_stat ...@@ -445,6 +445,7 @@ vlc_stat
vlc_unlink vlc_unlink
vlc_rename vlc_rename
vlc_dup vlc_dup
vlc_accept
utf8_vfprintf utf8_vfprintf
var_AddCallback var_AddCallback
var_Change var_Change
......
...@@ -655,3 +655,45 @@ int vlc_socket (int pf, int type, int proto, bool nonblock) ...@@ -655,3 +655,45 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
#endif #endif
return fd; return fd;
} }
/**
* Accepts an inbound connection request on a listening socket.
* The new file descriptor has the close-on-exec flag set.
* @param lfd listening socket file descriptor
* @param addr pointer to the peer address or NULL [OUT]
* @param alen pointer to the length of the peer address or NULL [OUT]
* @param nonblock whether to put the new socket in non-blocking mode
* @return a new file descriptor, or -1 on error.
*/
int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
{
#ifdef HAVE_ACCEPT4
int flags = SOCK_CLOEXEC;
if (nonblock)
flags |= SOCK_NONBLOCK;
do
{
int fd = accept4 (lfd, addr, alen, flags);
if (fd != -1)
return fd;
}
while (errno == EINTR);
if (errno != ENOSYS)
return -1;
#endif
#ifdef WIN32
errno = 0;
#endif
do
{
int fd = accept (lfd, addr, alen);
if (fd != -1)
return fd;
}
while (errno == EINTR);
return -1;
}
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