added IRC Client and RAW pass-through
[TransparentIRC.git] / src / IOEngine_select.c
index dabe2e6b28ec94f788c19cc592c348b45736ec93..e37b10496651c5ece864c18a07c6ff97f898a317 100644 (file)
@@ -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;
             }
         }