1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements ZOOM C socket interface.
19 #include <yaz/xmalloc.h>
22 #include <sys/types.h>
31 ZOOM_event_sys_yaz_poll(int no, ZOOM_connection *cs)
33 struct yaz_poll_fd *yp = (struct yaz_poll_fd *) xmalloc(sizeof(*yp) * no);
38 for (i = 0; i < no; i++)
40 ZOOM_connection c = cs[i];
45 fd = ZOOM_connection_get_socket(c);
46 mask = ZOOM_connection_get_mask(c);
47 timeout = ZOOM_connection_get_timeout(c);
53 enum yaz_poll_mask input_mask = yaz_poll_none;
55 if (mask & ZOOM_SELECT_READ)
56 yaz_poll_add(input_mask, yaz_poll_read);
57 if (mask & ZOOM_SELECT_WRITE)
58 yaz_poll_add(input_mask, yaz_poll_write);
59 if (mask & ZOOM_SELECT_EXCEPT)
60 yaz_poll_add(input_mask, yaz_poll_except);
62 yp[nfds].input_mask = input_mask;
63 yp[nfds].client_data = c;
72 r = yaz_poll(yp, nfds, timeout, 0);
75 for (i = 0; i < nfds; i++)
77 ZOOM_connection c = (ZOOM_connection) yp[i].client_data;
78 enum yaz_poll_mask output_mask = yp[i].output_mask;
79 if (output_mask & yaz_poll_timeout)
80 ZOOM_connection_fire_event_timeout(c);
84 if (output_mask & yaz_poll_read)
85 mask += ZOOM_SELECT_READ;
86 if (output_mask & yaz_poll_write)
87 mask += ZOOM_SELECT_WRITE;
88 if (output_mask & yaz_poll_except)
89 mask += ZOOM_SELECT_EXCEPT;
90 ZOOM_connection_fire_event_socket(c, mask);
99 ZOOM_event(int no, ZOOM_connection *cs)
103 r = ZOOM_event_nonblock(no, cs);
106 while (ZOOM_event_sys_yaz_poll(no, cs) < 0 && errno == EINTR)
108 return ZOOM_event_nonblock(no, cs);
114 * c-file-style: "Stroustrup"
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab