X-Git-Url: http://git.pk910.de/?p=TransparentIRC.git;a=blobdiff_plain;f=src%2FIOEngine_select.c;h=2f32bf04fe9f8eb457bd5c5c5c7dd0f316d04948;hp=dabe2e6b28ec94f788c19cc592c348b45736ec93;hb=4fdc419424dd18df5807ed4218a84fa38e1dd6f6;hpb=1f2baa2e7b90ea83c5a0c93598e22e5063fc6d95 diff --git a/src/IOEngine_select.c b/src/IOEngine_select.c index dabe2e6..2f32bf0 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,6 +88,8 @@ 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; @@ -94,14 +97,16 @@ static void engine_select_loop(struct timeval *timeout) { 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)); } - } 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; } }