From 300a809a7a6b30595962308c4215ead6ec361053 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 30 Dec 2012 17:26:40 +0100 Subject: [PATCH] ustream: fix polling for write buffer availability after buffering writes Signed-off-by: Felix Fietkau --- ustream-fd.c | 4 ++-- ustream.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ustream-fd.c b/ustream-fd.c index 6bb39e9..0cd2eb3 100644 --- a/ustream-fd.c +++ b/ustream-fd.c @@ -105,7 +105,7 @@ static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events) ustream_fd_read_pending(sf, &more); if (events & ULOOP_WRITE) { - if (ustream_write_pending(s)) + if (!ustream_write_pending(s)) ustream_fd_set_uloop(s); } @@ -122,7 +122,7 @@ static bool ustream_fd_poll(struct ustream *s) { struct ustream_fd *sf = container_of(s, struct ustream_fd, stream); - return __ustream_fd_poll(sf, ULOOP_READ); + return __ustream_fd_poll(sf, ULOOP_READ | ULOOP_WRITE); } static void ustream_uloop_cb(struct uloop_fd *fd, unsigned int events) diff --git a/ustream.c b/ustream.c index 9c14678..37fbaf7 100644 --- a/ustream.c +++ b/ustream.c @@ -341,7 +341,7 @@ bool ustream_write_pending(struct ustream *s) if (s->write_error) return false; - while (buf) { + while (buf && s->w.data_bytes) { struct ustream_buf *next = buf->next; int maxlen = buf->tail - buf->data; @@ -379,6 +379,7 @@ static int ustream_write_buffered(struct ustream *s, const char *data, int len, struct ustream_buf_list *l = &s->w; struct ustream_buf *buf; int maxlen; + bool has_data = !!s->w.data_bytes; while (len) { if (!ustream_prepare_buf(s, &s->w, len)) @@ -398,6 +399,9 @@ static int ustream_write_buffered(struct ustream *s, const char *data, int len, l->data_bytes += maxlen; } + if (s->poll && !has_data) + s->poll(s); + return wr; }