From ee6c055b69a608e46f23a8d3daae0527d0817e3e Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 24 Sep 2014 14:29:06 +0100 Subject: Only poll the file descriptors we added to the set --- ratox.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/ratox.c b/ratox.c index 824b101..65c568c 100644 --- a/ratox.c +++ b/ratox.c @@ -1289,37 +1289,27 @@ loop(void) for (f = TAILQ_FIRST(&friendhead); f; f = ftmp) { ftmp = TAILQ_NEXT(f, entry); - for (i = 0; i < LEN(ffiles); i++) { - if (FD_ISSET(f->fd[i], &rfds) == 0) - continue; - switch (i) { - case FTEXT_IN: - sendfriendtext(f); - break; - case FFILE_IN: - switch (f->t.state) { - case TRANSFER_NONE: - /* Prepare a new transfer */ - f->t.state = TRANSFER_INITIATED; - now = time(NULL); - snprintf(tstamp, sizeof(tstamp), "%lu", (unsigned long)now); - tox_new_file_sender(tox, f->fid, - 0, (uint8_t *)tstamp, strlen(tstamp)); - printout("Initiated transfer to %s\n", - f->namestr[0] == '\0' ? "Anonymous" : f->namestr); - break; - case TRANSFER_INPROGRESS: - sendfriendfile(f); - break; - } + if (FD_ISSET(f->fd[FTEXT_IN], &rfds)) + sendfriendtext(f); + if (FD_ISSET(f->fd[FFILE_IN], &rfds)) { + switch (f->t.state) { + case TRANSFER_NONE: + /* Prepare a new transfer */ + f->t.state = TRANSFER_INITIATED; + now = time(NULL); + snprintf(tstamp, sizeof(tstamp), "%lu", (unsigned long)now); + tox_new_file_sender(tox, f->fid, + 0, (uint8_t *)tstamp, strlen(tstamp)); + printout("Initiated transfer to %s\n", + f->namestr[0] == '\0' ? "Anonymous" : f->namestr); break; - case FREMOVE: - removefriend(f); + case TRANSFER_INPROGRESS: + sendfriendfile(f); break; - default: - fprintf(stderr, "Unhandled FIFO read\n"); } } + if (FD_ISSET(f->fd[FREMOVE], &rfds)) + removefriend(f); } } } -- cgit v1.2.3