From cd7901e11b7ad654a9ec9995f572f9d2657e0628 Mon Sep 17 00:00:00 2001 From: z3bra Date: Tue, 8 Nov 2016 15:43:51 +0100 Subject: Mark transfer as complete as soon as chunk len is 0 --- ratox.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 9fb9792..9e200a7 100644 --- a/ratox.c +++ b/ratox.c @@ -798,6 +798,19 @@ cbfiledata(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, const uint8_t *d if (!f) return; + /* When length is 0, the transfer is finished */ + if (!len) { + logmsg(": %s : Rx > Complete\n", f->name); + if (f->fd[FFILE_OUT] != -1) { + close(f->fd[FFILE_OUT]); + f->fd[FFILE_OUT] = -1; + } + ftruncate(f->fd[FFILE_STATE], 0); + lseek(f->fd[FFILE_STATE], 0, SEEK_SET); + f->rxstate = TRANSFER_NONE; + return; + } + while (len > 0) { n = write(f->fd[FFILE_OUT], &data[wrote], len); if (n < 0) { @@ -807,25 +820,10 @@ cbfiledata(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, const uint8_t *d } else if (errno == EWOULDBLOCK) { continue; } - break; - } else if (n == 0) { - break; } wrote += n; len -= n; } - - /* When length is 0, the transfer is finished */ - if (!len) { - logmsg(": %s : Rx > Complete\n", f->name); - if (f->fd[FFILE_OUT] != -1) { - close(f->fd[FFILE_OUT]); - f->fd[FFILE_OUT] = -1; - } - ftruncate(f->fd[FFILE_STATE], 0); - lseek(f->fd[FFILE_STATE], 0, SEEK_SET); - f->rxstate = TRANSFER_NONE; - } } static void -- cgit v1.2.3