X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fyaz-pdu-assoc.cpp;h=e20837b77d9ac2ebfc108496ba2be812ce7cd77a;hb=c6e5ad789740135af3558298f6e2014ae99ee7dd;hp=334490f19f334d499f1511f164904124d4c47874;hpb=cc44793fb69db2885c570cc5de05fda796993bba;p=yazpp-moved-to-github.git diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index 334490f..e20837b 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -4,7 +4,13 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-pdu-assoc.cpp,v $ - * Revision 1.3 1999-02-02 14:01:20 adam + * Revision 1.5 1999-04-09 11:46:57 adam + * Added object Yaz_Z_Assoc. Much more functional client. + * + * Revision 1.4 1999/03/23 14:17:57 adam + * More work on timeout handling. Work on yaz-client. + * + * Revision 1.3 1999/02/02 14:01:20 adam * First WIN32 port of YAZ++. * * Revision 1.2 1999/01/28 13:08:44 adam @@ -52,7 +58,7 @@ Yaz_PDU_Assoc::~Yaz_PDU_Assoc() void Yaz_PDU_Assoc::socketNotify(int event) { - logf (LOG_LOG, "socketNotify p=%p event = %d", this, event); + logf (LOG_LOG, "Yaz_PDU_Assoc::socketNotify p=%p event = %d", this, event); if (m_state == Connected) { m_state = Ready; @@ -106,6 +112,8 @@ void Yaz_PDU_Assoc::socketNotify(int event) assoc->m_socketObservable->maskObserver(assoc, YAZ_SOCKET_OBSERVE_READ| YAZ_SOCKET_OBSERVE_EXCEPT); + if (m_idleTime) + assoc->m_socketObservable->timeoutObserver(assoc, m_idleTime); } } else if (m_state == Ready) @@ -137,6 +145,10 @@ void Yaz_PDU_Assoc::socketNotify(int event) return; } while (m_cs && cs_more (m_cs)); } + if (event & YAZ_SOCKET_OBSERVE_TIMEOUT) + { + m_PDU_Observer->timeoutNotify(); + } } } @@ -206,9 +218,12 @@ Yaz_PDU_Assoc::PDU_Queue::~PDU_Queue() int Yaz_PDU_Assoc::flush_PDU() { int r; - + + logf (LOG_LOG, "Yaz_PDU_Assoc::flush_PDU"); if (m_state != Ready) + { return 1; + } PDU_Queue *q = m_queue_out; if (!q) { @@ -228,13 +243,12 @@ int Yaz_PDU_Assoc::flush_PDU() m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ| YAZ_SOCKET_OBSERVE_EXCEPT| YAZ_SOCKET_OBSERVE_WRITE); - logf (LOG_LOG, "put %d bytes (incomplete write)", q->m_len); + logf (LOG_LOG, "flush_PDU put %d bytes (incomplete write)", q->m_len); return r; } - logf (LOG_LOG, "put %d bytes fd=%d", q->m_len, cs_fileno(m_cs)); + logf (LOG_LOG, "flush_PDU put %d bytes fd=%d", q->m_len, cs_fileno(m_cs)); // whole packet sent... delete this and proceed to next ... m_queue_out = q->m_next; - logf (LOG_LOG, "m_queue_out = %p", m_queue_out); delete q; // don't select on write if queue is empty ... if (!m_queue_out) @@ -245,7 +259,7 @@ int Yaz_PDU_Assoc::flush_PDU() int Yaz_PDU_Assoc::send_PDU(const char *buf, int len) { - logf (LOG_LOG, "send_PDU"); + logf (LOG_LOG, "Yaz_PDU_Assoc::send_PDU"); PDU_Queue **pq = &m_queue_out; int is_idle = (*pq ? 0 : 1); @@ -258,13 +272,9 @@ int Yaz_PDU_Assoc::send_PDU(const char *buf, int len) pq = &(*pq)->m_next; *pq = new PDU_Queue(buf, len); if (is_idle) - { return flush_PDU (); - } else - { logf (LOG_LOG, "cannot send_PDU fd=%d", cs_fileno(m_cs)); - } return 0; } @@ -301,6 +311,11 @@ void Yaz_PDU_Assoc::listen(IYaz_PDU_Observer *observer, m_state = Listen; } +void Yaz_PDU_Assoc::idleTime(int idleTime) +{ + m_idleTime = idleTime; +} + void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, const char *addr) { @@ -328,8 +343,14 @@ void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, YAZ_SOCKET_OBSERVE_EXCEPT| YAZ_SOCKET_OBSERVE_WRITE); if (res == 1) + { + logf (LOG_LOG, "Connect pending"); m_state = Connecting; + } else + { + logf (LOG_LOG, "Connect complete"); m_state = Connected; + } } }