tHandle rejected transfers - ratox - FIFO based tox client
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7171cb2591c5df14b362c45a0ebc6cb166518953
(DIR) parent fa8e064db3d5d2d37ac9e333e0b7ae15fcac4f0d
(HTM) Author: sin <sin@2f30.org>
Date: Fri, 19 Sep 2014 11:54:37 +0100
Handle rejected transfers
Diffstat:
M ratox.c | 32 +++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/ratox.c b/ratox.c
t@@ -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)
t@@ -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");