diff options
author | sin <sin@2f30.org> | 2014-09-19 11:54:37 +0100 |
---|---|---|
committer | sin <sin@2f30.org> | 2014-09-19 11:54:37 +0100 |
commit | 7171cb2591c5df14b362c45a0ebc6cb166518953 (patch) | |
tree | 622d9983d2174d76874411225803dbaec91d96fe | |
parent | fa8e064db3d5d2d37ac9e333e0b7ae15fcac4f0d (diff) |
Handle rejected transfers
-rw-r--r-- | ratox.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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"); |