Unix IO: Tried to fix strange behavior after POLLHUP or POLLERR.

This commit is contained in:
Jan Moskyto Matejka 2016-05-30 14:28:22 +02:00
parent 3f2c7600fa
commit 9dbcb11cb5

View file

@ -1853,6 +1853,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 void
sk_dump_all(void) sk_dump_all(void)
{ {
@ -2163,7 +2177,7 @@ io_loop(void)
int steps; int steps;
steps = MAX_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 do
{ {
steps--; steps--;
@ -2185,6 +2199,7 @@ io_loop(void)
goto next; goto next;
} }
while (e && steps); while (e && steps);
current_sock = sk_next(s); current_sock = sk_next(s);
next: ; next: ;
} }
@ -2208,7 +2223,7 @@ io_loop(void)
goto next2; 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++; count++;
io_log_event(s->rx_hook, s->data); io_log_event(s->rx_hook, s->data);
@ -2216,10 +2231,18 @@ io_loop(void)
if (s != current_sock) 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); current_sock = sk_next(s);
next2: ; next2: ;
} }
stored_sock = current_sock; stored_sock = current_sock;
} }
} }