From 933909a6cfd5dcacc446f45e7217849b917abefd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 20 Nov 2000 11:27:33 +0000 Subject: [PATCH] Fixes for connect operation (timeout and notify fix). --- buildconf.sh | 4 ++-- src/yaz-pdu-assoc.cpp | 44 +++++++++++++++++++++++++------------------- src/yaz-proxy.cpp | 11 ++++++++--- src/yaz-socket-manager.cpp | 9 +++++++-- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/buildconf.sh b/buildconf.sh index 82489d2..c0873b3 100755 --- a/buildconf.sh +++ b/buildconf.sh @@ -1,6 +1,6 @@ #!/bin/sh -# $Id: buildconf.sh,v 1.2 2000-10-26 21:31:50 adam Exp $ +# $Id: buildconf.sh,v 1.3 2000-11-20 11:27:33 adam Exp $ aclocal -libtoolize +libtoolize --force automake -a autoconf diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index eef59a6..a816d48 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-pdu-assoc.cpp,v $ - * Revision 1.19 2000-11-01 14:22:59 adam + * Revision 1.20 2000-11-20 11:27:33 adam + * Fixes for connect operation (timeout and notify fix). + * + * Revision 1.19 2000/11/01 14:22:59 adam * Added fd parameter for method IYaz_PDU_Observer::clone. * * Revision 1.18 2000/10/24 12:29:57 adam @@ -102,16 +105,9 @@ IYaz_PDU_Observable *Yaz_PDU_Assoc::clone() void Yaz_PDU_Assoc::socketNotify(int event) { logf (m_log, "Yaz_PDU_Assoc::socketNotify p=%p event = %d", this, event); - if (0 /* m_state == Connected */) - { - m_state = Ready; - m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ| - YAZ_SOCKET_OBSERVE_EXCEPT); - m_PDU_Observer->connectNotify(); - flush_PDU(); - } - else if (m_state == Connecting) + switch (m_state) { + case Connecting: if (event & YAZ_SOCKET_OBSERVE_READ) { close(); @@ -129,9 +125,8 @@ void Yaz_PDU_Assoc::socketNotify(int event) m_PDU_Observer->connectNotify(); flush_PDU(); } - } - else if (m_state == Listen) - { + break; + case Listen: if (event & YAZ_SOCKET_OBSERVE_READ) { int res; @@ -158,9 +153,8 @@ void Yaz_PDU_Assoc::socketNotify(int event) cs_close (new_line); childNotify(fd); } - } - else if (m_state == Ready) - { + break; + case Ready: if (event & YAZ_SOCKET_OBSERVE_WRITE) { flush_PDU(); @@ -193,6 +187,16 @@ void Yaz_PDU_Assoc::socketNotify(int event) { m_PDU_Observer->timeoutNotify(); } + break; + case Closed: + logf (m_log, "CLOSING state=%d event was %d", m_state, event); + close(); + m_PDU_Observer->failNotify(); + break; + default: + logf (m_log, "Unknown state=%d event was %d", m_state, event); + close(); + m_PDU_Observer->failNotify(); } } @@ -382,9 +386,11 @@ void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, logf (m_log, "Yaz_PDU_Assoc::connect fd=%d res=%d", cs_fileno(cs), res); m_socketObservable->addObserver(cs_fileno(cs), this); m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ| - YAZ_SOCKET_OBSERVE_EXCEPT| - YAZ_SOCKET_OBSERVE_WRITE); - m_state = Connecting; + YAZ_SOCKET_OBSERVE_EXCEPT| + YAZ_SOCKET_OBSERVE_WRITE); + if (res >= 0) + m_state = Connecting; + // if res < 0, then cs_connect failed immediately. state is Closed.. } void Yaz_PDU_Assoc::socket(IYaz_PDU_Observer *observer, int fd) diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 72969d3..e0ec329 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-proxy.cpp,v $ - * Revision 1.21 2000-11-01 14:22:59 adam + * Revision 1.22 2000-11-20 11:27:33 adam + * Fixes for connect operation (timeout and notify fix). + * + * Revision 1.21 2000/11/01 14:22:59 adam * Added fd parameter for method IYaz_PDU_Observer::clone. * * Revision 1.20 2000/10/24 12:29:57 adam @@ -301,7 +304,7 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) c->m_last_resultCount = 0; c->m_sr_transform = 0; c->m_waiting = 0; - c->timeout(600); + c->timeout(10); (parent->m_seqno)++; } @@ -478,7 +481,9 @@ void Yaz_ProxyClient::failNotify() void Yaz_ProxyClient::connectNotify() { - logf (LOG_LOG, "Yaz_ProxyClient connection accept by %s", get_hostname()); + logf (LOG_LOG, "Yaz_ProxyClient connection accepted by %s", + get_hostname()); + timeout(600); } IYaz_PDU_Observer *Yaz_ProxyClient::clone(IYaz_PDU_Observable diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index 376a079..37ad03f 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-socket-manager.cpp,v $ - * Revision 1.12 2000-10-24 12:29:57 adam + * Revision 1.13 2000-11-20 11:27:33 adam + * Fixes for connect operation (timeout and notify fix). + * + * Revision 1.12 2000/10/24 12:29:57 adam * Fixed bug in proxy where a Yaz_ProxyClient could be owned by * two Yaz_Proxy's (fatal). * @@ -174,6 +177,8 @@ int Yaz_SocketManager::processEvent() timeout_this = p->timeout; if (p->last_activity) timeout_this -= now - p->last_activity; + else + p->last_activity = now; if (timeout_this < 1) timeout_this = 1; if (!timeout || timeout_this < timeout) @@ -222,7 +227,7 @@ int Yaz_SocketManager::processEvent() now >= p->last_activity + (int) (p->timeout)) { YazSocketEvent *event = new YazSocketEvent; - logf (LOG_LOG, "timeout now = %ld last_activity=%ld timeout=%d", + logf (m_log, "timeout, now = %ld last_activity=%ld timeout=%d", now, p->last_activity, p->timeout); p->last_activity = now; event->observer = p->observer; -- 1.7.10.4