ratox

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

commit 74c488007be7376e43d09233633a874368621532
parent 0548d9faf93c292781e214b3f38e9aa501f79a15
Author: sin <sin@2f30.org>
Date:   Fri, 19 Sep 2014 11:27:42 +0100

Add TRANSFER_PAUSED state

Doesn't quite work yet though.

Diffstat:
Mratox.c | 78++++++++++++++++++++++++++++++++++++------------------------------------------
1 file changed, 36 insertions(+), 42 deletions(-)

diff --git a/ratox.c b/ratox.c @@ -105,6 +105,7 @@ enum { TRANSFER_NONE, TRANSFER_INITIATED, TRANSFER_INPROGRESS, + TRANSFER_PAUSED, TRANSFER_DONE }; @@ -361,37 +362,49 @@ cbfilecontrol(Tox *m, int32_t fid, uint8_t rec_sen, uint8_t fnum, uint8_t ctrlty { struct friend *f; + TAILQ_FOREACH(f, &friendhead, entry) + if (f->fid == fid) + break; + if (!f) + return; + switch (ctrltype) { case TOX_FILECONTROL_ACCEPT: if (rec_sen == 1) { - TAILQ_FOREACH(f, &friendhead, entry) { - if (f->fid != fid) - continue; - f->t.fnum = fnum; - f->t.chunksz = tox_file_data_size(tox, fnum); - f->t.buf = malloc(f->t.chunksz); - if (!f->t.buf) { - perror("malloc"); - exit(EXIT_FAILURE); - } - f->t.n = 0; - f->t.pending = 0; + f->t.fnum = fnum; + f->t.chunksz = tox_file_data_size(tox, fnum); + f->t.buf = malloc(f->t.chunksz); + if (!f->t.buf) { + perror("malloc"); + exit(EXIT_FAILURE); + } + f->t.n = 0; + f->t.pending = 0; + f->t.state = TRANSFER_INPROGRESS; + printout("Transfer is in progress\n"); + } else { + if (f->t.state == TRANSFER_PAUSED) { + printf("Receiver resumed transfer\n"); f->t.state = TRANSFER_INPROGRESS; - printout("Transfer is in progress\n"); - break; } } break; - case TOX_FILECONTROL_FINISHED: + case TOX_FILECONTROL_PAUSE: if (rec_sen == 1) { - TAILQ_FOREACH(f, &friendhead, entry) { - if (f->fid != fid) - continue; - f->t.state = TRANSFER_DONE; - break; + if (f->t.state == TRANSFER_INPROGRESS) { + f->t.state = TRANSFER_PAUSED; + printout("Receiver paused transfer\n"); } } break; + case TOX_FILECONTROL_FINISHED: + if (rec_sen == 1) { + printout("Transfer complete\n"); + f->t.state = TRANSFER_NONE; + free(f->t.buf); + f->t.buf = NULL; + } + break; default: fprintf(stderr, "Unhandled file control type: %d\n", ctrltype); break; @@ -956,7 +969,7 @@ loop(void) { struct friend *f; struct request *r, *rtmp; - time_t t0, t1, now; + time_t t0, t1; int connected = 0; int i, n; int fdmax; @@ -1004,13 +1017,8 @@ loop(void) FD_SET(f->fd[FTEXT_IN], &rfds); if (f->fd[FTEXT_IN] > fdmax) fdmax = f->fd[FTEXT_IN]; - /* If the transfer has just been initiated - * wait until we have a state change before we start - * polling. Avoids spinning endlessly while waiting - * for the transfer to be accepted by the other - * party. - */ - if (f->t.state == TRANSFER_INITIATED) + if (f->t.state == TRANSFER_INITIATED || + f->t.state == TRANSFER_PAUSED) continue; FD_SET(f->fd[FFILE_IN], &rfds); if (f->fd[FFILE_IN] > fdmax) @@ -1059,20 +1067,6 @@ loop(void) sendfriendfile(f); } - /* Check for completed file transfers */ - now = time(NULL); - TAILQ_FOREACH(f, &friendhead, entry) { - if (tox_get_friend_connection_status(tox, f->fid) == 0) - continue; - if (f->t.state == TRANSFER_DONE) { - printout("Transfer complete\n"); - f->t.state = TRANSFER_NONE; - free(f->t.buf); - f->t.buf = NULL; - break; - } - } - if (n == 0) continue;