ratox

FIFO based tox client
git clone git://git.2f30.org/ratox
Log | Files | Refs | README | LICENSE

commit 07adc70417a23b143d445adea30b56f89a76cf01
parent d56468901999789d01ba822ea21d00b356193275
Author: z3bra <contactatz3bradotorg>
Date:   Tue,  8 Nov 2016 21:40:16 +0100

Handle file transfer in multiple chunks

Diffstat:
Mratox.c | 29+++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/ratox.c b/ratox.c @@ -724,22 +724,12 @@ cbfiledatareq(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, size_t flen, /* Grab another buffer from the FIFO */ if (!f->tx.pendingbuf) { - n = fiforead(f->dirfd, &f->fd[FFILE_IN], ffiles[FFILE_IN], f->tx.buf, - f->tx.chunksz); + n = fiforead(f->dirfd, &f->fd[FFILE_IN], ffiles[FFILE_IN], + f->tx.buf, flen); f->tx.n = n; f->tx.pendingbuf = 0; } - if (f->tx.n == 0) { - /* Signal transfer completion to other end */ - if (!tox_file_send_chunk(tox, f->num, f->tx.fnum, pos, NULL, 0, NULL)) - weprintf("Failed to signal transfer completion to the receiver\n"); - logmsg(": %s : Tx > Complete\n", f->name); - f->tx.state = TRANSFER_NONE; - free(f->tx.buf); - f->tx.buf = NULL; - return; - } if (f->tx.n < 0) { if (errno != EWOULDBLOCK) weprintf("fiforead:"); @@ -748,6 +738,21 @@ cbfiledatareq(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, size_t flen, if (!tox_file_send_chunk(tox, f->num, f->tx.fnum, pos, f->tx.buf, f->tx.n, NULL)) f->tx.pendingbuf = 1; + + /* + * For streams, core will know that the transfer is finished + * if a chunk with length less than the length requested in the + * callback is sent. + */ + if (!f->tx.pendingbuf && f->tx.n < flen) { + logmsg(": %s : Tx > Complete\n", f->name); + f->tx.state = TRANSFER_NONE; + f->tx.fnum = -1; + free(f->tx.buf); + f->tx.buf = NULL; + fiforeset(f->dirfd, &f->fd[FFILE_IN], ffiles[FFILE_IN]); + return; + } } static void