Merge branch 'master' into graceful_stop
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 24 Apr 2012 12:40:26 +0000 (14:40 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 24 Apr 2012 12:40:26 +0000 (14:40 +0200)
include/yazpp/socket-manager.h
src/yaz-pdu-assoc.cpp
src/yaz-socket-manager.cpp

index e9970d9..25f99e8 100644 (file)
@@ -81,6 +81,7 @@ class YAZ_EXPORT SocketManager : public ISocketObservable {
                                  int timeout);
     /// Process one event. return > 0 if event could be processed;
     int processEvent();
+    int getNumberOfObservers();
     SocketManager();
     virtual ~SocketManager();
 };
index 8d6f577..b94213e 100644 (file)
@@ -422,6 +422,29 @@ COMSTACK PDU_Assoc::comstack(const char *type_and_host, void **vp)
 
 int PDU_Assoc::listen(IPDU_Observer *observer, const char *addr)
 {
+    if (*addr == '\0')
+    {
+        m_socketObservable->deleteObserver(this);
+        m_state = Closed;
+        if (m_cs)
+        {
+            yaz_log (m_log, "PDU_Assoc::close fd=%d", cs_fileno(m_cs));
+            cs_close (m_cs);
+        }
+        m_cs = 0;
+        while (m_queue_out)
+        {
+            PDU_Queue *q_this = m_queue_out;
+            m_queue_out = m_queue_out->m_next;
+            delete q_this;
+        }
+        xfree (m_input_buf);
+        m_input_buf = 0;
+        m_input_len = 0;
+        
+        return 0;
+    }
+
     shutdown();
 
     m_PDU_Observer = observer;
index 62182d8..d872cf3 100644 (file)
@@ -39,6 +39,15 @@ SocketManager::SocketEntry **SocketManager::lookupObserver(
     return se;
 }
 
+int SocketManager::getNumberOfObservers()
+{
+    int i = 0;
+    SocketEntry *se;
+    for (se = m_observers; se; se = se->next, i++)
+        ;
+    return i;
+}
+
 void SocketManager::addObserver(int fd, ISocketObserver *observer)
 {
     SocketEntry *se;
@@ -168,7 +177,6 @@ void SocketManager::inspect_poll_result(int res, struct yaz_poll_fd *fds,
         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();
     }
 }
 
@@ -228,21 +236,19 @@ int SocketManager::processEvent()
     }
 
     int pass = 0;
-    while ((res = yaz_poll(fds, no_fds, timeout, 0)) < 0)
+    while ((res = yaz_poll(fds, no_fds, timeout, 0)) < 0 && pass < 10)
     {
-        if (errno != EINTR)
-        {
-            yaz_log(YLOG_ERRNO|YLOG_WARN, "yaz_poll");
-            yaz_log(YLOG_WARN, "errno=%d timeout=%d", errno, timeout);
-            if (++pass > 10)
-                return -1;
-        }
+        if (errno == EINTR)
+            continue;
+        yaz_log(YLOG_ERRNO|YLOG_WARN, "yaz_poll");
+        yaz_log(YLOG_WARN, "errno=%d timeout=%d", errno, timeout);
     }
 
-    inspect_poll_result(res, fds, no_fds, timeout);
+    if (res >= 0)
+        inspect_poll_result(res, fds, no_fds, timeout);
 
     delete [] fds;
-    return 1;
+    return res >= 0 ? 1 : -1;
 }