diff options
-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 |