From 81ab45add511fd02ac08924841ec811186b3e4bb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 13 Jan 2009 19:20:04 +0000 Subject: [PATCH] Use new EVUTIL_ERR_*_RETRIABLE macros when we're testing an errno for blocking. Previously, we used inconsistent and incompletely ported ifdefs. (We don't use these macros in platform-specific files like evpoll.c, since they don't need to work on win32.) svn:r995 --- bufferevent.c | 22 ++++++++-------------- evdns.c | 21 +++++++++------------ http.c | 16 +++++----------- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/bufferevent.c b/bufferevent.c index 4082f53f..32e63b83 100644 --- a/bufferevent.c +++ b/bufferevent.c @@ -56,6 +56,7 @@ #include "log.h" #include "mm-internal.h" #include "bufferevent-internal.h" +#include "util-internal.h" /* prototypes */ @@ -171,7 +172,8 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg) res = evbuffer_read(input, fd, howmuch); if (res == -1) { - if (errno == EAGAIN || errno == EINTR) + int err = evutil_socket_geterror(fd); + if (EVUTIL_ERR_RW_RETRIABLE(err)) goto reschedule; /* error case */ what |= EVBUFFER_ERROR; @@ -226,20 +228,12 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) if (EVBUFFER_LENGTH(bufev->output)) { res = evbuffer_write(bufev->output, fd); if (res == -1) { -#ifndef WIN32 -/*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not - *set errno. thus this error checking is not portable*/ - if (errno == EAGAIN || - errno == EINTR || - errno == EINPROGRESS) - goto reschedule; - /* error case */ - what |= EVBUFFER_ERROR; - -#else + int err = evutil_socket_geterror(fd); + /* XXXX we used to check for EINPROGRESS here too, but I + don't think write can set that. -nick */ + if (EVUTIL_ERR_RW_RETRIABLE(err)) goto reschedule; -#endif - + what |= EVBUFFER_ERROR; } else if (res == 0) { /* eof case */ what |= EVBUFFER_EOF; diff --git a/evdns.c b/evdns.c index 391c32d1..444e01c4 100644 --- a/evdns.c +++ b/evdns.c @@ -105,6 +105,7 @@ #include "mm-internal.h" #include "strlcpy-internal.h" #include "ipv6-internal.h" +#include "util-internal.h" #ifdef WIN32 #include #include @@ -361,11 +362,6 @@ static int strtoint(const char *const str); #ifdef WIN32 static int -error_is_eagain(int err) -{ - return err == EAGAIN || err == WSAEWOULDBLOCK; -} -static int inet_aton(const char *c, struct in_addr *addr) { ev_uint32_t r; @@ -379,8 +375,6 @@ inet_aton(const char *c, struct in_addr *addr) } return 1; } -#else -#define error_is_eagain(err) ((err) == EAGAIN) #endif #define CLOSE_SOCKET(s) EVUTIL_CLOSESOCKET(s) @@ -1246,7 +1240,8 @@ nameserver_read(struct nameserver *ns) { const int r = recv(ns->socket, packet, sizeof(packet), 0); if (r < 0) { int err = evutil_socket_geterror(ns->socket); - if (error_is_eagain(err)) return; + if (EVUTIL_ERR_RW_RETRIABLE(err)) + return; nameserver_failed(ns, evutil_socket_error_to_string(err)); return; } @@ -1270,7 +1265,8 @@ server_port_read(struct evdns_server_port *s) { (struct sockaddr*) &addr, &addrlen); if (r < 0) { int err = evutil_socket_geterror(s->socket); - if (error_is_eagain(err)) return; + if (EVUTIL_ERR_RW_RETRIABLE(err)) + return; log(EVDNS_LOG_WARN, "Error %s (%d) while reading request.", evutil_socket_error_to_string(err), err); return; @@ -1289,7 +1285,7 @@ server_port_flush(struct evdns_server_port *port) (struct sockaddr*) &req->addr, req->addrlen); if (r < 0) { int err = evutil_socket_geterror(port->socket); - if (error_is_eagain(err)) + if (EVUTIL_ERR_RW_RETRIABLE(err)) return; log(EVDNS_LOG_WARN, "Error %s (%d) while writing response to port; dropping", evutil_socket_error_to_string(err), err); } @@ -1821,7 +1817,7 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err) (struct sockaddr*) &req->addr, req->addrlen); if (r<0) { int sock_err = evutil_socket_geterror(port->socket); - if (! error_is_eagain(sock_err)) + if (EVUTIL_ERR_RW_RETRIABLE(sock_err)) return -1; if (port->pending_replies) { @@ -1999,7 +1995,8 @@ evdns_request_transmit_to(struct evdns_request *req, struct nameserver *server) const int r = send(server->socket, req->request, req->request_len, 0); if (r < 0) { int err = evutil_socket_geterror(server->socket); - if (error_is_eagain(err)) return 1; + if (EVUTIL_ERR_RW_RETRIABLE(err)) + return 1; nameserver_failed(req->ns, evutil_socket_error_to_string(err)); return 2; } else if (r != (int)req->request_len) { diff --git a/http.c b/http.c index 768cc8ad..86844742 100644 --- a/http.c +++ b/http.c @@ -94,6 +94,7 @@ #include "log.h" #include "http-internal.h" #include "mm-internal.h" +#include "util-internal.h" #ifdef WIN32 #define strcasecmp _stricmp @@ -2320,7 +2321,8 @@ accept_socket(evutil_socket_t fd, short what, void *arg) evutil_socket_t nfd; if ((nfd = accept(fd, (struct sockaddr *)&ss, &addrlen)) == -1) { - if (errno != EAGAIN && errno != EINTR) + int err = evutil_socket_geterror(fd); + if (! EVUTIL_ERR_ACCEPT_RETRIABLE(err)) event_warn("%s: bad accept", __func__); return; } @@ -2972,17 +2974,9 @@ socket_connect(evutil_socket_t fd, const char *address, unsigned short port) } if (connect(fd, ai->ai_addr, ai->ai_addrlen) == -1) { -#ifdef WIN32 - int tmp_error = WSAGetLastError(); - if (tmp_error != WSAEWOULDBLOCK && tmp_error != WSAEINVAL && - tmp_error != WSAEINPROGRESS) { - goto out; - } -#else - if (errno != EINPROGRESS) { + int err = evutil_socket_geterror(fd); + if (! EVUTIL_ERR_CONNECT_RETRIABLE(err)) goto out; - } -#endif } /* everything is fine */ -- 2.40.0