From 7fc0fddcb85cd64461c7b3dd3e68791eb88b40be Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 10 Oct 2003 12:37:26 +0000 Subject: [PATCH] Graceful handling of comstack creation failure --- include/yaz++/pdu-assoc.h | 4 ++-- include/yaz++/pdu-observer.h | 4 ++-- include/yaz++/z-assoc.h | 4 ++-- src/yaz-pdu-assoc.cpp | 10 ++++------ src/yaz-proxy.cpp | 16 ++++++++++++---- src/yaz-z-assoc.cpp | 6 +++--- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/include/yaz++/pdu-assoc.h b/include/yaz++/pdu-assoc.h index fd217b4..38a0d66 100644 --- a/include/yaz++/pdu-assoc.h +++ b/include/yaz++/pdu-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: pdu-assoc.h,v 1.2 2003-10-01 13:13:51 adam Exp $ + * $Id: pdu-assoc.h,v 1.3 2003-10-10 12:37:26 adam Exp $ */ #ifndef YAZ_PDU_ASSOC_INCLUDED @@ -65,7 +65,7 @@ class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver /// Send PDU int send_PDU(const char *buf, int len); /// connect to server (client role) - void connect(IYaz_PDU_Observer *observer, const char *addr); + int connect(IYaz_PDU_Observer *observer, const char *addr); /// listen for clients (server role) void listen(IYaz_PDU_Observer *observer, const char *addr); /// Socket notification diff --git a/include/yaz++/pdu-observer.h b/include/yaz++/pdu-observer.h index d391189..dda0ca8 100644 --- a/include/yaz++/pdu-observer.h +++ b/include/yaz++/pdu-observer.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. * - * $Id: pdu-observer.h,v 1.2 2003-10-01 13:13:51 adam Exp $ + * $Id: pdu-observer.h,v 1.3 2003-10-10 12:37:26 adam Exp $ */ #ifndef YAZ_PDU_OBSERVER_H @@ -21,7 +21,7 @@ class YAZ_EXPORT IYaz_PDU_Observable { /// Send encoded PDU buffer of specified length virtual int send_PDU(const char *buf, int len) = 0; /// Connect with server specified by addr. - virtual void connect(IYaz_PDU_Observer *observer, const char *addr) = 0; + virtual int connect(IYaz_PDU_Observer *observer, const char *addr) = 0; /// Listen on address addr. virtual void listen(IYaz_PDU_Observer *observer, const char *addr) = 0; /// Close connection diff --git a/include/yaz++/z-assoc.h b/include/yaz++/z-assoc.h index ada736b..13f57fe 100644 --- a/include/yaz++/z-assoc.h +++ b/include/yaz++/z-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. * - * $Id: z-assoc.h,v 1.2 2003-10-01 13:13:51 adam Exp $ + * $Id: z-assoc.h,v 1.3 2003-10-10 12:37:26 adam Exp $ */ #ifndef YAZ_Z_ASSOC_INCLUDED @@ -33,7 +33,7 @@ class YAZ_EXPORT Yaz_Z_Assoc : public IYaz_PDU_Observer { /// Timeout specify void timeout(int timeout); /// Begin Z39.50 client role - void client(const char *addr); + int client(const char *addr); /// Begin Z39.50 server role void server(const char *addr); /// Close connection diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index 2b73275..50ebbe7 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-pdu-assoc.cpp,v 1.32 2003-10-10 10:50:37 adam Exp $ + * $Id: yaz-pdu-assoc.cpp,v 1.33 2003-10-10 12:37:26 adam Exp $ */ #include @@ -420,7 +420,7 @@ void Yaz_PDU_Assoc::idleTime(int idleTime) m_socketObservable->timeoutObserver(this, m_idleTime); } -void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, +int Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, const char *addr) { yaz_log (m_log, "Yaz_PDU_Assoc::connect %s", addr); @@ -429,10 +429,7 @@ void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, void *ap; m_cs = comstack(addr, &ap); if (!m_cs) - { - m_PDU_Observer->failNotify(); - return; - } + return -1; int res = cs_connect (m_cs, ap); yaz_log (m_log, "Yaz_PDU_Assoc::connect fd=%d res=%d", cs_fileno(m_cs), res); @@ -466,6 +463,7 @@ void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_WRITE| YAZ_SOCKET_OBSERVE_EXCEPT); } + return 0; } // Single-threaded... Only useful for non-blocking handlers diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index fb49caf..d80d24e 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.54 2003-10-09 12:11:10 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.55 2003-10-10 12:37:26 adam Exp $ */ #include @@ -288,7 +288,6 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) yaz_log (LOG_LOG, "%s REOPEN target=%s", m_session_str, c->get_hostname()); c->close(); - c->client(m_proxyTarget); c->m_init_flag = 0; c->m_last_ok = 0; @@ -297,6 +296,11 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) c->m_sr_transform = 0; c->m_waiting = 0; c->m_resultSetStartPoint = 0; + if (c->client(m_proxyTarget)) + { + delete c; + return 0; + } c->timeout(m_target_idletime); } c->m_seqno = parent->m_seqno; @@ -429,7 +433,6 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) c->m_cookie = xstrdup(cookie); c->m_seqno = parent->m_seqno; - c->client(m_proxyTarget); c->m_init_flag = 0; c->m_last_resultCount = 0; c->m_last_ok = 0; @@ -437,9 +440,14 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) c->m_sr_transform = 0; c->m_waiting = 0; c->m_resultSetStartPoint = 0; + (parent->m_seqno)++; + if (c->client(m_proxyTarget)) + { + delete c; + return 0; + } c->timeout(30); - (parent->m_seqno)++; } yaz_log (LOG_DEBUG, "get_client 3 %p %p", this, c); return c; diff --git a/src/yaz-z-assoc.cpp b/src/yaz-z-assoc.cpp index 91b47ce..1990698 100644 --- a/src/yaz-z-assoc.cpp +++ b/src/yaz-z-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-assoc.cpp,v 1.26 2003-10-01 13:13:51 adam Exp $ + * $Id: yaz-z-assoc.cpp,v 1.27 2003-10-10 12:37:26 adam Exp $ */ #include @@ -233,12 +233,12 @@ const char *Yaz_Z_Assoc::get_hostname() return m_hostname; } -void Yaz_Z_Assoc::client(const char *addr) +int Yaz_Z_Assoc::client(const char *addr) { delete [] m_hostname; m_hostname = new char[strlen(addr)+1]; strcpy (m_hostname, addr); - m_PDU_Observable->connect (this, addr); + return m_PDU_Observable->connect (this, addr); } void Yaz_Z_Assoc::close() -- 1.7.10.4