1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements ZOOM C socket interface.
16 #include <yaz/xmalloc.h>
19 #include <sys/types.h>
28 ZOOM_event_sys_yaz_poll(int no, ZOOM_connection *cs)
30 struct yaz_poll_fd *yp = (struct yaz_poll_fd *) xmalloc(sizeof(*yp) * no);
35 for (i = 0; i < no; i++)
37 ZOOM_connection c = cs[i];
42 fd = ZOOM_connection_get_socket(c);
43 mask = ZOOM_connection_get_mask(c);
44 timeout = ZOOM_connection_get_timeout(c);
50 enum yaz_poll_mask input_mask = yaz_poll_none;
52 if (mask & ZOOM_SELECT_READ)
53 yaz_poll_add(input_mask, yaz_poll_read);
54 if (mask & ZOOM_SELECT_WRITE)
55 yaz_poll_add(input_mask, yaz_poll_write);
56 if (mask & ZOOM_SELECT_EXCEPT)
57 yaz_poll_add(input_mask, yaz_poll_except);
59 yp[nfds].input_mask = input_mask;
60 yp[nfds].client_data = c;
69 r = yaz_poll(yp, nfds, timeout, 0);
72 for (i = 0; i < nfds; i++)
74 ZOOM_connection c = (ZOOM_connection) yp[i].client_data;
75 enum yaz_poll_mask output_mask = yp[i].output_mask;
76 if (output_mask & yaz_poll_timeout)
77 ZOOM_connection_fire_event_timeout(c);
81 if (output_mask & yaz_poll_read)
82 mask += ZOOM_SELECT_READ;
83 if (output_mask & yaz_poll_write)
84 mask += ZOOM_SELECT_WRITE;
85 if (output_mask & yaz_poll_except)
86 mask += ZOOM_SELECT_EXCEPT;
87 ZOOM_connection_fire_event_socket(c, mask);
96 ZOOM_event(int no, ZOOM_connection *cs)
100 r = ZOOM_event_nonblock(no, cs);
103 while (ZOOM_event_sys_yaz_poll(no, cs) < 0 && errno == EINTR)
105 return ZOOM_event_nonblock(no, cs);
111 * c-file-style: "Stroustrup"
112 * indent-tabs-mode: nil
114 * vim: shiftwidth=4 tabstop=8 expandtab