ustream-fd: stop trying to read when s->read_blocked is set.
[project/libubox.git] / ustream-fd.c
index c8f0ef9..5ffca53 100644 (file)
@@ -50,6 +50,9 @@ static void ustream_fd_read_pending(struct ustream_fd *sf, bool *more)
        char *buf;
 
        do {
        char *buf;
 
        do {
+               if (s->read_blocked)
+                       break;
+
                buf = ustream_reserve(s, 1, &buflen);
                if (!buf)
                        break;
                buf = ustream_reserve(s, 1, &buflen);
                if (!buf)
                        break;
@@ -66,8 +69,9 @@ static void ustream_fd_read_pending(struct ustream_fd *sf, bool *more)
                }
 
                if (!len) {
                }
 
                if (!len) {
+                       if (!s->eof)
+                               ustream_state_change(s);
                        s->eof = true;
                        s->eof = true;
-                       ustream_state_change(s);
                        ustream_fd_set_uloop(s, false);
                        return;
                }
                        ustream_fd_set_uloop(s, false);
                        return;
                }
@@ -118,7 +122,8 @@ static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)
                ustream_fd_read_pending(sf, &more);
 
        if (events & ULOOP_WRITE) {
                ustream_fd_read_pending(sf, &more);
 
        if (events & ULOOP_WRITE) {
-               if (!ustream_write_pending(s))
+               bool no_more = ustream_write_pending(s);
+               if (no_more)
                        ustream_fd_set_uloop(s, false);
        }
 
                        ustream_fd_set_uloop(s, false);
        }