X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-socket.c;h=cb5579af431e68eff85e500e222fcfe79b1e030a;hp=8eb9733b490eaed512f8395bb3639cfa79d2f10d;hb=0e7fdbc857d4905e67a7bdf8fe5b6c773ee47a7b;hpb=0982c13b874d79d950800b62ea22d91d943f3036 diff --git a/src/zoom-socket.c b/src/zoom-socket.c index 8eb9733..cb5579a 100644 --- a/src/zoom-socket.c +++ b/src/zoom-socket.c @@ -1,13 +1,14 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. - * - * $Id: zoom-socket.c,v 1.2 2007-01-12 21:03:31 adam Exp $ */ /** * \file zoom-socket.c * \brief Implements ZOOM C socket interface. */ +#if HAVE_CONFIG_H +#include +#endif #include #include @@ -15,6 +16,7 @@ #include #include +#include #if HAVE_SYS_TYPES_H #include @@ -22,114 +24,18 @@ #if HAVE_SYS_TIME_H #include #endif -#if HAVE_SYS_POLL_H -#include -#endif -#if HAVE_SYS_SELECT_H -#include -#endif -#ifdef WIN32 -#if FD_SETSIZE < 512 -#define FD_SETSIZE 512 -#endif -#include -#endif - - -ZOOM_API(int) - ZOOM_event_sys_select(int no, ZOOM_connection *cs) -{ - struct timeval tv; - fd_set input, output, except; - int i, r; - int max_fd = 0; - int timeout = 30; - int nfds = 0; - - FD_ZERO(&input); - FD_ZERO(&output); - FD_ZERO(&except); - - for (i = 0; i -#if HAVE_SYS_POLL_H ZOOM_API(int) - ZOOM_event_sys_poll(int no, ZOOM_connection *cs) + ZOOM_event_sys_yaz_poll(int no, ZOOM_connection *cs) { - struct pollfd pollfds[1024]; - ZOOM_connection poll_cs[1024]; + struct yaz_poll_fd *yp = (struct yaz_poll_fd *) xmalloc(sizeof(*yp) * no); int i, r; int nfds = 0; int timeout = 30; - for (i = 0; i= 0) { - ZOOM_connection c = poll_cs[i]; - if (r) + for (i = 0; i < nfds; i++) { - int mask = 0; - if (pollfds[i].revents & POLLIN) - mask += ZOOM_SELECT_READ; - if (pollfds[i].revents & POLLOUT) - mask += ZOOM_SELECT_WRITE; - if (pollfds[i].revents & POLLERR) - mask += ZOOM_SELECT_EXCEPT; - ZOOM_connection_fire_event_socket(c, mask); + ZOOM_connection c = (ZOOM_connection) yp[i].client_data; + enum yaz_poll_mask output_mask = yp[i].output_mask; + if (output_mask & yaz_poll_timeout) + ZOOM_connection_fire_event_timeout(c); + else + { + int mask = 0; + if (output_mask & yaz_poll_read) + mask += ZOOM_SELECT_READ; + if (output_mask & yaz_poll_write) + mask += ZOOM_SELECT_WRITE; + if (output_mask & yaz_poll_except) + mask += ZOOM_SELECT_EXCEPT; + ZOOM_connection_fire_event_socket(c, mask); + } } - else - ZOOM_connection_fire_event_timeout(c); } + xfree(yp); return r; } -#endif ZOOM_API(int) ZOOM_event(int no, ZOOM_connection *cs) @@ -201,17 +103,15 @@ ZOOM_API(int) r = ZOOM_event_nonblock(no, cs); if (r) return r; -#if HAVE_SYS_POLL_H - ZOOM_event_sys_poll(no, cs); -#else - ZOOM_event_sys_select(no, cs); -#endif + while (ZOOM_event_sys_yaz_poll(no, cs) < 0 && errno == EINTR) + ; return ZOOM_event_nonblock(no, cs); } /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab