ustream-fd: handle uloop errors
authorPhilip Craig <philipjcraig@gmail.com>
Mon, 13 Jul 2015 02:12:28 +0000 (12:12 +1000)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 14 Jul 2015 14:57:05 +0000 (16:57 +0200)
The default uloop error handling is to delete the fd. Continue to do
that, but also set the write_error flag and notify the user.

Signed-off-by: Philip Craig <philipjcraig@gmail.com>
ustream-fd.c

index 5ffca53328858280e3a1bb51c944728b71fe38c7..d5abb5a1f524c73d635b856966def2fcb8d3a26b 100644 (file)
@@ -25,7 +25,7 @@ static void ustream_fd_set_uloop(struct ustream *s, bool write)
 {
        struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
        struct ustream_buf *buf;
-       unsigned int flags = ULOOP_EDGE_TRIGGER;
+       unsigned int flags = ULOOP_EDGE_TRIGGER | ULOOP_ERROR_CB;
 
        if (!s->read_blocked && !s->eof)
                flags |= ULOOP_READ;
@@ -127,6 +127,12 @@ static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)
                        ustream_fd_set_uloop(s, false);
        }
 
+       if (sf->fd.error && !s->write_error) {
+               ustream_state_change(s);
+               s->write_error = true;
+               ustream_fd_set_uloop(s, false);
+       }
+
        return more;
 }