ustream: suppress write attempts in ustream_printf and ustream_vprintf if a write...
[project/libubox.git] / ustream.c
index ed4fbb3..9c14678 100644 (file)
--- a/ustream.c
+++ b/ustream.c
@@ -104,7 +104,8 @@ static void ustream_state_change_cb(struct uloop_timeout *t)
 
        if (s->write_error)
                ustream_free_buffers(&s->w);
-       s->notify_state(s);
+       if (s->notify_state)
+               s->notify_state(s);
 }
 
 void ustream_init_defaults(struct ustream *s)
@@ -434,6 +435,9 @@ int ustream_vprintf(struct ustream *s, const char *format, va_list arg)
        va_list arg2;
        int wr, maxlen, buflen;
 
+       if (s->write_error)
+               return 0;
+
        if (!l->data_bytes) {
                buf = alloca(MAX_STACK_BUFLEN);
                va_copy(arg2, arg);
@@ -492,6 +496,9 @@ int ustream_printf(struct ustream *s, const char *format, ...)
        va_list arg;
        int ret;
 
+       if (s->write_error)
+               return 0;
+
        va_start(arg, format);
        ret = ustream_vprintf(s, format, arg);
        va_end(arg);