From 5b851cf1bb19aea8448630ac6f179e53d8847e57 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 28 Feb 2007 11:14:56 +0000 Subject: [PATCH] Remove hardcoded limit of 1024 sockets in ZOOM_event_sys_poll(). Note that ZOOM_event_sys_select() still has the limit due to the fixed-size fd_set structure used as a bitmask for the FDs to be selected on. --- src/zoom-socket.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/zoom-socket.c b/src/zoom-socket.c index 8eb9733..fc1df84 100644 --- a/src/zoom-socket.c +++ b/src/zoom-socket.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-socket.c,v 1.2 2007-01-12 21:03:31 adam Exp $ + * $Id: zoom-socket.c,v 1.3 2007-02-28 11:14:56 mike Exp $ */ /** * \file zoom-socket.c @@ -15,6 +15,7 @@ #include #include +#include #if HAVE_SYS_TYPES_H #include @@ -36,6 +37,18 @@ #endif +/* + * Note that ZOOM_event_sys_select() is limited as to how many file + * descriptors it can multiplex due to its use of select() which in + * turn uses the statically defined fd_set type to be a bitmap of the + * file descriptors to check. On Ubuntu 6.06 (and almost certainly on + * Debian, and probably on all Linuxes, and maybe all Unixes) this is + * by default set to 1024 (though it may be possible to override this + * using a #define before including -- I've not tried + * this). 1024 file descriptors is a lot, but not enough in all + * cases, e.g. when running IRSpy on a large target database. So you + * should ensure that YAZ uses ZOOM_event_sys_poll() when possible. + */ ZOOM_API(int) ZOOM_event_sys_select(int no, ZOOM_connection *cs) { @@ -123,8 +136,8 @@ ZOOM_API(int) ZOOM_API(int) ZOOM_event_sys_poll(int no, ZOOM_connection *cs) { - struct pollfd pollfds[1024]; - ZOOM_connection poll_cs[1024]; + struct pollfd *pollfds = xmalloc(no * sizeof *pollfds); + ZOOM_connection *poll_cs = xmalloc(no * sizeof *poll_cs); int i, r; int nfds = 0; int timeout = 30; @@ -159,8 +172,11 @@ ZOOM_API(int) nfds++; } } - if (nfds == 0) + if (nfds == 0) { + xfree(pollfds); + xfree(poll_cs); return 0; + } while ((r = poll(pollfds, nfds, (timeout == -1 ? -1 : timeout * 1000))) < 0 && errno == EINTR) @@ -170,6 +186,8 @@ ZOOM_API(int) if (r < 0) { yaz_log(YLOG_WARN|YLOG_ERRNO, "ZOOM_event_sys_poll"); + xfree(pollfds); + xfree(poll_cs); return r; } for (i = 0; i