… | |
… | |
44 | int idx; |
44 | int idx; |
45 | |
45 | |
46 | if (oev == nev) |
46 | if (oev == nev) |
47 | return; |
47 | return; |
48 | |
48 | |
49 | array_needsize (pollidxs, pollidxmax, fd + 1, pollidx_init); |
49 | array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init); |
50 | |
50 | |
51 | idx = pollidxs [fd]; |
51 | idx = pollidxs [fd]; |
52 | |
52 | |
53 | if (idx < 0) /* need to allocate a new pollfd */ |
53 | if (idx < 0) /* need to allocate a new pollfd */ |
54 | { |
54 | { |
55 | idx = pollcnt++; |
55 | idx = pollcnt++; |
56 | array_needsize (polls, pollmax, pollcnt, ); |
56 | array_needsize (struct pollfd, polls, pollmax, pollcnt, ); |
57 | polls [idx].fd = fd; |
57 | polls [idx].fd = fd; |
58 | } |
58 | } |
59 | |
59 | |
60 | if (nev) |
60 | if (nev) |
61 | polls [idx].events = |
61 | polls [idx].events = |
… | |
… | |
73 | } |
73 | } |
74 | |
74 | |
75 | static void |
75 | static void |
76 | poll_poll (EV_P_ ev_tstamp timeout) |
76 | poll_poll (EV_P_ ev_tstamp timeout) |
77 | { |
77 | { |
|
|
78 | int i; |
78 | int res = poll (polls, pollcnt, ceil (timeout * 1000.)); |
79 | int res = poll (polls, pollcnt, ceil (timeout * 1000.)); |
79 | |
80 | |
80 | if (res > 0) |
81 | if (res < 0) |
81 | { |
|
|
82 | int i; |
|
|
83 | |
|
|
84 | for (i = 0; i < pollcnt; ++i) |
|
|
85 | fd_event ( |
|
|
86 | EV_A_ |
|
|
87 | polls [i].fd, |
|
|
88 | (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) |
|
|
89 | | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) |
|
|
90 | ); |
|
|
91 | } |
|
|
92 | else if (res < 0) |
|
|
93 | { |
82 | { |
94 | if (errno == EBADF) |
83 | if (errno == EBADF) |
95 | fd_ebadf (EV_A); |
84 | fd_ebadf (EV_A); |
96 | else if (errno == ENOMEM) |
85 | else if (errno == ENOMEM && !syserr_cb) |
97 | fd_enomem (EV_A); |
86 | fd_enomem (EV_A); |
|
|
87 | else if (errno != EINTR) |
|
|
88 | syserr ("(libev) poll"); |
|
|
89 | |
|
|
90 | return; |
98 | } |
91 | } |
|
|
92 | |
|
|
93 | for (i = 0; i < pollcnt; ++i) |
|
|
94 | fd_event ( |
|
|
95 | EV_A_ |
|
|
96 | polls [i].fd, |
|
|
97 | (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) |
|
|
98 | | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) |
|
|
99 | ); |
99 | } |
100 | } |
100 | |
101 | |
101 | static int |
102 | static int |
102 | poll_init (EV_P_ int flags) |
103 | poll_init (EV_P_ int flags) |
103 | { |
104 | { |
… | |
… | |
112 | } |
113 | } |
113 | |
114 | |
114 | static void |
115 | static void |
115 | poll_destroy (EV_P) |
116 | poll_destroy (EV_P) |
116 | { |
117 | { |
117 | free (pollidxs); |
118 | ev_free (pollidxs); |
118 | free (polls); |
119 | ev_free (polls); |
119 | } |
120 | } |
|
|
121 | |