From 5dddeb732a1409f9787cbdb3ce993f73a47f2dcc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 17 Apr 2012 14:45:32 +0200 Subject: [PATCH] Add SocketManager::getNumberOfObservers Returns number of observers. --- include/yazpp/socket-manager.h | 1 + src/yaz-socket-manager.cpp | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/yazpp/socket-manager.h b/include/yazpp/socket-manager.h index e9970d9..25f99e8 100644 --- a/include/yazpp/socket-manager.h +++ b/include/yazpp/socket-manager.h @@ -81,6 +81,7 @@ class YAZ_EXPORT SocketManager : public ISocketObservable { int timeout); /// Process one event. return > 0 if event could be processed; int processEvent(); + int getNumberOfObservers(); SocketManager(); virtual ~SocketManager(); }; diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index e240e6f..d872cf3 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -39,6 +39,15 @@ SocketManager::SocketEntry **SocketManager::lookupObserver( return se; } +int SocketManager::getNumberOfObservers() +{ + int i = 0; + SocketEntry *se; + for (se = m_observers; se; se = se->next, i++) + ; + return i; +} + void SocketManager::addObserver(int fd, ISocketObserver *observer) { SocketEntry *se; @@ -227,21 +236,19 @@ int SocketManager::processEvent() } int pass = 0; - while ((res = yaz_poll(fds, no_fds, timeout, 0)) < 0) + while ((res = yaz_poll(fds, no_fds, timeout, 0)) < 0 && pass < 10) { - if (errno != EINTR) - { - yaz_log(YLOG_ERRNO|YLOG_WARN, "yaz_poll"); - yaz_log(YLOG_WARN, "errno=%d timeout=%d", errno, timeout); - if (++pass > 10) - return -1; - } + if (errno == EINTR) + continue; + yaz_log(YLOG_ERRNO|YLOG_WARN, "yaz_poll"); + yaz_log(YLOG_WARN, "errno=%d timeout=%d", errno, timeout); } - inspect_poll_result(res, fds, no_fds, timeout); + if (res >= 0) + inspect_poll_result(res, fds, no_fds, timeout); delete [] fds; - return 1; + return res >= 0 ? 1 : -1; } -- 1.7.10.4