From 7171cb2591c5df14b362c45a0ebc6cb166518953 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 19 Sep 2014 11:54:37 +0100 Subject: Handle rejected transfers --- ratox.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ratox.c b/ratox.c index 1d983b9..564de60 100644 --- a/ratox.c +++ b/ratox.c @@ -361,6 +361,9 @@ cbfilecontrol(Tox *m, int32_t fid, uint8_t rec_sen, uint8_t fnum, uint8_t ctrlty const uint8_t *data, uint16_t len, void *udata) { struct friend *f; + char buf[BUFSIZ]; + ssize_t n; + int r; TAILQ_FOREACH(f, &friendhead, entry) if (f->fid == fid) @@ -397,6 +400,35 @@ cbfilecontrol(Tox *m, int32_t fid, uint8_t rec_sen, uint8_t fnum, uint8_t ctrlty } } break; + case TOX_FILECONTROL_KILL: + if (rec_sen == 1) { + printout("Transfer rejected by receiver\n"); + f->t.state = TRANSFER_NONE; + free(f->t.buf); + f->t.buf = NULL; + + /* Flush the FIFO */ + while (1) { + n = read(f->fd[FFILE_IN], buf, sizeof(buf)); + if (n < 0) { + if (errno == EINTR || errno == EWOULDBLOCK) + continue; + perror("read"); + exit(EXIT_FAILURE); + } + if (n == 0) + break; + } + + close(f->fd[FFILE_IN]); + r = openat(f->dirfd, ffiles[FFILE_IN].name, ffiles[FFILE_IN].flags, 0644); + if (r < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + f->fd[FFILE_IN] = r; + } + break; case TOX_FILECONTROL_FINISHED: if (rec_sen == 1) { printout("Transfer complete\n"); -- cgit v1.2.3