Event Select: need to monitor for socket exceptions too

v1.27
Brad House 4 months ago
parent f555ebff99
commit b1b15e42c3
  1. 7
      src/lib/ares_event_select.c

@ -77,12 +77,14 @@ static size_t ares_evsys_select_wait(ares_event_thread_t *e,
size_t i; size_t i;
fd_set read_fds; fd_set read_fds;
fd_set write_fds; fd_set write_fds;
fd_set except_fds;
int nfds = 0; int nfds = 0;
struct timeval tv; struct timeval tv;
struct timeval *tout = NULL; struct timeval *tout = NULL;
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_ZERO(&write_fds); FD_ZERO(&write_fds);
FD_ZERO(&except_fds);
for (i = 0; i < num_fds; i++) { for (i = 0; i < num_fds; i++) {
const ares_event_t *ev = const ares_event_t *ev =
@ -93,6 +95,7 @@ static size_t ares_evsys_select_wait(ares_event_thread_t *e,
if (ev->flags & ARES_EVENT_FLAG_WRITE) { if (ev->flags & ARES_EVENT_FLAG_WRITE) {
FD_SET(ev->fd, &write_fds); FD_SET(ev->fd, &write_fds);
} }
FD_SET(ev->fd, &except_fds);
if (ev->fd + 1 > nfds) { if (ev->fd + 1 > nfds) {
nfds = ev->fd + 1; nfds = ev->fd + 1;
} }
@ -104,7 +107,7 @@ static size_t ares_evsys_select_wait(ares_event_thread_t *e,
tout = &tv; tout = &tv;
} }
rv = select(nfds, &read_fds, &write_fds, NULL, tout); rv = select(nfds, &read_fds, &write_fds, &except_fds, tout);
if (rv > 0) { if (rv > 0) {
for (i = 0; i < num_fds; i++) { for (i = 0; i < num_fds; i++) {
ares_event_t *ev; ares_event_t *ev;
@ -115,7 +118,7 @@ static size_t ares_evsys_select_wait(ares_event_thread_t *e,
continue; continue;
} }
if (FD_ISSET(fdlist[i], &read_fds)) { if (FD_ISSET(fdlist[i], &read_fds) || FD_ISSET(fdlist[i], &except_fds)) {
flags |= ARES_EVENT_FLAG_READ; flags |= ARES_EVENT_FLAG_READ;
} }

Loading…
Cancel
Save