Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yazpp
[yazpp-moved-to-github.git] / src / yaz-pdu-assoc.cpp
index 2d17f11..ded89bd 100644 (file)
@@ -1,8 +1,11 @@
 /* This file is part of the yazpp toolkit.
- * Copyright (C) 1998-2011 Index Data and Mike Taylor
+ * Copyright (C) 1998-2012 Index Data and Mike Taylor
  * See the file LICENSE for details.
  */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <assert.h>
 #include <string.h>
 #include <yaz/log.h>
@@ -386,6 +389,8 @@ int PDU_Assoc::flush_PDU()
         yaz_log(m_log, "maskObserver 8");
         m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ|
                                          SOCKET_OBSERVE_EXCEPT);
+        if (m_session_is_dead)
+            shutdown();
     }
     return r;
 }
@@ -419,6 +424,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;