Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-22 13:09:55 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-01-22 13:09:55 +0400
commitf15ceb8ced4a88f3a4c30f6b45cf52691f4c1a5f (patch)
tree386b784d98479ac3ef62dc27eb7290b812cdcb02 /ustream-fd.c
parent220958b7d9deb41d9ec957acf53c2dc5ef13e0e3 (diff)
ustream-fd: retry partial writes
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'ustream-fd.c')
-rw-r--r--ustream-fd.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/ustream-fd.c b/ustream-fd.c
index a47ff94..a252708 100644
--- a/ustream-fd.c
+++ b/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)
{
struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
- ssize_t len;
+ ssize_t ret = 0, len;
if (!buflen)
return 0;
-retry:
- len = write(sf->fd.fd, buf, buflen);
- if (!len)
- goto retry;
+ while (buflen) {
+ len = write(sf->fd.fd, buf, buflen);
+
+ if (len < 0) {
+ if (errno == EINTR)
+ continue;
+
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ break;
- if (len < 0) {
- if (errno == EINTR)
- goto retry;
+ return -1;
+ }
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- len = 0;
+ ret += len;
+ buf += len;
+ buflen -= len;
}
- if (len >= 0 && len < buflen)
+ if (buflen)
ustream_fd_set_uloop(s, true);
- return len;
+ return ret;
}
static bool __ustream_fd_poll(struct ustream_fd *sf, unsigned int events)