[Reconnoiter-devel] [reconnoiter commit] r1276 - trunk/src/eventer

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Wed May 5 12:00:08 EDT 2010


Author: jesus
Date: 2010-05-05 12:00:08 -0400 (Wed, 05 May 2010)
New Revision: 1276

Modified:
   trunk/src/eventer/eventer_ports_impl.c
Log:
Solaris portion, refs #273

Modified: trunk/src/eventer/eventer_ports_impl.c
===================================================================
--- trunk/src/eventer/eventer_ports_impl.c	2010-04-29 20:58:06 UTC (rev 1275)
+++ trunk/src/eventer/eventer_ports_impl.c	2010-05-05 16:00:08 UTC (rev 1276)
@@ -55,6 +55,7 @@
 
 #include "eventer/eventer_impl_private.h"
 
+static const struct timeval __dyna_increment = { 0, 1000 }; /* 1 ms */
 static pthread_t master_thread;
 static int port_fd = -1;
 
@@ -241,6 +242,7 @@
   release_master_fd(fd, lockstate);
 }
 static int eventer_ports_impl_loop() {
+  struct timeval __dyna_sleep = { 0, 0 };
   int is_master_thread = 0;
   pthread_t self;
 
@@ -257,10 +259,16 @@
     int max_timed_events_to_process;
     int newmask;
 
-    __sleeptime = eventer_max_sleeptime;
+    if(compare_timeval(eventer_max_sleeptime, __dyna_sleep) < 0)
+      __dyna_sleep = eventer_max_sleeptime;
+ 
+    __sleeptime = __dyna_sleep;
 
     eventer_dispatch_timed(&__now, &__sleeptime);
 
+    if(compare_timeval(__sleeptime, __dyna_sleep) > 0)
+      __sleeptime = __dyna_sleep;
+
     /* Handle recurrent events */
     eventer_dispatch_recurrent(&__now);
 
@@ -273,13 +281,23 @@
 
     ret = port_getn(port_fd, pevents, MAX_PORT_EVENTS, &fd_cnt,
                     &__ports_sleeptime);
-    noitLT(eventer_deb, &__now, "debug: port_getn(%d, [], %d) => %d\n", port_fd,
-           fd_cnt, ret);
+    /* The timeout case is a tad complex with ports.  -1/ETIME is clearly
+     * a timeout.  However, it i spossible that we got that and fd_cnt isn't
+     * 0, which means we both timed out and got events... WTF?
+     */
+    if(fd_cnt == 0 ||
+       (ret == -1 && errno == ETIME && pevents[0].portev_source == 65535))
+      add_timeval(__dyna_sleep, __dyna_increment, &__dyna_sleep);
+
+    if(ret == -1 && (errno != ETIME && errno != EINTR))
+      noitLT(eventer_err, &__now, "port_getn: %s\n", strerror(errno));
+
     if(ret < 0)
       noitLT(eventer_deb, &__now, "port_getn: %s\n", strerror(errno));
 
-    if(ret == -1 && (errno != ETIME && errno != EINTR))
-      noitLT(eventer_err, &__now, "port_getn: %s\n", strerror(errno));
+    noitLT(eventer_deb, &__now, "debug: port_getn(%d, [], %d) => %d\n", port_fd,
+           fd_cnt, ret);
+
     if(pevents[0].portev_source == 65535) {
       /* the impossible still remains, which means our fd_cnt _must_ be 0 */
       fd_cnt = 0;
@@ -288,6 +306,7 @@
     if(fd_cnt > 0) {
       int idx;
       /* Loop a last time to process */
+      __dyna_sleep.tv_sec = __dyna_sleep.tv_usec = 0; /* reset */
       for(idx = 0; idx < fd_cnt; idx++) {
         port_event_t *pe;
         eventer_t e;



More information about the Reconnoiter-devel mailing list