summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2014-09-24 15:43:11 +0100
committersin <sin@2f30.org>2014-09-24 15:43:25 +0100
commite020b1e9369fc6aaf9f600ab5b1bf93c1235e503 (patch)
tree36197056969b6cc22a1515d137ccfea4d17fec44 /ratox.c
parent04d2c71dcd1aff729fcf59c720245aa270a02815 (diff)
Handle partial writes
Diffstat (limited to 'ratox.c')
-rw-r--r--ratox.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ratox.c b/ratox.c
index fb9c36d..5511710 100644
--- a/ratox.c
+++ b/ratox.c
@@ -535,6 +535,7 @@ static void
cbfiledata(Tox *m, int32_t fid, uint8_t fnum, const uint8_t *data, uint16_t len, void *udata)
{
struct friend *f;
+ uint16_t wrote = 0;
ssize_t n;
TAILQ_FOREACH(f, &friendhead, entry)
@@ -543,13 +544,17 @@ cbfiledata(Tox *m, int32_t fid, uint8_t fnum, const uint8_t *data, uint16_t len,
if (!f)
return;
-again:
- n = write(f->fd[FFILE_OUT], data, len);
- if (n < 0) {
- if (errno == EPIPE)
- cancelrxtransfer(f);
- if (errno == EWOULDBLOCK)
- goto again;
+ while (len > 0) {
+ n = write(f->fd[FFILE_OUT], &data[wrote], len);
+ if (n < 0) {
+ if (errno == EPIPE)
+ cancelrxtransfer(f);
+ if (errno == EWOULDBLOCK)
+ continue;
+ } else if (n == 0)
+ break;
+ wrote += n;
+ len -= n;
}
}