X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=ustream.h;h=53e08280bf522118f6ff53447aa62e71aeb1b16e;hp=a1502afb00676f2943e7104c0a81f4a2363f2bf1;hb=9c4aeda96220b3f0d097d153bedd328f71f382bf;hpb=975ac3e5e30f1106b6b4ea69c8cbf10c7ce8483e diff --git a/ustream.h b/ustream.h index a1502af..53e0828 100644 --- a/ustream.h +++ b/ustream.h @@ -143,6 +143,11 @@ void ustream_free(struct ustream *s); /* ustream_consume: remove data from the head of the read buffer */ void ustream_consume(struct ustream *s, int len); +/* + * ustream_read: read and consume data in read buffer into caller-specified + * area. Return length of data read. + */ +int ustream_read(struct ustream *s, char *buf, int buflen); /* ustream_write: add data to the write buffer */ int ustream_write(struct ustream *s, const char *buf, int len, bool more); int ustream_printf(struct ustream *s, const char *format, ...); @@ -163,9 +168,17 @@ static inline bool ustream_read_blocked(struct ustream *s) return !!(s->read_blocked & READ_BLOCKED_USER); } +static inline int ustream_pending_data(struct ustream *s, bool write) +{ + struct ustream_buf_list *b = write ? &s->w : &s->r; + return b->data_bytes; +} + static inline bool ustream_read_buf_full(struct ustream *s) { - return s->r.data_bytes == s->r.buffer_len; + struct ustream_buf *buf = s->r.data_tail; + return buf && buf->data == buf->head && buf->tail == buf->end && + s->r.buffers == s->r.max_buffers; } /*** --- functions only used by ustream implementations --- ***/