ustream: fix polling for write buffer availability after buffering writes

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2012-12-30 17:26:40 +01:00
parent 84822fd6d5
commit 300a809a7a
2 changed files with 7 additions and 3 deletions

View file

@ -105,7 +105,7 @@ static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)
ustream_fd_read_pending(sf, &more); ustream_fd_read_pending(sf, &more);
if (events & ULOOP_WRITE) { if (events & ULOOP_WRITE) {
if (ustream_write_pending(s)) if (!ustream_write_pending(s))
ustream_fd_set_uloop(s); ustream_fd_set_uloop(s);
} }
@ -122,7 +122,7 @@ static bool ustream_fd_poll(struct ustream *s)
{ {
struct ustream_fd *sf = container_of(s, struct ustream_fd, stream); struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
return __ustream_fd_poll(sf, ULOOP_READ); return __ustream_fd_poll(sf, ULOOP_READ | ULOOP_WRITE);
} }
static void ustream_uloop_cb(struct uloop_fd *fd, unsigned int events) static void ustream_uloop_cb(struct uloop_fd *fd, unsigned int events)

View file

@ -341,7 +341,7 @@ bool ustream_write_pending(struct ustream *s)
if (s->write_error) if (s->write_error)
return false; return false;
while (buf) { while (buf && s->w.data_bytes) {
struct ustream_buf *next = buf->next; struct ustream_buf *next = buf->next;
int maxlen = buf->tail - buf->data; int maxlen = buf->tail - buf->data;
@ -379,6 +379,7 @@ static int ustream_write_buffered(struct ustream *s, const char *data, int len,
struct ustream_buf_list *l = &s->w; struct ustream_buf_list *l = &s->w;
struct ustream_buf *buf; struct ustream_buf *buf;
int maxlen; int maxlen;
bool has_data = !!s->w.data_bytes;
while (len) { while (len) {
if (!ustream_prepare_buf(s, &s->w, len)) if (!ustream_prepare_buf(s, &s->w, len))
@ -398,6 +399,9 @@ static int ustream_write_buffered(struct ustream *s, const char *data, int len,
l->data_bytes += maxlen; l->data_bytes += maxlen;
} }
if (s->poll && !has_data)
s->poll(s);
return wr; return wr;
} }