ustream-fd: retry partial writes
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
220958b7d9
commit
f15ceb8ced
1 changed files with 17 additions and 12 deletions
21
ustream-fd.c
21
ustream-fd.c
|
@ -83,28 +83,33 @@ static void ustream_fd_read_pending(struct ustream_fd *sf, bool *more)
|
||||||
static int ustream_fd_write(struct ustream *s, const char *buf, int buflen, bool more)
|
static int ustream_fd_write(struct ustream *s, const char *buf, int buflen, bool more)
|
||||||
{
|
{
|
||||||
struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
|
struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
|
||||||
ssize_t len;
|
ssize_t ret = 0, len;
|
||||||
|
|
||||||
if (!buflen)
|
if (!buflen)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
retry:
|
while (buflen) {
|
||||||
len = write(sf->fd.fd, buf, buflen);
|
len = write(sf->fd.fd, buf, buflen);
|
||||||
if (!len)
|
|
||||||
goto retry;
|
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
goto retry;
|
continue;
|
||||||
|
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
len = 0;
|
break;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len >= 0 && len < buflen)
|
ret += len;
|
||||||
|
buf += len;
|
||||||
|
buflen -= len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buflen)
|
||||||
ustream_fd_set_uloop(s, true);
|
ustream_fd_set_uloop(s, true);
|
||||||
|
|
||||||
return len;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)
|
static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)
|
||||||
|
|
Loading…
Reference in a new issue