From a07200295daa103c01535d72e64dd8b295f93289 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 9 Nov 2007 21:49:15 +0000 Subject: [PATCH] Using yaz_poll instead of select. SocketManager::processEvent uses yaz_poll instead of select. This requires YAZ 3.0.15 or later. --- configure.ac | 4 +-- src/yaz-socket-manager.cpp | 82 ++++++++++++++++---------------------------- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/configure.ac b/configure.ac index 0693a0b..edb8747 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl YAZ++ Toolkit, Index Data 1994-2007 dnl See the file LICENSE for details. -dnl $Id: configure.ac,v 1.17 2007-05-08 12:04:50 adam Exp $ +dnl $Id: configure.ac,v 1.18 2007-11-09 21:49:15 adam Exp $ AC_PREREQ(2.59) AC_INIT([yazpp],[1.0.3],[adam@indexdata.dk]) AC_CONFIG_SRCDIR(configure.ac) @@ -13,7 +13,7 @@ AC_PROG_CXX AC_HEADER_STDC AM_PROG_LIBTOOL -YAZ_INIT([threads],[3.0.2]) +YAZ_INIT([threads],[3.0.15]) if test -z "$YAZLIB"; then AC_MSG_ERROR([YAZ development libraries missing]) fi diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index 1a2d472..edc56af 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -2,11 +2,8 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: yaz-socket-manager.cpp,v 1.36 2006-03-29 13:14:17 adam Exp $ + * $Id: yaz-socket-manager.cpp,v 1.37 2007-11-09 21:49:15 adam Exp $ */ -#ifdef WIN32 -#include -#endif #if HAVE_SYS_TIME_H #include @@ -23,7 +20,9 @@ #include #include + #include +#include using namespace yazpp_1; @@ -118,38 +117,26 @@ int SocketManager::processEvent() return 1; } - fd_set in, out, except; int res; - int max = 0; - int no = 0; - - FD_ZERO(&in); - FD_ZERO(&out); - FD_ZERO(&except); - time_t now = time(0); + int i; + int no_fds = 0; for (p = m_observers; p; p = p->next) + no_fds++; + + if (!no_fds) + return 0; + struct yaz_poll_fd *fds = new yaz_poll_fd [no_fds]; + for (i = 0, p = m_observers; p; p = p->next, i++) { - int fd = p->fd; - if (p->mask) - no++; + fds[i].fd = p->fd; + int input_mask = 0; if (p->mask & SOCKET_OBSERVE_READ) - { - yaz_log (m_log, "SocketManager::select fd=%d read", fd); - FD_SET(fd, &in); - } + input_mask += yaz_poll_read; if (p->mask & SOCKET_OBSERVE_WRITE) - { - yaz_log (m_log, "SocketManager::select fd=%d write", fd); - FD_SET(fd, &out); - } + input_mask += yaz_poll_write; if (p->mask & SOCKET_OBSERVE_EXCEPT) - { - yaz_log (m_log, "SocketManager::select fd=%d except", fd); - FD_SET(fd, &except); - } - if (fd > max) - max = fd; + input_mask += yaz_poll_except; if (p->timeout > 0 || (p->timeout == 0 && (p->mask & SOCKET_OBSERVE_WRITE) == 0)) { @@ -169,45 +156,35 @@ int SocketManager::processEvent() } else p->timeout_this = -1; - } - if (!no) - { - yaz_log (m_log, "no pending events return 0"); - if (!m_observers) - yaz_log (m_log, "no observers"); - return 0; + fds[i].input_mask = (enum yaz_poll_mask) input_mask; } - struct timeval to; - to.tv_sec = timeout; - to.tv_usec = 0; - - yaz_log (m_log, "SocketManager::select begin no=%d timeout=%d", - no, timeout); int pass = 0; - while ((res = select(max + 1, &in, &out, &except, - timeout== -1 ? 0 : &to)) < 0) + while ((res = yaz_poll(fds, no_fds, timeout)) < 0) + { if (errno != EINTR) { - yaz_log(YLOG_ERRNO|YLOG_WARN, "select"); - yaz_log(YLOG_WARN, "errno=%d max=%d timeout=%d", - errno, max, timeout); + yaz_log(YLOG_ERRNO|YLOG_WARN, "yaz_poll"); + yaz_log(YLOG_WARN, "errno=%d timeout=%d", errno, timeout); if (++pass > 10) return -1; } + } + yaz_log(m_log, "select returned res=%d", res); now = time(0); - for (p = m_observers; p; p = p->next) + for (i = 0, p = m_observers; p; p = p->next, i++) { - int fd = p->fd; + enum yaz_poll_mask output_mask = fds[i].output_mask; + int mask = 0; - if (FD_ISSET(fd, &in)) + if (output_mask & yaz_poll_read) mask |= SOCKET_OBSERVE_READ; - if (FD_ISSET(fd, &out)) + if (output_mask & yaz_poll_write) mask |= SOCKET_OBSERVE_WRITE; - if (FD_ISSET(fd, &except)) + if (output_mask & yaz_poll_except) mask |= SOCKET_OBSERVE_EXCEPT; if (mask) @@ -232,6 +209,7 @@ int SocketManager::processEvent() putEvent (event); } } + delete [] fds; if ((event = getEvent())) { event->observer->socketNotify(event->event); -- 1.7.10.4