ustream: fix polling for write buffer availability after buffering writes
authorFelix Fietkau <nbd@openwrt.org>
Sun, 30 Dec 2012 16:26:40 +0000 (17:26 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 30 Dec 2012 16:26:40 +0000 (17:26 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
ustream-fd.c
ustream.c

index 6bb39e934e5dfd960cef528f0dcf2bef998c21d2..0cd2eb3d7915c1e18e8e7d683afbc8aa52006dca 100644 (file)
@@ -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)
index 9c14678b059ad656ddc5b318cac23953615ba968..37fbaf76d03111d05a352f4891d47d1f8b5d0741 100644 (file)
--- 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;
 }