0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 10:11:53 +00:00

Poll: Prevent the improbable case of EAGAIN after POLLIN

This commit is contained in:
Jan Moskyto Matejka 2016-03-15 14:57:49 +01:00 committed by Pavel Tvrdik
parent a23f764517
commit b9bf5fad7c
2 changed files with 10 additions and 5 deletions

View File

@ -576,7 +576,7 @@ sockets_close_fds(struct birdloop *loop)
loop->close_scheduled = 0; loop->close_scheduled = 0;
} }
int sk_read(sock *s); int sk_read(sock *s, int revents);
int sk_write(sock *s); int sk_write(sock *s);
static void static void
@ -605,7 +605,7 @@ sockets_fire(struct birdloop *loop)
if (pfd->revents & POLLIN) if (pfd->revents & POLLIN)
while (e && *psk && (*psk)->rx_hook) while (e && *psk && (*psk)->rx_hook)
e = sk_read(*psk); e = sk_read(*psk, 0);
e = 1; e = 1;
if (pfd->revents & POLLOUT) if (pfd->revents & POLLOUT)

View File

@ -1755,7 +1755,7 @@ sk_send_full(sock *s, unsigned len, struct iface *ifa,
/* sk_read() and sk_write() are called from BFD's event loop */ /* sk_read() and sk_write() are called from BFD's event loop */
int int
sk_read(sock *s) sk_read(sock *s, int revents)
{ {
switch (s->type) switch (s->type)
{ {
@ -1774,6 +1774,11 @@ sk_read(sock *s)
{ {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
s->err_hook(s, errno); s->err_hook(s, errno);
else if (errno == EAGAIN && !(revents & POLLIN))
{
log(L_ERR "Got EAGAIN from read when revents=%x (without POLLIN)", revents);
s->err_hook(s, 0);
}
} }
else if (!c) else if (!c)
s->err_hook(s, 0); s->err_hook(s, 0);
@ -2154,7 +2159,7 @@ io_loop(void)
{ {
steps--; steps--;
io_log_event(s->rx_hook, s->data); io_log_event(s->rx_hook, s->data);
e = sk_read(s); e = sk_read(s, pfd[s->index].revents);
if (s != current_sock) if (s != current_sock)
goto next; goto next;
} }
@ -2198,7 +2203,7 @@ io_loop(void)
{ {
count++; count++;
io_log_event(s->rx_hook, s->data); io_log_event(s->rx_hook, s->data);
sk_read(s); sk_read(s, pfd[s->index].revents);
if (s != current_sock) if (s != current_sock)
goto next2; goto next2;
} }