diff options
author | antirez <antirez@gmail.com> | 2014-10-17 16:45:48 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-10-17 16:45:53 +0200 |
commit | 525c488f639672e5b36cc67ede857d25a39c016d (patch) | |
tree | d222e7acb3d79f63c8aea5660b5c42c8c0c6a7c8 /src/rio.c | |
parent | 74f90c61232859f35db4eabf5b0bf1c8e4123bf0 (diff) | |
download | redis-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.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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; |