ustream: add a poll callback function defined by the ustream implementation
[project/libubox.git] / ustream.h
index c9e23e8..d9f98b7 100644 (file)
--- a/ustream.h
+++ b/ustream.h
@@ -19,6 +19,7 @@
 #ifndef __USTREAM_H
 #define __USTREAM_H
 
 #ifndef __USTREAM_H
 #define __USTREAM_H
 
+#include <stdarg.h>
 #include "uloop.h"
 
 struct ustream;
 #include "uloop.h"
 
 struct ustream;
@@ -48,6 +49,7 @@ struct ustream_buf_list {
 struct ustream {
        struct ustream_buf_list r, w;
        struct uloop_timeout state_change;
 struct ustream {
        struct ustream_buf_list r, w;
        struct uloop_timeout state_change;
+       struct ustream *next;
 
        /*
         * notify_read:
 
        /*
         * notify_read:
@@ -99,6 +101,14 @@ struct ustream {
        void (*set_read_blocked)(struct ustream *s);
 
        /*
        void (*set_read_blocked)(struct ustream *s);
 
        /*
+        * poll: (optional)
+        * defined by the upstream implementation, called to request polling for
+        * available data.
+        * returns true if data was fetched.
+        */
+       bool (*poll)(struct ustream *s);
+
+       /*
         * ustream user should set this if the input stream is expected
         * to contain string data. the core will keep all data 0-terminated.
         */
         * ustream user should set this if the input stream is expected
         * to contain string data. the core will keep all data 0-terminated.
         */
@@ -180,4 +190,12 @@ static inline void ustream_state_change(struct ustream *s)
        uloop_timeout_set(&s->state_change, 0);
 }
 
        uloop_timeout_set(&s->state_change, 0);
 }
 
+static inline bool ustream_poll(struct ustream *s)
+{
+       if (!s->poll)
+               return false;
+
+       return s->poll(s);
+}
+
 #endif
 #endif