X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FIOEngine_select.c;h=e37b10496651c5ece864c18a07c6ff97f898a317;hb=8889b0aee1dc430e735e2a0df462fd0aeee63847;hp=dabe2e6b28ec94f788c19cc592c348b45736ec93;hpb=1f2baa2e7b90ea83c5a0c93598e22e5063fc6d95;p=TransparentIRC.git diff --git a/src/IOEngine_select.c b/src/IOEngine_select.c index dabe2e6..e37b104 100644 --- a/src/IOEngine_select.c +++ b/src/IOEngine_select.c @@ -56,15 +56,16 @@ static void engine_select_loop(struct timeval *timeout) { FD_SET(iofd->fd, &read_fds); if(iohandler_wants_writes(iofd)) FD_SET(iofd->fd, &write_fds); - } else if(iofd->type == IOTYPE_TIMER) { + } + if(iofd->type == IOTYPE_TIMER || iofd->timeout.tv_sec || iofd->timeout.tv_usec) { tdiff.tv_sec = iofd->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = iofd->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { //exec timer - iofd->state = IO_CLOSED; - iohandler_events(iofd, 1, 0); - iohandler_close(iofd); + iohandler_events(iofd, 0, 0); + if(iofd->type == IOTYPE_TIMER) + iohandler_close(iofd); continue; } else if(tdiff.tv_usec < 0) { tdiff.tv_sec--; @@ -87,21 +88,26 @@ static void engine_select_loop(struct timeval *timeout) { } } + gettimeofday(&now, NULL); + //check all descriptors for(iofd = first_descriptor; iofd; iofd = tmp_iofd) { tmp_iofd = iofd->next; if(iofd->type == IOTYPE_SERVER || iofd->type == IOTYPE_CLIENT || iofd->type == IOTYPE_STDIN) { if(FD_ISSET(iofd->fd, &read_fds) || FD_ISSET(iofd->fd, &write_fds)) { iohandler_events(iofd, FD_ISSET(iofd->fd, &read_fds), FD_ISSET(iofd->fd, &write_fds)); + continue; } - } else if(iofd->type == IOTYPE_TIMER) { + } + if(iofd->type == IOTYPE_TIMER || iofd->timeout.tv_sec || iofd->timeout.tv_usec) { tdiff.tv_sec = iofd->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = iofd->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { //exec timer - iofd->state = IO_CLOSED; - iohandler_events(iofd, 1, 0); + iohandler_events(iofd, 0, 0); + if(iofd->type == IOTYPE_TIMER) + iohandler_close(iofd); continue; } }