X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-socket-manager.cpp;h=d872cf379211448fcd2fa583e4cc14549dc003d1;hb=5dddeb732a1409f9787cbdb3ce993f73a47f2dcc;hp=b6b789a8ed084fcc6481717405b42edd3dca32b4;hpb=8353663886b90d762d43790780be6cb58fb93c8a;p=yazpp-moved-to-github.git diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index b6b789a..d872cf3 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -1,8 +1,11 @@ /* This file is part of the yazpp toolkit. - * Copyright (C) 1998-2011 Index Data and Mike Taylor + * Copyright (C) 1998-2012 Index Data and Mike Taylor * See the file LICENSE for details. */ +#if HAVE_CONFIG_H +#include +#endif #if HAVE_SYS_TIME_H #include #endif @@ -36,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; @@ -165,7 +177,6 @@ void SocketManager::inspect_poll_result(int res, struct yaz_poll_fd *fds, yaz_log(YLOG_WARN, "unhandled socket event. yaz_poll returned %d", res); yaz_log(YLOG_WARN, "no_put_events=%d no_fds=%d i=%d timeout=%d", no_put_events, no_fds, i, timeout); - abort(); } } @@ -225,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; }