… | |
… | |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
30 | */ |
31 | |
31 | |
32 | #include <stddef.h> |
32 | #include <stddef.h> |
33 | #include <stdlib.h> |
33 | #include <stdlib.h> |
34 | #include <sys/time.h> |
|
|
35 | #include <assert.h> |
34 | #include <assert.h> |
|
|
35 | |
|
|
36 | #ifndef WIN32 |
|
|
37 | # include <sys/time.h> |
|
|
38 | #endif |
36 | |
39 | |
37 | #include "ev.h" |
40 | #include "ev.h" |
38 | #include "event.h" |
41 | #include "event.h" |
39 | |
42 | |
40 | #if EV_MULTIPLICITY |
43 | #if EV_MULTIPLICITY |
… | |
… | |
139 | } |
142 | } |
140 | |
143 | |
141 | static void |
144 | static void |
142 | x_cb_sig (EV_P_ struct ev_signal *w, int revents) |
145 | x_cb_sig (EV_P_ struct ev_signal *w, int revents) |
143 | { |
146 | { |
144 | x_cb ((struct event *)(((char *)w) - offsetof (struct event, iosig.sig)), revents); |
147 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.sig)); |
|
|
148 | |
|
|
149 | if (revents & EV_ERROR) |
|
|
150 | event_del (ev); |
|
|
151 | |
|
|
152 | x_cb (ev, revents); |
145 | } |
153 | } |
146 | |
154 | |
147 | static void |
155 | static void |
148 | x_cb_io (EV_P_ struct ev_io *w, int revents) |
156 | x_cb_io (EV_P_ struct ev_io *w, int revents) |
149 | { |
157 | { |
150 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); |
158 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); |
151 | |
159 | |
|
|
160 | if (revents & EV_ERROR) |
|
|
161 | event_del (ev); |
152 | if (!(ev->ev_events & EV_PERSIST) && ev_is_active (w)) |
162 | else if (!(ev->ev_events & EV_PERSIST) && ev_is_active (w)) |
153 | ev_io_stop (EV_A_ w); |
163 | ev_io_stop (EV_A_ w); |
154 | |
164 | |
155 | x_cb (ev, revents); |
165 | x_cb (ev, revents); |
156 | } |
166 | } |
157 | |
167 | |
… | |
… | |
238 | return 0; |
248 | return 0; |
239 | } |
249 | } |
240 | |
250 | |
241 | int event_pending (struct event *ev, short events, struct timeval *tv) |
251 | int event_pending (struct event *ev, short events, struct timeval *tv) |
242 | { |
252 | { |
|
|
253 | short revents = 0; |
243 | dLOOPev; |
254 | dLOOPev; |
244 | |
255 | |
245 | short revents = 0; |
|
|
246 | |
256 | |
247 | if (ev->ev_events & EV_SIGNAL) |
257 | if (ev->ev_events & EV_SIGNAL) |
248 | { |
258 | { |
249 | /* sig */ |
259 | /* sig */ |
250 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) |
260 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) |
… | |
… | |
309 | ev_unloop (EV_A_ EVUNLOOP_ONCE); |
319 | ev_unloop (EV_A_ EVUNLOOP_ONCE); |
310 | } |
320 | } |
311 | |
321 | |
312 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
322 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
313 | { |
323 | { |
314 | dLOOPbase; |
|
|
315 | ev_tstamp after = tv_get (tv); |
324 | ev_tstamp after = tv_get (tv); |
|
|
325 | dLOOPbase; |
316 | |
326 | |
317 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
327 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
318 | |
328 | |
319 | return -1; |
329 | return -1; |
320 | } |
330 | } |
… | |
… | |
327 | }; |
337 | }; |
328 | |
338 | |
329 | static void |
339 | static void |
330 | x_once_cb (int revents, void *arg) |
340 | x_once_cb (int revents, void *arg) |
331 | { |
341 | { |
332 | struct x_once *once = arg; |
342 | struct x_once *once = (struct x_once *)arg; |
333 | |
343 | |
334 | once->cb (once->fd, revents, once->arg); |
344 | once->cb (once->fd, revents, once->arg); |
335 | free (once); |
345 | free (once); |
336 | } |
346 | } |
337 | |
347 | |
338 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
348 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
339 | { |
349 | { |
340 | dLOOPbase; |
|
|
341 | struct x_once *once = malloc (sizeof (struct x_once)); |
350 | struct x_once *once = (struct x_once *)malloc (sizeof (struct x_once)); |
|
|
351 | dLOOPbase; |
342 | |
352 | |
343 | if (!once) |
353 | if (!once) |
344 | return -1; |
354 | return -1; |
345 | |
355 | |
346 | once->fd = fd; |
356 | once->fd = fd; |