diff --git a/lib/roken/roken-common.h b/lib/roken/roken-common.h index a819d510d..02122be49 100644 --- a/lib/roken/roken-common.h +++ b/lib/roken/roken-common.h @@ -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); diff --git a/lib/roken/socket.c b/lib/roken/socket.c index 017d6252e..65aea15b5 100644 --- a/lib/roken/socket.c +++ b/lib/roken/socket.c @@ -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'. */