Simplifies stacked ustreams and calling poll from the read function.
Reuse an unused leftover struct member in order to not break ABI.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
+#define CB_PENDING_READ (1 << 0)
+
static void ustream_init_buf(struct ustream_buf *buf, int len)
{
if (!len)
static void ustream_init_buf(struct ustream_buf *buf, int len)
{
if (!len)
s->state_change.cb = ustream_state_change_cb;
s->write_error = false;
s->eof = false;
s->state_change.cb = ustream_state_change_cb;
s->write_error = false;
s->eof = false;
- s->eof_write_done = false;
s->read_blocked = 0;
s->r.buffers = 0;
s->read_blocked = 0;
s->r.buffers = 0;
void ustream_fill_read(struct ustream *s, int len)
{
struct ustream_buf *buf = s->r.data_tail;
void ustream_fill_read(struct ustream *s, int len)
{
struct ustream_buf *buf = s->r.data_tail;
int maxlen;
s->r.data_bytes += len;
int maxlen;
s->r.data_bytes += len;
buf = buf->next;
} while (len);
buf = buf->next;
} while (len);
- if (s->notify_read)
- s->notify_read(s, n);
+ if (s->notify_read) {
+ if (s->pending_cb & CB_PENDING_READ)
+ return;
+
+ s->pending_cb |= CB_PENDING_READ;
+ s->notify_read(s, s->r.data_bytes);
+ s->pending_cb &= ~CB_PENDING_READ;
+ }
}
char *ustream_get_read_buf(struct ustream *s, int *buflen)
}
char *ustream_get_read_buf(struct ustream *s, int *buflen)
*/
bool string_data;
bool write_error;
*/
bool string_data;
bool write_error;
- bool eof, eof_write_done;
+ bool eof;
+ uint8_t pending_cb;
enum read_blocked_reason read_blocked;
};
enum read_blocked_reason read_blocked;
};