Latest m4
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 15 Apr 2008 08:14:02 +0000 (10:14 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 15 Apr 2008 08:14:02 +0000 (10:14 +0200)
include/yazpp/socket-manager.h
m4
src/yaz-socket-manager.cpp

index f7be9e6..b4e26ff 100644 (file)
@@ -11,6 +11,7 @@
 #include <yazpp/socket-observer.h>
 #include <time.h>
 
+struct yaz_poll_fd;
 namespace yazpp_1 {
 
 /** Simple Socket Manager.
@@ -44,6 +45,8 @@ class YAZ_EXPORT SocketManager : public ISocketObservable {
     void putEvent(SocketEvent *event);
     void removeEvent(ISocketObserver *observer);
     int m_log;
+    void inspect_poll_result(int res, struct yaz_poll_fd *fds, int no_fds,
+                             int timeout);
  public:
     /// Add an observer
     virtual void addObserver(int fd, ISocketObserver *observer);
diff --git a/m4 b/m4
index a3d7a33..9763824 160000 (submodule)
--- a/m4
+++ b/m4
@@ -1 +1 @@
-Subproject commit a3d7a3375702caae9794ae3a724e51ae9ee46ac3
+Subproject commit 9763824ebc2240e71a2eff5bb5b3775ab56d0508
index c623b20..7d771ad 100644 (file)
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <string.h>
 #include <assert.h>
+#include <stdlib.h>
 
 #include <yaz/log.h>
 
@@ -104,6 +105,72 @@ void SocketManager::timeoutObserver(ISocketObserver *observer,
         se->timeout = timeout;
 }
 
+
+void SocketManager::inspect_poll_result(int res, struct yaz_poll_fd *fds,
+                                        int no_fds, int timeout)
+
+{
+    yaz_log(m_log, "yaz_poll returned res=%d", res);
+    time_t now = time(0);
+    int i;
+    int no_put_events = 0;
+    SocketEntry *p;
+
+    for (i = 0, p = m_observers; p; p = p->next, i++)
+    {
+        enum yaz_poll_mask output_mask = fds[i].output_mask;
+
+        int mask = 0;
+        if (output_mask & yaz_poll_read)
+            mask |= SOCKET_OBSERVE_READ;
+
+        if (output_mask & yaz_poll_write)
+            mask |= SOCKET_OBSERVE_WRITE;
+
+        if (output_mask & yaz_poll_except)
+            mask |= SOCKET_OBSERVE_EXCEPT;
+        
+        if (mask)
+        {
+            SocketEvent *event = new SocketEvent;
+            p->last_activity = now;
+            event->observer = p->observer;
+            event->event = mask;
+            putEvent (event);
+            no_put_events++;
+            yaz_log (m_log, "putEvent I/O mask=%d", mask);
+        }
+        else if (res == 0 && p->timeout_this == timeout)
+        {
+            SocketEvent *event = new SocketEvent;
+            assert (p->last_activity);
+            yaz_log (m_log, "putEvent timeout fd=%d, now = %ld last_activity=%ld timeout=%d",
+                     p->fd, now, p->last_activity, p->timeout);
+            p->last_activity = now;
+            event->observer = p->observer;
+            event->event = SOCKET_OBSERVE_TIMEOUT;
+            putEvent (event);
+            no_put_events++;
+            
+        }
+    }
+    SocketEvent *event = getEvent();
+    if (event)
+    {
+        event->observer->socketNotify(event->event);
+        delete event;
+    }
+    else
+    {
+        // bug #2035
+        
+        yaz_log(YLOG_WARN, "unhandled socket event. yaz_poll returned %d", res);
+        yaz_log(YLOG_WARN, "no_put_events=%d no_fds=%d i=%d timeout=%d",
+                no_put_events, no_fds, i, timeout);
+        abort();
+    }
+}
+
 int SocketManager::processEvent()
 {
     SocketEntry *p;
@@ -170,53 +237,10 @@ int SocketManager::processEvent()
                 return -1;
         }
     }
-    
-    yaz_log(m_log, "select returned res=%d", res);
-    now = time(0);
-    for (i = 0, p = m_observers; p; p = p->next, i++)
-    {
-        enum yaz_poll_mask output_mask = fds[i].output_mask;
-
-        int mask = 0;
-        if (output_mask & yaz_poll_read)
-            mask |= SOCKET_OBSERVE_READ;
 
-        if (output_mask & yaz_poll_write)
-            mask |= SOCKET_OBSERVE_WRITE;
+    inspect_poll_result(res, fds, no_fds, timeout);
 
-        if (output_mask & yaz_poll_except)
-            mask |= SOCKET_OBSERVE_EXCEPT;
-        
-        if (mask)
-        {
-            SocketEvent *event = new SocketEvent;
-            p->last_activity = now;
-            event->observer = p->observer;
-            event->event = mask;
-            putEvent (event);
-
-            yaz_log (m_log, "putEvent I/O mask=%d", mask);
-        }
-        else if (res == 0 && p->timeout_this == timeout)
-        {
-            SocketEvent *event = new SocketEvent;
-            assert (p->last_activity);
-            yaz_log (m_log, "putEvent timeout fd=%d, now = %ld last_activity=%ld timeout=%d",
-                     p->fd, now, p->last_activity, p->timeout);
-            p->last_activity = now;
-            event->observer = p->observer;
-            event->event = SOCKET_OBSERVE_TIMEOUT;
-            putEvent (event);
-        }
-    }
     delete [] fds;
-    if ((event = getEvent()))
-    {
-        event->observer->socketNotify(event->event);
-        delete event;
-        return 1;
-    }
-    yaz_log(YLOG_WARN, "unhandled event in processEvent res=%d", res);
     return 1;
 }