diff options
author | Jan Moskyto Matejka <mq@ucw.cz> | 2016-05-30 14:28:22 +0200 |
---|---|---|
committer | Jan Moskyto Matejka <mq@ucw.cz> | 2016-05-30 14:28:22 +0200 |
commit | 9dbcb11cb50167e959536e5a564ee9aafae509c6 (patch) | |
tree | 3a8005208a8963871af415ea235c503a7add3ef4 /sysdep/unix | |
parent | 3f2c7600fa2e35b1028c755aa06092b5991e1a8e (diff) |
Unix IO: Tried to fix strange behavior after POLLHUP or POLLERR.
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/io.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 486319ff..8198743d 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1854,6 +1854,20 @@ sk_write(sock *s) } void +sk_err(sock *s, int revents) +{ + int se = 0, sse = sizeof(se); + if (revents & POLLERR) + if (getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &se, &sse) < 0) + { + log(L_ERR "IO: Socket error: SO_ERROR: %m"); + se = 0; + } + + s->err_hook(s, se); +} + +void sk_dump_all(void) { node *n; @@ -2163,7 +2177,7 @@ io_loop(void) int steps; steps = MAX_STEPS; - if (s->fast_rx && (pfd[s->index].revents & (POLLIN | POLLHUP | POLLERR)) && s->rx_hook) + if (s->fast_rx && (pfd[s->index].revents & POLLIN) && s->rx_hook) do { steps--; @@ -2185,6 +2199,7 @@ io_loop(void) goto next; } while (e && steps); + current_sock = sk_next(s); next: ; } @@ -2208,18 +2223,26 @@ io_loop(void) goto next2; } - if (!s->fast_rx && (pfd[s->index].revents & (POLLIN | POLLHUP | POLLERR)) && s->rx_hook) + if (!s->fast_rx && (pfd[s->index].revents & POLLIN) && s->rx_hook) { count++; io_log_event(s->rx_hook, s->data); sk_read(s, pfd[s->index].revents); if (s != current_sock) - goto next2; + goto next2; + } + + if (pfd[s->index].revents & (POLLHUP | POLLERR)) + { + sk_err(s, pfd[s->index].revents); + goto next2; } + current_sock = sk_next(s); next2: ; } + stored_sock = current_sock; } } |