commit cd7901e11b7ad654a9ec9995f572f9d2657e0628
parent 0caaa7794db0045a23a06db21613bdad5040c576
Author: z3bra <contactatz3bradotorg>
Date: Tue, 8 Nov 2016 15:43:51 +0100
Mark transfer as complete as soon as chunk len is 0
Diffstat:
M | ratox.c | | | 28 | +++++++++++++--------------- |
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git 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