added session manager and support for an external login system
[TransparentIRC.git] / src / IOEngine_select.c
index dabe2e6b28ec94f788c19cc592c348b45736ec93..2f32bf04fe9f8eb457bd5c5c5c7dd0f316d04948 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,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;
             }
         }