/*
- * Copyright (c) 1998-2001, Index Data.
+ * Copyright (c) 1998-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-socket-manager.cpp,v 1.17 2001-11-04 22:36:21 adam Exp $
+ * $Id: yaz-socket-manager.cpp,v 1.24 2004-01-07 13:40:06 adam Exp $
*/
#include <assert.h>
#ifdef WIN32
#include <string.h>
#include <yaz/log.h>
-#include <yaz++/yaz-socket-manager.h>
+#include <yaz++/socket-manager.h>
Yaz_SocketManager::YazSocketEntry **Yaz_SocketManager::lookupObserver(
IYazSocketObserver *observer)
se->fd = fd;
se->mask = 0;
se->last_activity = 0;
- se->timeout = 0;
+ se->timeout = -1;
}
void Yaz_SocketManager::deleteObserver(IYazSocketObserver *observer)
{
YazSocketEntry *se;
+ yaz_log(m_log, "obs=%p read=%d write=%d except=%d", observer,
+ mask & YAZ_SOCKET_OBSERVE_READ,
+ mask & YAZ_SOCKET_OBSERVE_WRITE,
+ mask & YAZ_SOCKET_OBSERVE_EXCEPT);
+
se = *lookupObserver(observer);
if (se)
se->mask = mask;
}
void Yaz_SocketManager::timeoutObserver(IYazSocketObserver *observer,
- unsigned timeout)
+ int timeout)
{
YazSocketEntry *se;
{
YazSocketEntry *p;
YazSocketEvent *event = getEvent();
- unsigned timeout = 0;
+ int timeout = -1;
yaz_log (m_log, "Yaz_SocketManager::processEvent manager=%p", this);
if (event)
{
}
if (fd > max)
max = fd;
- if (p->timeout)
+ if (p->timeout >= 0)
{
- unsigned timeout_this;
+ int timeout_this;
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)
+ if (timeout_this < 0 || timeout_this > 2147483646)
+ timeout_this = 0;
+ if (timeout == -1 || timeout_this < timeout)
timeout = timeout_this;
p->timeout_this = timeout_this;
yaz_log (m_log, "Yaz_SocketManager::select timeout_this=%d",
yaz_log (m_log, "Yaz_SocketManager::select begin no=%d timeout=%d",
no, timeout);
- while ((res = select(max + 1, &in, &out, &except, timeout ? &to : 0)) < 0)
+ while ((res = select(max + 1, &in, &out, &except,
+ timeout== -1 ? 0 : &to)) < 0)
if (errno != EINTR)
+ {
+ yaz_log (LOG_LOG|LOG_WARN, "select");
return -1;
+ }
now = time(0);
for (p = m_observers; p; p = p->next)
{
event->observer = p->observer;
event->event = mask;
putEvent (event);
+
+ yaz_log (m_log, "putEvent I/O mask=%d", mask);
}
- else if (res == 0 && p->timeout && p->timeout_this == timeout)
+ else if (p->timeout && (now - p->last_activity) >= p->timeout)
{
YazSocketEvent *event = new YazSocketEvent;
assert (p->last_activity);
- yaz_log (m_log, "timeout, now = %ld last_activity=%ld timeout=%d",
+ yaz_log (m_log, "putEvent timeout, now = %ld last_activity=%ld timeout=%d",
now, p->last_activity, p->timeout);
p->last_activity = now;
event->observer = p->observer;