From: Adam Dickmeiss Date: Mon, 21 Jan 2008 15:57:27 +0000 (+0000) Subject: Changed IPDU_Observer's interface WRT close. X-Git-Tag: YAZPP.1.1.0~6 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=e432b52c33a684e9f90627b971d14da6b362daff;p=yazpp-moved-to-github.git Changed IPDU_Observer's interface WRT close. The IDPU_Observer method, close, renamed to shutdown. Method hutdown shuts down the socket connection (immediately). Added new method, close_session, which closes the connection as soon as it becomes idle (when everything in queue is flushed). These changes should make it possible to fix bug #1130. --- diff --git a/include/yazpp/pdu-assoc.h b/include/yazpp/pdu-assoc.h index d0fdeb7..2f377b8 100644 --- a/include/yazpp/pdu-assoc.h +++ b/include/yazpp/pdu-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: pdu-assoc.h,v 1.1 2006-03-29 13:14:15 adam Exp $ + * $Id: pdu-assoc.h,v 1.2 2008-01-21 15:57:27 adam Exp $ */ #ifndef YAZ_PDU_ASSOC_INCLUDED @@ -53,6 +53,7 @@ class YAZ_EXPORT PDU_Assoc : public IPDU_Observable, yazpp_1::ISocketObserver { int m_idleTime; int m_log; void init(yazpp_1::ISocketObservable *socketObservable); + bool m_session_is_dead; public: COMSTACK comstack(const char *type_and_host, void **vp); /// Create object using specified socketObservable @@ -73,13 +74,15 @@ class YAZ_EXPORT PDU_Assoc : public IPDU_Observable, yazpp_1::ISocketObserver { /// Socket notification void socketNotify(int event); /// Close socket - void close(); + void shutdown(); /// Close and destroy void destroy(); /// Set Idle Time void idleTime (int timeout); /// Child start... virtual void childNotify(COMSTACK cs); + /// close session + void close_session(); const char *getpeername(); }; diff --git a/include/yazpp/pdu-observer.h b/include/yazpp/pdu-observer.h index 3af0bd9..dfe2596 100644 --- a/include/yazpp/pdu-observer.h +++ b/include/yazpp/pdu-observer.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: pdu-observer.h,v 1.1 2006-03-29 13:14:15 adam Exp $ + * $Id: pdu-observer.h,v 1.2 2008-01-21 15:57:27 adam Exp $ */ #ifndef YAZ_PDU_OBSERVER_H @@ -29,7 +29,7 @@ class YAZ_EXPORT IPDU_Observable { /// Listen on address addr. virtual int listen(IPDU_Observer *observer, const char *addr) = 0; /// Close connection - virtual void close() = 0; + virtual void shutdown() = 0; /// Make clone of this object using this interface virtual IPDU_Observable *clone() = 0; /// Destroy completely @@ -38,6 +38,8 @@ class YAZ_EXPORT IPDU_Observable { virtual void idleTime (int timeout) = 0; /// Get peername virtual const char *getpeername() = 0; + /// Close session + virtual void close_session() = 0; virtual ~IPDU_Observable(); }; diff --git a/src/yaz-pdu-assoc-thread.cpp b/src/yaz-pdu-assoc-thread.cpp index 5957ac4..4612ad4 100644 --- a/src/yaz-pdu-assoc-thread.cpp +++ b/src/yaz-pdu-assoc-thread.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-pdu-assoc-thread.cpp,v 1.15 2006-03-30 11:58:00 adam Exp $ + * $Id: yaz-pdu-assoc-thread.cpp,v 1.16 2008-01-21 15:57:27 adam Exp $ */ #ifdef WIN32 @@ -85,7 +85,7 @@ void PDU_AssocThread::childNotify(COMSTACK cs) if (!new_observable->m_PDU_Observer) { - new_observable->close(); + new_observable->shutdown(); delete new_observable; delete socket_observable; return; diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index 89e427d..73bd0a8 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-pdu-assoc.cpp,v 1.46 2006-03-30 11:58:00 adam Exp $ + * $Id: yaz-pdu-assoc.cpp,v 1.47 2008-01-21 15:57:27 adam Exp $ */ #include @@ -30,6 +30,7 @@ void PDU_Assoc::init(ISocketObservable *socketObservable) m_destroyed = 0; m_idleTime = 0; m_log = YLOG_DEBUG; + m_session_is_dead = false; } PDU_Assoc::PDU_Assoc(ISocketObservable *socketObservable) @@ -79,7 +80,7 @@ void PDU_Assoc::socketNotify(int event) this, m_state, event); if (event & SOCKET_OBSERVE_EXCEPT) { - close(); + shutdown(); m_PDU_Observer->failNotify(); return; } @@ -95,7 +96,7 @@ void PDU_Assoc::socketNotify(int event) { yaz_log (m_log, "PDU_Assoc::cs_accept failed"); m_cs = 0; - close(); + shutdown(); m_PDU_Observer->failNotify(); } else @@ -123,7 +124,7 @@ void PDU_Assoc::socketNotify(int event) event & SOCKET_OBSERVE_WRITE) { // For Unix: if both read and write is set, then connect failed. - close(); + shutdown(); m_PDU_Observer->failNotify(); } else @@ -199,7 +200,7 @@ void PDU_Assoc::socketNotify(int event) else if (res <= 0) { yaz_log (m_log, "PDU_Assoc::Connection closed by peer"); - close(); + shutdown(); if (m_PDU_Observer) m_PDU_Observer->failNotify(); // problem here.. return; @@ -234,21 +235,31 @@ void PDU_Assoc::socketNotify(int event) break; case Closed: yaz_log (m_log, "CLOSING state=%d event was %d", m_state, event); - close(); + shutdown(); m_PDU_Observer->failNotify(); break; default: yaz_log (m_log, "Unknown state=%d event was %d", m_state, event); - close(); + shutdown(); m_PDU_Observer->failNotify(); } } -void PDU_Assoc::close() +void PDU_Assoc::close_session() +{ + m_session_is_dead = true; + if (!m_queue_out) + { + shutdown(); + m_PDU_Observer->failNotify(); + } +} + +void PDU_Assoc::shutdown() { PDU_Assoc *ch; for (ch = m_children; ch; ch = ch->m_next) - ch->close(); + ch->shutdown(); m_socketObservable->deleteObserver(this); m_state = Closed; @@ -271,7 +282,7 @@ void PDU_Assoc::close() void PDU_Assoc::destroy() { - close(); + shutdown(); if (m_destroyed) *m_destroyed = 1; @@ -331,13 +342,18 @@ int PDU_Assoc::flush_PDU() m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| SOCKET_OBSERVE_WRITE| SOCKET_OBSERVE_EXCEPT); + if (m_session_is_dead) + { + shutdown(); + m_PDU_Observer->failNotify(); + } return 0; } r = cs_put (m_cs, q->m_buf, q->m_len); if (r < 0) { yaz_log (m_log, "PDU_Assoc::flush_PDU cs_put failed"); - close(); + shutdown(); m_PDU_Observer->failNotify(); return r; } @@ -401,7 +417,7 @@ COMSTACK PDU_Assoc::comstack(const char *type_and_host, void **vp) int PDU_Assoc::listen(IPDU_Observer *observer, const char *addr) { - close(); + shutdown(); m_PDU_Observer = observer; void *ap; @@ -430,7 +446,7 @@ void PDU_Assoc::idleTime(int idleTime) int PDU_Assoc::connect(IPDU_Observer *observer, const char *addr) { yaz_log (m_log, "PDU_Assoc::connect %s", addr); - close(); + shutdown(); m_PDU_Observer = observer; void *ap; m_cs = comstack(addr, &ap); @@ -484,7 +500,7 @@ void PDU_Assoc::childNotify(COMSTACK cs) if (!new_observable->m_PDU_Observer) { - new_observable->close(); + new_observable->shutdown(); delete new_observable; return; } diff --git a/src/yaz-z-assoc.cpp b/src/yaz-z-assoc.cpp index b0eae8a..f6acc2d 100644 --- a/src/yaz-z-assoc.cpp +++ b/src/yaz-z-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2007, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-assoc.cpp,v 1.43 2007-05-08 12:04:50 adam Exp $ + * $Id: yaz-z-assoc.cpp,v 1.44 2008-01-21 15:57:28 adam Exp $ */ #include @@ -292,7 +292,7 @@ int Z_Assoc::client(const char *addr) void Z_Assoc::close() { - m_PDU_Observable->close (); + m_PDU_Observable->close_session(); } int Z_Assoc::server(const char *addr)