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--;
}
}
+ gettimeofday(&now, NULL);
+
//check all descriptors
for(iofd = first_descriptor; iofd; iofd = tmp_iofd) {
tmp_iofd = iofd->next;
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;
}
}