This patch fixes compilation of libevent trunk on mingw for me. It defines a static function to make sockets nonblocking; Windows does not do this in the same way as standard sockets do. This function could probably be safely exported and used elsewhere.
yrs, -- Nick Mathewson
=== http.c ================================================================== --- http.c (revision 9826) +++ http.c (local) @@ -112,6 +112,28 @@ } #endif +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +static int +event_make_socket_nonblocking(int fd) +{ + +#ifdef WIN32 + { + unsigned long nonblocking = 1; + ioctlsocket(fd, FIONBIO, (unsigned long*) &nonblocking); + } +#else + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + event_warn("fcntl(O_NONBLOCK)"); + return -1; + } +#endif + return 0; +} + extern int debug; static int make_socket_ai(int should_bind, struct addrinfo *); @@ -1804,10 +1826,9 @@ event_warn("%s: bad accept", __func__); return; } - if (fcntl(nfd, F_SETFL, O_NONBLOCK) == -1) { - event_warn("fcntl(O_NONBLOCK)"); + if (event_make_socket_nonblocking(fd) < 0) return; - } + evhttp_get_request(http, nfd, (struct sockaddr *)&ss, addrlen); } @@ -2151,17 +2172,10 @@ return (-1); } -#ifdef WIN32 - { - unsigned long nonblocking = 1; - ioctlsocket(fd, FIONBIO, (unsigned long*) &nonblocking); - } -#else - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { - event_warn("fcntl(O_NONBLOCK)"); + if (event_make_socket_nonblocking(fd) < 0) goto out; - } +#ifndef WIN32 if (fcntl(fd, F_SETFD, 1) == -1) { event_warn("fcntl(F_SETFD)"); goto out;
pgpASVw7W480b.pgp
Description: PGP signature
_______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users