From bfb9f44f370ab0afa230f9e7795236043da7a5ea Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Fri, 9 Feb 2007 07:49:55 +0000 Subject: [PATCH] make mingw happy; from Nick Mathewson svn:r322 --- http.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/http.c b/http.c index 0e29ec65..62ab505d 100644 --- a/http.c +++ b/http.c @@ -112,6 +112,28 @@ fake_freeaddrinfo(struct addrinfo *ai) } #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 @@ accept_socket(int fd, short what, void *arg) 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 @@ make_socket_ai(int should_bind, struct addrinfo *ai) 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; -- 2.40.0