summaryrefslogtreecommitdiff
path: root/src/rio.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-10-17 16:45:48 +0200
committerantirez <antirez@gmail.com>2014-10-17 16:45:53 +0200
commit525c488f639672e5b36cc67ede857d25a39c016d (patch)
treed222e7acb3d79f63c8aea5660b5c42c8c0c6a7c8 /src/rio.c
parent74f90c61232859f35db4eabf5b0bf1c8e4123bf0 (diff)
downloadredis-525c488f639672e5b36cc67ede857d25a39c016d.tar.gz
rio fdset target: handle short writes.
While the socket is set in blocking mode, we still can get short writes writing to a socket.
Diffstat (limited to 'src/rio.c')
-rw-r--r--src/rio.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/rio.c b/src/rio.c
index 5153ed28e..3513e1889 100644
--- a/src/rio.c
+++ b/src/rio.c
@@ -197,8 +197,17 @@ static size_t rioFdsetWrite(rio *r, const void *buf, size_t len) {
broken++;
continue;
}
- retval = write(r->io.fdset.fds[j],p,count);
- if (retval != count) {
+
+ /* Make sure to write 'count' bytes to the socket regardless
+ * of short writes. */
+ size_t nwritten = 0;
+ while(nwritten != count) {
+ retval = write(r->io.fdset.fds[j],p+nwritten,count-nwritten);
+ if (retval <= 0) break;
+ nwritten += retval;
+ }
+
+ if (nwritten != count) {
/* Mark this FD as broken. */
r->io.fdset.state[j] = errno;
if (r->io.fdset.state[j] == 0) r->io.fdset.state[j] = EIO;