[PATCH] Don't include socket in pollset if read buffer is full
Kenth Eriksson
kenth.eriksson at infinera.com
Wed Jun 12 09:41:07 CEST 2019
Don't set the POLLIN flag on a socket if the socket buffer is
full. I.e. a socket with full read buffer is not included in the io
loop for reading.
Signed-off-by: Kenth Eriksson <kenth.eriksson at infinera.com>
---
sysdep/unix/io.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index d1d86e3b..2b163417 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -1845,6 +1845,12 @@ sk_read_ssh(sock *s)
}
#endif
+static inline size_t
+sk_rbcount(sock *s)
+{
+ return s->rbuf + s->rbsize - s->rpos;
+}
+
/* sk_read() and sk_write() are called from BFD's event loop */
int
@@ -1861,7 +1867,7 @@ sk_read(sock *s, int revents)
case SK_TCP:
case SK_UNIX:
{
- int c = read(s->fd, s->rpos, s->rbuf + s->rbsize - s->rpos);
+ int c = read(s->fd, s->rpos, sk_rbcount(s));
if (c < 0)
{
@@ -2207,7 +2213,7 @@ io_loop(void)
{
pfd[nfds] = (struct pollfd) { .fd = -1 }; /* everything other set to 0 by this */
s = SKIP_BACK(sock, n, n);
- if (s->rx_hook)
+ if (s->rx_hook && sk_rbcount(s))
{
pfd[nfds].fd = s->fd;
pfd[nfds].events |= POLLIN;
--
2.21.0
More information about the Bird-users
mailing list