diff options
author | William Ahern <william@25thandclement.com> | 2006-06-19 01:18:05 +0000 |
---|---|---|
committer | William Ahern <william@25thandclement.com> | 2006-06-19 01:18:05 +0000 |
commit | 70dbc3725d9d297e3caa30f65cb4137c93420ba4 (patch) | |
tree | 3f3496a5159e4052a0dce9237c1cccc5964e7a14 | |
parent | 2fc66d7b0131f33261ecd3f9a2ddd8b827ec8a52 (diff) | |
download | c-ares-70dbc3725d9d297e3caa30f65cb4137c93420ba4.tar.gz c-ares-70dbc3725d9d297e3caa30f65cb4137c93420ba4.tar.bz2 c-ares-70dbc3725d9d297e3caa30f65cb4137c93420ba4.zip |
Handle EAGAIN/EWOULDBLOCK readiness errors, which can occur for both TCP and
UDP even when a poll(2) or select(2) suggest otherwise.
-rw-r--r-- | CHANGES | 8 | ||||
-rw-r--r-- | ares_process.c | 43 |
2 files changed, 46 insertions, 5 deletions
@@ -1,5 +1,13 @@ Changelog for the c-ares project +* June 18, 2006 + +- William Ahern handles EAGAIN/EWOULDBLOCK errors in most of the I/O calls + from area_process.c. + + TODO: Handle one last EAGAIN for a UDP socket send(2) in + ares__send_query(). + * May 10, 2006 - Bram Matthys brought my attention to a libtool peculiarity where detecting diff --git a/ares_process.c b/ares_process.c index f38e591..533e780 100644 --- a/ares_process.c +++ b/ares_process.c @@ -63,6 +63,7 @@ #define GET_ERRNO() errno #endif +static int try_again(int errnum); static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now); static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now); @@ -94,6 +95,31 @@ void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds) process_timeouts(channel, now); } +/* Return 1 if the specified errno describes a readiness error, or 0 + * otherwise. This is mostly for HP-UX, which could return EAGAIN or + * EWOULDBLOCK. See this man page + * + * http://devrsrc1.external.hp.com/STKS/cgi-bin/man2html?manpage=/usr/share/man/man2.Z/send.2 + */ +static int try_again(int errnum) +{ +#if !defined EWOULDBLOCK && !defined EAGAIN +#error "Neither EWOULDBLOCK nor EAGAIN defined" +#endif + switch (errnum) + { +#ifdef EWOULDBLOCK + case EWOULDBLOCK: + return 1; +#endif +#if defined EAGAIN && EAGAIN != EWOULDBLOCK + case EAGAIN: + return 1; +#endif + } + return 0; +} + /* If any TCP sockets select true for writing, write out queued data * we have for them. */ @@ -136,7 +162,8 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now) free(vec); if (wcount < 0) { - handle_error(channel, i, now); + if (!try_again(GET_ERRNO())) + handle_error(channel, i, now); continue; } @@ -173,7 +200,8 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now) if (scount < 0) { - handle_error(channel, i, now); + if (!try_again(GET_ERRNO())) + handle_error(channel, i, now); continue; } @@ -224,7 +252,8 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now) 2 - server->tcp_lenbuf_pos, 0); if (count <= 0) { - handle_error(channel, i, now); + if (!(count == -1 && try_again(GET_ERRNO()))) + handle_error(channel, i, now); continue; } @@ -250,7 +279,8 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now) server->tcp_length - server->tcp_buffer_pos, 0); if (count <= 0) { - handle_error(channel, i, now); + if (!(count == -1 && try_again(GET_ERRNO()))) + handle_error(channel, i, now); continue; } @@ -289,7 +319,9 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds, continue; count = recv(server->udp_socket, (void *)buf, sizeof(buf), 0); - if (count <= 0) + if (count == -1 && try_again(GET_ERRNO())) + continue; + else if (count <= 0) handle_error(channel, i, now); process_answer(channel, buf, count, i, 0, now); @@ -479,6 +511,7 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now) if (send(server->udp_socket, (void *)query->qbuf, query->qlen, 0) == -1) { + /* FIXME: Handle EAGAIN here since it likely can happen. */ query->skip_server[query->server] = 1; next_server(channel, query, now); return; |