rio fdset target: handle short writes.

While the socket is set in blocking mode, we still can get short writes
writing to a socket.
This commit is contained in:
antirez
2014-10-17 16:45:48 +02:00
parent 74f90c6123
commit 525c488f63
3 changed files with 18 additions and 2 deletions

View File

@ -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;