add socket_set_nonblocking

This commit is contained in:
Love Hornquist Astrand
2012-12-20 12:03:54 +01:00
parent 6a442d5df9
commit 087c859db6
2 changed files with 27 additions and 0 deletions

View File

@@ -401,6 +401,10 @@ socket_set_debug (rk_socket_t);
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_tos (rk_socket_t, int);
#define socket_set_nonblocking rk_socket_set_nonblocking
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_nonblocking(rk_socket_t, int);
#define socket_set_reuseaddr rk_socket_set_reuseaddr
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_reuseaddr (rk_socket_t, int);

View File

@@ -259,6 +259,29 @@ socket_set_tos (rk_socket_t sock, int tos)
#endif
}
/*
* Set the non-blocking-ness of the socket.
*/
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_nonblocking(rk_socket_t sock, int nonblock)
{
int flags;
#if defined(O_NONBLOCK)
flags = fcntl(sock, F_GETFL, 0);
if (flags == -1)
return;
if (nonblock)
flags |= O_NONBLOCK;
else
flags &= ~O_NONBLOCK;
fcntl(sock, F_SETFL, flags);
#elif defined(FIOBIO)
flags = !!nonblock;
return ioctl(sock, FIOBIO, &flags);
#endif
}
/*
* set the reuse of addresses on `sock' to `val'.
*/