From 439f41149b34f4df4feb19bc7063f30831835022 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Fri, 3 Nov 2017 16:42:38 +0100 Subject: [PATCH] Last rename + explicit EMFILE check replacement --- src/anchor.c | 4 ++-- src/extension/select_eventloop.c | 2 +- src/platform.h | 2 +- src/server.c | 10 +++++----- src/stub.c | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/anchor.c b/src/anchor.c index 7f992a5c..006e5da4 100644 --- a/src/anchor.c +++ b/src/anchor.c @@ -1199,7 +1199,7 @@ static void tas_read_cb(void *userarg) return; } } - } else if (_getdns_socket_wants_retry()) + } else if (_getdns_socketerror_wants_retry()) return; DEBUG_ANCHOR("Read error: %d %s\n", (int)n, _getdns_errnostr()); @@ -1249,7 +1249,7 @@ static void tas_write_cb(void *userarg) tas_read_cb, NULL, tas_timeout_cb)); return; - } else if (_getdns_socket_wants_retry()) + } else if (_getdns_socketerror_wants_retry()) return; DEBUG_ANCHOR("Write error: %s\n", _getdns_errnostr()); diff --git a/src/extension/select_eventloop.c b/src/extension/select_eventloop.c index 2b0ddf21..7855c21d 100644 --- a/src/extension/select_eventloop.c +++ b/src/extension/select_eventloop.c @@ -245,7 +245,7 @@ select_eventloop_run_once(getdns_eventloop *loop, int blocking) #endif if (select(max_fd + 1, &readfds, &writefds, NULL, (timeout == TIMEOUT_FOREVER ? NULL : &tv)) < 0) { - if (_getdns_socket_wants_retry()) + if (_getdns_socketerror_wants_retry()) return; DEBUG_SCHED("I/O error with select(): %s\n", _getdns_errnostr()); diff --git a/src/platform.h b/src/platform.h index ffff4c97..ddfb9575 100644 --- a/src/platform.h +++ b/src/platform.h @@ -143,7 +143,7 @@ void _getdns_perror(const char *str); || (X) == _getdns_EWOULDBLOCK \ || (X) == _getdns_EINPROGRESS \ || (X) == _getdns_ENOBUFS )) -#define _getdns_socket_wants_retry() (_getdns_error_wants_retry(_getdns_socketerror())) +#define _getdns_socketerror_wants_retry() (_getdns_error_wants_retry(_getdns_socketerror())) #define _getdns_resource_depletion() ( _getdns_socketerror() != 0 \ && ( _getdns_socketerror() == _getdns_ENFILE \ || _getdns_socketerror() == _getdns_EMFILE )) diff --git a/src/server.c b/src/server.c index 7bbda6eb..ef5676f8 100644 --- a/src/server.c +++ b/src/server.c @@ -191,7 +191,7 @@ static void tcp_write_cb(void *userarg) (const void *)&to_write->write_buf[to_write->written], to_write->write_buf_len - to_write->written, 0)) == -1) { - if (_getdns_socket_wants_retry()) + if (_getdns_socketerror_wants_retry()) return; DEBUG_SERVER("I/O error from send(): %s\n", @@ -287,7 +287,7 @@ getdns_reply( if (conn->l->fd >= 0 && sendto(conn->l->fd, (void *)buf, len, 0, (struct sockaddr *)&conn->remote_in, conn->addrlen) == -1) { - /* TODO: handle _getdns_socket_wants_retry() */ + /* TODO: handle _getdns_socketerror_wants_retry() */ /* IO error, never cleanup a listener because of I/O error */ DEBUG_SERVER("I/O error from sendto(): %s\n", @@ -371,7 +371,7 @@ static void tcp_read_cb(void *userarg) if ((bytes_read = recv(conn->fd, (void *)conn->read_pos, conn->to_read, 0)) < 0) { - if (_getdns_socket_wants_retry()) + if (_getdns_socketerror_wants_retry()) return; /* Come back to do the read later */ /* IO error, close connection */ @@ -486,7 +486,7 @@ static void tcp_accept_cb(void *userarg) if ((conn->fd = accept(l->fd, (struct sockaddr *) &conn->super.remote_in, &conn->super.addrlen)) == -1) { - if (_getdns_socket_wants_retry() || + if (_getdns_socketerror_wants_retry() || _getdns_socketerror() == _getdns_ECONNRESET) ; /* pass */ @@ -564,7 +564,7 @@ static void udp_read_cb(void *userarg) conn->addrlen = sizeof(conn->remote_in); if ((len = recvfrom(l->fd, (void *)buf, sizeof(buf), 0, (struct sockaddr *)&conn->remote_in, &conn->addrlen)) == -1) { - if ( _getdns_socket_wants_retry() && + if ( _getdns_socketerror_wants_retry() && _getdns_socketerror() != _getdns_ECONNRESET) { /* * WINSOCK gives ECONNRESET on ICMP Port Unreachable diff --git a/src/stub.c b/src/stub.c index bb46e5b0..10745928 100644 --- a/src/stub.c +++ b/src/stub.c @@ -638,7 +638,7 @@ stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf) } read = recv(fd, (void *)tcp->read_pos, tcp->to_read, 0); if (read < 0) { - if (_getdns_socket_wants_retry()) + if (_getdns_socketerror_wants_retry()) return STUB_TCP_RETRY; else return STUB_TCP_ERROR; @@ -756,7 +756,7 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq) (struct sockaddr *)&(netreq->upstream->addr), netreq->upstream->addr_len); #endif - if ((written == -1 && _getdns_socket_wants_retry()) || + if ((written == -1 && _getdns_socketerror_wants_retry()) || (size_t)written < pkt_len + 2) { /* We couldn't write the whole packet. @@ -788,7 +788,7 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq) written = send(fd, (void *)(tcp->write_buf + tcp->written), tcp->write_buf_len - tcp->written, 0); if (written == -1) { - if (_getdns_socket_wants_retry()) + if (_getdns_socketerror_wants_retry()) return STUB_TCP_RETRY; else { DEBUG_STUB("%s %-35s: MSG: %p error while writing to TCP socket:" @@ -1331,7 +1331,7 @@ stub_udp_read_cb(void *userarg) * i.e. overflow */ 0, NULL, NULL); - if (read == -1 && (_getdns_socket_wants_retry() || + if (read == -1 && (_getdns_socketerror_wants_retry() || _getdns_socketerror() == _getdns_ECONNRESET)) return; /* Try again later */ @@ -2060,7 +2060,7 @@ upstream_find_for_netreq(getdns_network_req *netreq) continue; if (fd == -1) { - if (_getdns_socketerror() == _getdns_EMFILE) + if (_getdns_resource_depletion()) return STUB_TRY_AGAIN_LATER; return -1; }