aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_sockets.c')
-rw-r--r--src/microhttpd/mhd_sockets.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index 640c59e3..21e265f6 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -25,6 +25,10 @@
25 */ 25 */
26 26
27#include "mhd_sockets.h" 27#include "mhd_sockets.h"
28#ifdef HAVE_UNISTD_H
29#include <unistd.h>
30#endif /* HAVE_UNISTD_H */
31#include <fcntl.h>
28 32
29#ifdef MHD_WINSOCK_SOCKETS 33#ifdef MHD_WINSOCK_SOCKETS
30 34
@@ -264,3 +268,32 @@ MHD_add_to_fd_set_ (MHD_socket fd,
264 268
265 return !0; 269 return !0;
266} 270}
271
272
273/**
274 * Change socket options to be non-blocking.
275 *
276 * @param sock socket to manipulate
277 * @return non-zero if succeeded, zero otherwise
278 */
279int
280MHD_socket_nonblocking_ (MHD_socket sock)
281{
282#if defined(MHD_POSIX_SOCKETS)
283 int flags;
284
285 flags = fcntl (sock, F_GETFL);
286 if (-1 == flags)
287 return 0;
288
289 if ( ((flags | O_NONBLOCK) != flags) &&
290 (0 != fcntl (sock, F_SETFL, flags | O_NONBLOCK)) )
291 return 0;
292#elif defined(MHD_WINSOCK_SOCKETS)
293 unsigned long flags = 1;
294
295 if (0 != ioctlsocket (sock, FIONBIO, &flags))
296 return 0;
297#endif /* MHD_WINSOCK_SOCKETS */
298 return !0;
299}