diff options
author | z3bra <contactatz3bradotorg> | 2016-11-08 15:43:51 +0100 |
---|---|---|
committer | z3bra <contactatz3bradotorg> | 2016-11-08 16:47:52 +0100 |
commit | cd7901e11b7ad654a9ec9995f572f9d2657e0628 (patch) | |
tree | fc2f0eba93ef7cb6a70fe9552d50a746fd3502a3 /ratox.c | |
parent | 0caaa7794db0045a23a06db21613bdad5040c576 (diff) |
Mark transfer as complete as soon as chunk len is 0
Diffstat (limited to 'ratox.c')
-rw-r--r-- | ratox.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -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 |