… | |
… | |
54 | |
54 | |
55 | #endif |
55 | #endif |
56 | |
56 | |
57 | #include <math.h> |
57 | #include <math.h> |
58 | #include <stdlib.h> |
58 | #include <stdlib.h> |
59 | #include <unistd.h> |
|
|
60 | #include <fcntl.h> |
59 | #include <fcntl.h> |
61 | #include <signal.h> |
|
|
62 | #include <stddef.h> |
60 | #include <stddef.h> |
63 | |
61 | |
64 | #include <stdio.h> |
62 | #include <stdio.h> |
65 | |
63 | |
66 | #include <assert.h> |
64 | #include <assert.h> |
67 | #include <errno.h> |
65 | #include <errno.h> |
68 | #include <sys/types.h> |
66 | #include <sys/types.h> |
|
|
67 | #include <time.h> |
|
|
68 | |
|
|
69 | #include <signal.h> |
|
|
70 | |
69 | #ifndef WIN32 |
71 | #ifndef WIN32 |
|
|
72 | # include <unistd.h> |
|
|
73 | # include <sys/time.h> |
70 | # include <sys/wait.h> |
74 | # include <sys/wait.h> |
71 | #endif |
75 | #endif |
72 | #include <sys/time.h> |
|
|
73 | #include <time.h> |
|
|
74 | |
|
|
75 | /**/ |
76 | /**/ |
76 | |
77 | |
77 | #ifndef EV_USE_MONOTONIC |
78 | #ifndef EV_USE_MONOTONIC |
78 | # define EV_USE_MONOTONIC 1 |
79 | # define EV_USE_MONOTONIC 1 |
79 | #endif |
80 | #endif |
… | |
… | |
94 | # define EV_USE_KQUEUE 0 |
95 | # define EV_USE_KQUEUE 0 |
95 | #endif |
96 | #endif |
96 | |
97 | |
97 | #ifndef EV_USE_WIN32 |
98 | #ifndef EV_USE_WIN32 |
98 | # ifdef WIN32 |
99 | # ifdef WIN32 |
|
|
100 | # define EV_USE_WIN32 0 /* it does not exist, use select */ |
|
|
101 | # undef EV_USE_SELECT |
99 | # define EV_USE_WIN32 1 |
102 | # define EV_USE_SELECT 1 |
100 | # else |
103 | # else |
101 | # define EV_USE_WIN32 0 |
104 | # define EV_USE_WIN32 0 |
102 | # endif |
105 | # endif |
103 | #endif |
106 | #endif |
104 | |
107 | |
… | |
… | |
145 | typedef struct ev_watcher_list *WL; |
148 | typedef struct ev_watcher_list *WL; |
146 | typedef struct ev_watcher_time *WT; |
149 | typedef struct ev_watcher_time *WT; |
147 | |
150 | |
148 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
151 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
149 | |
152 | |
|
|
153 | #include "ev_win32.c" |
|
|
154 | |
150 | /*****************************************************************************/ |
155 | /*****************************************************************************/ |
151 | |
156 | |
|
|
157 | static void (*syserr_cb)(const char *msg); |
|
|
158 | |
|
|
159 | void ev_set_syserr_cb (void (*cb)(const char *msg)) |
|
|
160 | { |
|
|
161 | syserr_cb = cb; |
|
|
162 | } |
|
|
163 | |
|
|
164 | static void |
|
|
165 | syserr (const char *msg) |
|
|
166 | { |
|
|
167 | if (!msg) |
|
|
168 | msg = "(libev) system error"; |
|
|
169 | |
|
|
170 | if (syserr_cb) |
|
|
171 | syserr_cb (msg); |
|
|
172 | else |
|
|
173 | { |
|
|
174 | perror (msg); |
|
|
175 | abort (); |
|
|
176 | } |
|
|
177 | } |
|
|
178 | |
|
|
179 | static void *(*alloc)(void *ptr, long size); |
|
|
180 | |
|
|
181 | void ev_set_allocator (void *(*cb)(void *ptr, long size)) |
|
|
182 | { |
|
|
183 | alloc = cb; |
|
|
184 | } |
|
|
185 | |
|
|
186 | static void * |
|
|
187 | ev_realloc (void *ptr, long size) |
|
|
188 | { |
|
|
189 | ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); |
|
|
190 | |
|
|
191 | if (!ptr && size) |
|
|
192 | { |
|
|
193 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
|
|
194 | abort (); |
|
|
195 | } |
|
|
196 | |
|
|
197 | return ptr; |
|
|
198 | } |
|
|
199 | |
|
|
200 | #define ev_malloc(size) ev_realloc (0, (size)) |
|
|
201 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
|
|
202 | |
|
|
203 | /*****************************************************************************/ |
|
|
204 | |
152 | typedef struct |
205 | typedef struct |
153 | { |
206 | { |
154 | struct ev_watcher_list *head; |
207 | WL head; |
155 | unsigned char events; |
208 | unsigned char events; |
156 | unsigned char reify; |
209 | unsigned char reify; |
157 | } ANFD; |
210 | } ANFD; |
158 | |
211 | |
159 | typedef struct |
212 | typedef struct |
… | |
… | |
162 | int events; |
215 | int events; |
163 | } ANPENDING; |
216 | } ANPENDING; |
164 | |
217 | |
165 | #if EV_MULTIPLICITY |
218 | #if EV_MULTIPLICITY |
166 | |
219 | |
167 | struct ev_loop |
220 | struct ev_loop |
168 | { |
221 | { |
169 | # define VAR(name,decl) decl; |
222 | #define VAR(name,decl) decl; |
170 | # include "ev_vars.h" |
223 | #include "ev_vars.h" |
171 | }; |
|
|
172 | # undef VAR |
224 | #undef VAR |
|
|
225 | }; |
173 | # include "ev_wrap.h" |
226 | #include "ev_wrap.h" |
|
|
227 | |
|
|
228 | struct ev_loop default_loop_struct; |
|
|
229 | static struct ev_loop *default_loop; |
174 | |
230 | |
175 | #else |
231 | #else |
176 | |
232 | |
177 | # define VAR(name,decl) static decl; |
233 | #define VAR(name,decl) static decl; |
178 | # include "ev_vars.h" |
234 | #include "ev_vars.h" |
179 | # undef VAR |
235 | #undef VAR |
|
|
236 | |
|
|
237 | static int default_loop; |
180 | |
238 | |
181 | #endif |
239 | #endif |
182 | |
240 | |
183 | /*****************************************************************************/ |
241 | /*****************************************************************************/ |
184 | |
242 | |
… | |
… | |
215 | ev_now (EV_P) |
273 | ev_now (EV_P) |
216 | { |
274 | { |
217 | return rt_now; |
275 | return rt_now; |
218 | } |
276 | } |
219 | |
277 | |
220 | #define array_roundsize(base,n) ((n) | 4 & ~3) |
278 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
221 | |
279 | |
222 | #define array_needsize(base,cur,cnt,init) \ |
280 | #define array_needsize(type,base,cur,cnt,init) \ |
223 | if (expect_false ((cnt) > cur)) \ |
281 | if (expect_false ((cnt) > cur)) \ |
224 | { \ |
282 | { \ |
225 | int newcnt = cur; \ |
283 | int newcnt = cur; \ |
226 | do \ |
284 | do \ |
227 | { \ |
285 | { \ |
228 | newcnt = array_roundsize (base, newcnt << 1); \ |
286 | newcnt = array_roundsize (type, newcnt << 1); \ |
229 | } \ |
287 | } \ |
230 | while ((cnt) > newcnt); \ |
288 | while ((cnt) > newcnt); \ |
231 | \ |
289 | \ |
232 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
290 | base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\ |
233 | init (base + cur, newcnt - cur); \ |
291 | init (base + cur, newcnt - cur); \ |
234 | cur = newcnt; \ |
292 | cur = newcnt; \ |
235 | } |
293 | } |
|
|
294 | |
|
|
295 | #define array_slim(type,stem) \ |
|
|
296 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
|
|
297 | { \ |
|
|
298 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
|
|
299 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
|
|
300 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
|
|
301 | } |
|
|
302 | |
|
|
303 | /* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ |
|
|
304 | /* bringing us everlasting joy in form of stupid extra macros that are not required in C */ |
|
|
305 | #define array_free_microshit(stem) \ |
|
|
306 | ev_free (stem ## s); stem ## cnt = stem ## max = 0; |
236 | |
307 | |
237 | #define array_free(stem, idx) \ |
308 | #define array_free(stem, idx) \ |
238 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
309 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
239 | |
310 | |
240 | /*****************************************************************************/ |
311 | /*****************************************************************************/ |
241 | |
312 | |
242 | static void |
313 | static void |
243 | anfds_init (ANFD *base, int count) |
314 | anfds_init (ANFD *base, int count) |
… | |
… | |
250 | |
321 | |
251 | ++base; |
322 | ++base; |
252 | } |
323 | } |
253 | } |
324 | } |
254 | |
325 | |
255 | static void |
326 | void |
256 | event (EV_P_ W w, int events) |
327 | ev_feed_event (EV_P_ void *w, int revents) |
257 | { |
328 | { |
|
|
329 | W w_ = (W)w; |
|
|
330 | |
258 | if (w->pending) |
331 | if (w_->pending) |
259 | { |
332 | { |
260 | pendings [ABSPRI (w)][w->pending - 1].events |= events; |
333 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
261 | return; |
334 | return; |
262 | } |
335 | } |
263 | |
336 | |
264 | w->pending = ++pendingcnt [ABSPRI (w)]; |
337 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
265 | array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); |
338 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); |
266 | pendings [ABSPRI (w)][w->pending - 1].w = w; |
339 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
267 | pendings [ABSPRI (w)][w->pending - 1].events = events; |
340 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
268 | } |
341 | } |
269 | |
342 | |
270 | static void |
343 | static void |
271 | queue_events (EV_P_ W *events, int eventcnt, int type) |
344 | queue_events (EV_P_ W *events, int eventcnt, int type) |
272 | { |
345 | { |
273 | int i; |
346 | int i; |
274 | |
347 | |
275 | for (i = 0; i < eventcnt; ++i) |
348 | for (i = 0; i < eventcnt; ++i) |
276 | event (EV_A_ events [i], type); |
349 | ev_feed_event (EV_A_ events [i], type); |
277 | } |
350 | } |
278 | |
351 | |
279 | static void |
352 | inline void |
280 | fd_event (EV_P_ int fd, int events) |
353 | fd_event (EV_P_ int fd, int revents) |
281 | { |
354 | { |
282 | ANFD *anfd = anfds + fd; |
355 | ANFD *anfd = anfds + fd; |
283 | struct ev_io *w; |
356 | struct ev_io *w; |
284 | |
357 | |
285 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
358 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
286 | { |
359 | { |
287 | int ev = w->events & events; |
360 | int ev = w->events & revents; |
288 | |
361 | |
289 | if (ev) |
362 | if (ev) |
290 | event (EV_A_ (W)w, ev); |
363 | ev_feed_event (EV_A_ (W)w, ev); |
291 | } |
364 | } |
|
|
365 | } |
|
|
366 | |
|
|
367 | void |
|
|
368 | ev_feed_fd_event (EV_P_ int fd, int revents) |
|
|
369 | { |
|
|
370 | fd_event (EV_A_ fd, revents); |
292 | } |
371 | } |
293 | |
372 | |
294 | /*****************************************************************************/ |
373 | /*****************************************************************************/ |
295 | |
374 | |
296 | static void |
375 | static void |
… | |
… | |
319 | } |
398 | } |
320 | |
399 | |
321 | static void |
400 | static void |
322 | fd_change (EV_P_ int fd) |
401 | fd_change (EV_P_ int fd) |
323 | { |
402 | { |
324 | if (anfds [fd].reify || fdchangecnt < 0) |
403 | if (anfds [fd].reify) |
325 | return; |
404 | return; |
326 | |
405 | |
327 | anfds [fd].reify = 1; |
406 | anfds [fd].reify = 1; |
328 | |
407 | |
329 | ++fdchangecnt; |
408 | ++fdchangecnt; |
330 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
409 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); |
331 | fdchanges [fdchangecnt - 1] = fd; |
410 | fdchanges [fdchangecnt - 1] = fd; |
332 | } |
411 | } |
333 | |
412 | |
334 | static void |
413 | static void |
335 | fd_kill (EV_P_ int fd) |
414 | fd_kill (EV_P_ int fd) |
… | |
… | |
337 | struct ev_io *w; |
416 | struct ev_io *w; |
338 | |
417 | |
339 | while ((w = (struct ev_io *)anfds [fd].head)) |
418 | while ((w = (struct ev_io *)anfds [fd].head)) |
340 | { |
419 | { |
341 | ev_io_stop (EV_A_ w); |
420 | ev_io_stop (EV_A_ w); |
342 | event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
421 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
343 | } |
422 | } |
|
|
423 | } |
|
|
424 | |
|
|
425 | static int |
|
|
426 | fd_valid (int fd) |
|
|
427 | { |
|
|
428 | #ifdef WIN32 |
|
|
429 | return !!win32_get_osfhandle (fd); |
|
|
430 | #else |
|
|
431 | return fcntl (fd, F_GETFD) != -1; |
|
|
432 | #endif |
344 | } |
433 | } |
345 | |
434 | |
346 | /* called on EBADF to verify fds */ |
435 | /* called on EBADF to verify fds */ |
347 | static void |
436 | static void |
348 | fd_ebadf (EV_P) |
437 | fd_ebadf (EV_P) |
349 | { |
438 | { |
350 | int fd; |
439 | int fd; |
351 | |
440 | |
352 | for (fd = 0; fd < anfdmax; ++fd) |
441 | for (fd = 0; fd < anfdmax; ++fd) |
353 | if (anfds [fd].events) |
442 | if (anfds [fd].events) |
354 | if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) |
443 | if (!fd_valid (fd) == -1 && errno == EBADF) |
355 | fd_kill (EV_A_ fd); |
444 | fd_kill (EV_A_ fd); |
356 | } |
445 | } |
357 | |
446 | |
358 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
447 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
359 | static void |
448 | static void |
… | |
… | |
362 | int fd; |
451 | int fd; |
363 | |
452 | |
364 | for (fd = anfdmax; fd--; ) |
453 | for (fd = anfdmax; fd--; ) |
365 | if (anfds [fd].events) |
454 | if (anfds [fd].events) |
366 | { |
455 | { |
367 | close (fd); |
|
|
368 | fd_kill (EV_A_ fd); |
456 | fd_kill (EV_A_ fd); |
369 | return; |
457 | return; |
370 | } |
458 | } |
371 | } |
459 | } |
372 | |
460 | |
373 | /* susually called after fork if method needs to re-arm all fds from scratch */ |
461 | /* usually called after fork if method needs to re-arm all fds from scratch */ |
374 | static void |
462 | static void |
375 | fd_rearm_all (EV_P) |
463 | fd_rearm_all (EV_P) |
376 | { |
464 | { |
377 | int fd; |
465 | int fd; |
378 | |
466 | |
… | |
… | |
430 | |
518 | |
431 | /*****************************************************************************/ |
519 | /*****************************************************************************/ |
432 | |
520 | |
433 | typedef struct |
521 | typedef struct |
434 | { |
522 | { |
435 | struct ev_watcher_list *head; |
523 | WL head; |
436 | sig_atomic_t volatile gotsig; |
524 | sig_atomic_t volatile gotsig; |
437 | } ANSIG; |
525 | } ANSIG; |
438 | |
526 | |
439 | static ANSIG *signals; |
527 | static ANSIG *signals; |
440 | static int signalmax; |
528 | static int signalmax; |
… | |
… | |
456 | } |
544 | } |
457 | |
545 | |
458 | static void |
546 | static void |
459 | sighandler (int signum) |
547 | sighandler (int signum) |
460 | { |
548 | { |
|
|
549 | #if WIN32 |
|
|
550 | signal (signum, sighandler); |
|
|
551 | #endif |
|
|
552 | |
461 | signals [signum - 1].gotsig = 1; |
553 | signals [signum - 1].gotsig = 1; |
462 | |
554 | |
463 | if (!gotsig) |
555 | if (!gotsig) |
464 | { |
556 | { |
465 | int old_errno = errno; |
557 | int old_errno = errno; |
466 | gotsig = 1; |
558 | gotsig = 1; |
|
|
559 | #ifdef WIN32 |
|
|
560 | send (sigpipe [1], &signum, 1, MSG_DONTWAIT); |
|
|
561 | #else |
467 | write (sigpipe [1], &signum, 1); |
562 | write (sigpipe [1], &signum, 1); |
|
|
563 | #endif |
468 | errno = old_errno; |
564 | errno = old_errno; |
469 | } |
565 | } |
470 | } |
566 | } |
471 | |
567 | |
|
|
568 | void |
|
|
569 | ev_feed_signal_event (EV_P_ int signum) |
|
|
570 | { |
|
|
571 | WL w; |
|
|
572 | |
|
|
573 | #if EV_MULTIPLICITY |
|
|
574 | assert (("feeding signal events is only supported in the default loop", loop == default_loop)); |
|
|
575 | #endif |
|
|
576 | |
|
|
577 | --signum; |
|
|
578 | |
|
|
579 | if (signum < 0 || signum >= signalmax) |
|
|
580 | return; |
|
|
581 | |
|
|
582 | signals [signum].gotsig = 0; |
|
|
583 | |
|
|
584 | for (w = signals [signum].head; w; w = w->next) |
|
|
585 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
|
|
586 | } |
|
|
587 | |
472 | static void |
588 | static void |
473 | sigcb (EV_P_ struct ev_io *iow, int revents) |
589 | sigcb (EV_P_ struct ev_io *iow, int revents) |
474 | { |
590 | { |
475 | struct ev_watcher_list *w; |
|
|
476 | int signum; |
591 | int signum; |
477 | |
592 | |
|
|
593 | #ifdef WIN32 |
|
|
594 | recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); |
|
|
595 | #else |
478 | read (sigpipe [0], &revents, 1); |
596 | read (sigpipe [0], &revents, 1); |
|
|
597 | #endif |
479 | gotsig = 0; |
598 | gotsig = 0; |
480 | |
599 | |
481 | for (signum = signalmax; signum--; ) |
600 | for (signum = signalmax; signum--; ) |
482 | if (signals [signum].gotsig) |
601 | if (signals [signum].gotsig) |
483 | { |
602 | ev_feed_signal_event (EV_A_ signum + 1); |
484 | signals [signum].gotsig = 0; |
|
|
485 | |
|
|
486 | for (w = signals [signum].head; w; w = w->next) |
|
|
487 | event (EV_A_ (W)w, EV_SIGNAL); |
|
|
488 | } |
|
|
489 | } |
603 | } |
490 | |
604 | |
491 | static void |
605 | static void |
492 | siginit (EV_P) |
606 | siginit (EV_P) |
493 | { |
607 | { |
… | |
… | |
505 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
619 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
506 | } |
620 | } |
507 | |
621 | |
508 | /*****************************************************************************/ |
622 | /*****************************************************************************/ |
509 | |
623 | |
|
|
624 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
625 | |
510 | #ifndef WIN32 |
626 | #ifndef WIN32 |
511 | |
627 | |
512 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
513 | static struct ev_signal childev; |
628 | static struct ev_signal childev; |
514 | |
629 | |
515 | #ifndef WCONTINUED |
630 | #ifndef WCONTINUED |
516 | # define WCONTINUED 0 |
631 | # define WCONTINUED 0 |
517 | #endif |
632 | #endif |
… | |
… | |
525 | if (w->pid == pid || !w->pid) |
640 | if (w->pid == pid || !w->pid) |
526 | { |
641 | { |
527 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
642 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
528 | w->rpid = pid; |
643 | w->rpid = pid; |
529 | w->rstatus = status; |
644 | w->rstatus = status; |
530 | event (EV_A_ (W)w, EV_CHILD); |
645 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
531 | } |
646 | } |
532 | } |
647 | } |
533 | |
648 | |
534 | static void |
649 | static void |
535 | childcb (EV_P_ struct ev_signal *sw, int revents) |
650 | childcb (EV_P_ struct ev_signal *sw, int revents) |
… | |
… | |
537 | int pid, status; |
652 | int pid, status; |
538 | |
653 | |
539 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
654 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
540 | { |
655 | { |
541 | /* make sure we are called again until all childs have been reaped */ |
656 | /* make sure we are called again until all childs have been reaped */ |
542 | event (EV_A_ (W)sw, EV_SIGNAL); |
657 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
543 | |
658 | |
544 | child_reap (EV_A_ sw, pid, pid, status); |
659 | child_reap (EV_A_ sw, pid, pid, status); |
545 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
660 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
546 | } |
661 | } |
547 | } |
662 | } |
… | |
… | |
631 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
746 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
632 | #endif |
747 | #endif |
633 | #if EV_USE_SELECT |
748 | #if EV_USE_SELECT |
634 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
749 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
635 | #endif |
750 | #endif |
|
|
751 | |
|
|
752 | ev_watcher_init (&sigev, sigcb); |
|
|
753 | ev_set_priority (&sigev, EV_MAXPRI); |
636 | } |
754 | } |
637 | } |
755 | } |
638 | |
756 | |
639 | void |
757 | void |
640 | loop_destroy (EV_P) |
758 | loop_destroy (EV_P) |
… | |
… | |
658 | #endif |
776 | #endif |
659 | |
777 | |
660 | for (i = NUMPRI; i--; ) |
778 | for (i = NUMPRI; i--; ) |
661 | array_free (pending, [i]); |
779 | array_free (pending, [i]); |
662 | |
780 | |
|
|
781 | /* have to use the microsoft-never-gets-it-right macro */ |
663 | array_free (fdchange, ); |
782 | array_free_microshit (fdchange); |
664 | array_free (timer, ); |
783 | array_free_microshit (timer); |
665 | array_free (periodic, ); |
784 | array_free_microshit (periodic); |
666 | array_free (idle, ); |
785 | array_free_microshit (idle); |
667 | array_free (prepare, ); |
786 | array_free_microshit (prepare); |
668 | array_free (check, ); |
787 | array_free_microshit (check); |
669 | |
788 | |
670 | method = 0; |
789 | method = 0; |
671 | /*TODO*/ |
|
|
672 | } |
790 | } |
673 | |
791 | |
674 | void |
792 | static void |
675 | loop_fork (EV_P) |
793 | loop_fork (EV_P) |
676 | { |
794 | { |
677 | /*TODO*/ |
|
|
678 | #if EV_USE_EPOLL |
795 | #if EV_USE_EPOLL |
679 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
796 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
680 | #endif |
797 | #endif |
681 | #if EV_USE_KQUEUE |
798 | #if EV_USE_KQUEUE |
682 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
799 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
683 | #endif |
800 | #endif |
|
|
801 | |
|
|
802 | if (ev_is_active (&sigev)) |
|
|
803 | { |
|
|
804 | /* default loop */ |
|
|
805 | |
|
|
806 | ev_ref (EV_A); |
|
|
807 | ev_io_stop (EV_A_ &sigev); |
|
|
808 | close (sigpipe [0]); |
|
|
809 | close (sigpipe [1]); |
|
|
810 | |
|
|
811 | while (pipe (sigpipe)) |
|
|
812 | syserr ("(libev) error creating pipe"); |
|
|
813 | |
|
|
814 | siginit (EV_A); |
|
|
815 | } |
|
|
816 | |
|
|
817 | postfork = 0; |
684 | } |
818 | } |
685 | |
819 | |
686 | #if EV_MULTIPLICITY |
820 | #if EV_MULTIPLICITY |
687 | struct ev_loop * |
821 | struct ev_loop * |
688 | ev_loop_new (int methods) |
822 | ev_loop_new (int methods) |
689 | { |
823 | { |
690 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
824 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
|
|
825 | |
|
|
826 | memset (loop, 0, sizeof (struct ev_loop)); |
691 | |
827 | |
692 | loop_init (EV_A_ methods); |
828 | loop_init (EV_A_ methods); |
693 | |
829 | |
694 | if (ev_method (EV_A)) |
830 | if (ev_method (EV_A)) |
695 | return loop; |
831 | return loop; |
… | |
… | |
699 | |
835 | |
700 | void |
836 | void |
701 | ev_loop_destroy (EV_P) |
837 | ev_loop_destroy (EV_P) |
702 | { |
838 | { |
703 | loop_destroy (EV_A); |
839 | loop_destroy (EV_A); |
704 | free (loop); |
840 | ev_free (loop); |
705 | } |
841 | } |
706 | |
842 | |
707 | void |
843 | void |
708 | ev_loop_fork (EV_P) |
844 | ev_loop_fork (EV_P) |
709 | { |
845 | { |
710 | loop_fork (EV_A); |
846 | postfork = 1; |
711 | } |
847 | } |
712 | |
848 | |
713 | #endif |
849 | #endif |
714 | |
850 | |
715 | #if EV_MULTIPLICITY |
851 | #if EV_MULTIPLICITY |
716 | struct ev_loop default_loop_struct; |
|
|
717 | static struct ev_loop *default_loop; |
|
|
718 | |
|
|
719 | struct ev_loop * |
852 | struct ev_loop * |
720 | #else |
853 | #else |
721 | static int default_loop; |
|
|
722 | |
|
|
723 | int |
854 | int |
724 | #endif |
855 | #endif |
725 | ev_default_loop (int methods) |
856 | ev_default_loop (int methods) |
726 | { |
857 | { |
727 | if (sigpipe [0] == sigpipe [1]) |
858 | if (sigpipe [0] == sigpipe [1]) |
… | |
… | |
738 | |
869 | |
739 | loop_init (EV_A_ methods); |
870 | loop_init (EV_A_ methods); |
740 | |
871 | |
741 | if (ev_method (EV_A)) |
872 | if (ev_method (EV_A)) |
742 | { |
873 | { |
743 | ev_watcher_init (&sigev, sigcb); |
|
|
744 | ev_set_priority (&sigev, EV_MAXPRI); |
|
|
745 | siginit (EV_A); |
874 | siginit (EV_A); |
746 | |
875 | |
747 | #ifndef WIN32 |
876 | #ifndef WIN32 |
748 | ev_signal_init (&childev, childcb, SIGCHLD); |
877 | ev_signal_init (&childev, childcb, SIGCHLD); |
749 | ev_set_priority (&childev, EV_MAXPRI); |
878 | ev_set_priority (&childev, EV_MAXPRI); |
… | |
… | |
763 | { |
892 | { |
764 | #if EV_MULTIPLICITY |
893 | #if EV_MULTIPLICITY |
765 | struct ev_loop *loop = default_loop; |
894 | struct ev_loop *loop = default_loop; |
766 | #endif |
895 | #endif |
767 | |
896 | |
|
|
897 | #ifndef WIN32 |
768 | ev_ref (EV_A); /* child watcher */ |
898 | ev_ref (EV_A); /* child watcher */ |
769 | ev_signal_stop (EV_A_ &childev); |
899 | ev_signal_stop (EV_A_ &childev); |
|
|
900 | #endif |
770 | |
901 | |
771 | ev_ref (EV_A); /* signal watcher */ |
902 | ev_ref (EV_A); /* signal watcher */ |
772 | ev_io_stop (EV_A_ &sigev); |
903 | ev_io_stop (EV_A_ &sigev); |
773 | |
904 | |
774 | close (sigpipe [0]); sigpipe [0] = 0; |
905 | close (sigpipe [0]); sigpipe [0] = 0; |
… | |
… | |
782 | { |
913 | { |
783 | #if EV_MULTIPLICITY |
914 | #if EV_MULTIPLICITY |
784 | struct ev_loop *loop = default_loop; |
915 | struct ev_loop *loop = default_loop; |
785 | #endif |
916 | #endif |
786 | |
917 | |
787 | loop_fork (EV_A); |
918 | if (method) |
788 | |
919 | postfork = 1; |
789 | ev_io_stop (EV_A_ &sigev); |
|
|
790 | close (sigpipe [0]); |
|
|
791 | close (sigpipe [1]); |
|
|
792 | pipe (sigpipe); |
|
|
793 | |
|
|
794 | ev_ref (EV_A); /* signal watcher */ |
|
|
795 | siginit (EV_A); |
|
|
796 | } |
920 | } |
797 | |
921 | |
798 | /*****************************************************************************/ |
922 | /*****************************************************************************/ |
|
|
923 | |
|
|
924 | static int |
|
|
925 | any_pending (EV_P) |
|
|
926 | { |
|
|
927 | int pri; |
|
|
928 | |
|
|
929 | for (pri = NUMPRI; pri--; ) |
|
|
930 | if (pendingcnt [pri]) |
|
|
931 | return 1; |
|
|
932 | |
|
|
933 | return 0; |
|
|
934 | } |
799 | |
935 | |
800 | static void |
936 | static void |
801 | call_pending (EV_P) |
937 | call_pending (EV_P) |
802 | { |
938 | { |
803 | int pri; |
939 | int pri; |
… | |
… | |
832 | downheap ((WT *)timers, timercnt, 0); |
968 | downheap ((WT *)timers, timercnt, 0); |
833 | } |
969 | } |
834 | else |
970 | else |
835 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
971 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
836 | |
972 | |
837 | event (EV_A_ (W)w, EV_TIMEOUT); |
973 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
838 | } |
974 | } |
839 | } |
975 | } |
840 | |
976 | |
841 | static void |
977 | static void |
842 | periodics_reify (EV_P) |
978 | periodics_reify (EV_P) |
… | |
… | |
846 | struct ev_periodic *w = periodics [0]; |
982 | struct ev_periodic *w = periodics [0]; |
847 | |
983 | |
848 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
984 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
849 | |
985 | |
850 | /* first reschedule or stop timer */ |
986 | /* first reschedule or stop timer */ |
|
|
987 | if (w->reschedule_cb) |
|
|
988 | { |
|
|
989 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001); |
|
|
990 | |
|
|
991 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now)); |
|
|
992 | downheap ((WT *)periodics, periodiccnt, 0); |
|
|
993 | } |
851 | if (w->interval) |
994 | else if (w->interval) |
852 | { |
995 | { |
853 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
996 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
854 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
997 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
855 | downheap ((WT *)periodics, periodiccnt, 0); |
998 | downheap ((WT *)periodics, periodiccnt, 0); |
856 | } |
999 | } |
857 | else |
1000 | else |
858 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1001 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
859 | |
1002 | |
860 | event (EV_A_ (W)w, EV_PERIODIC); |
1003 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
861 | } |
1004 | } |
862 | } |
1005 | } |
863 | |
1006 | |
864 | static void |
1007 | static void |
865 | periodics_reschedule (EV_P) |
1008 | periodics_reschedule (EV_P) |
… | |
… | |
869 | /* adjust periodics after time jump */ |
1012 | /* adjust periodics after time jump */ |
870 | for (i = 0; i < periodiccnt; ++i) |
1013 | for (i = 0; i < periodiccnt; ++i) |
871 | { |
1014 | { |
872 | struct ev_periodic *w = periodics [i]; |
1015 | struct ev_periodic *w = periodics [i]; |
873 | |
1016 | |
|
|
1017 | if (w->reschedule_cb) |
|
|
1018 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
874 | if (w->interval) |
1019 | else if (w->interval) |
875 | { |
|
|
876 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1020 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
877 | |
|
|
878 | if (fabs (diff) >= 1e-4) |
|
|
879 | { |
|
|
880 | ev_periodic_stop (EV_A_ w); |
|
|
881 | ev_periodic_start (EV_A_ w); |
|
|
882 | |
|
|
883 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
|
|
884 | } |
|
|
885 | } |
|
|
886 | } |
1021 | } |
|
|
1022 | |
|
|
1023 | /* now rebuild the heap */ |
|
|
1024 | for (i = periodiccnt >> 1; i--; ) |
|
|
1025 | downheap ((WT *)periodics, periodiccnt, i); |
887 | } |
1026 | } |
888 | |
1027 | |
889 | inline int |
1028 | inline int |
890 | time_update_monotonic (EV_P) |
1029 | time_update_monotonic (EV_P) |
891 | { |
1030 | { |
… | |
… | |
978 | { |
1117 | { |
979 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1118 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
980 | call_pending (EV_A); |
1119 | call_pending (EV_A); |
981 | } |
1120 | } |
982 | |
1121 | |
|
|
1122 | /* we might have forked, so reify kernel state if necessary */ |
|
|
1123 | if (expect_false (postfork)) |
|
|
1124 | loop_fork (EV_A); |
|
|
1125 | |
983 | /* update fd-related kernel structures */ |
1126 | /* update fd-related kernel structures */ |
984 | fd_reify (EV_A); |
1127 | fd_reify (EV_A); |
985 | |
1128 | |
986 | /* calculate blocking time */ |
1129 | /* calculate blocking time */ |
987 | |
1130 | |
988 | /* we only need this for !monotonic clockor timers, but as we basically |
1131 | /* we only need this for !monotonic clock or timers, but as we basically |
989 | always have timers, we just calculate it always */ |
1132 | always have timers, we just calculate it always */ |
990 | #if EV_USE_MONOTONIC |
1133 | #if EV_USE_MONOTONIC |
991 | if (expect_true (have_monotonic)) |
1134 | if (expect_true (have_monotonic)) |
992 | time_update_monotonic (EV_A); |
1135 | time_update_monotonic (EV_A); |
993 | else |
1136 | else |
… | |
… | |
1026 | /* queue pending timers and reschedule them */ |
1169 | /* queue pending timers and reschedule them */ |
1027 | timers_reify (EV_A); /* relative timers called last */ |
1170 | timers_reify (EV_A); /* relative timers called last */ |
1028 | periodics_reify (EV_A); /* absolute timers called first */ |
1171 | periodics_reify (EV_A); /* absolute timers called first */ |
1029 | |
1172 | |
1030 | /* queue idle watchers unless io or timers are pending */ |
1173 | /* queue idle watchers unless io or timers are pending */ |
1031 | if (!pendingcnt) |
1174 | if (idlecnt && !any_pending (EV_A)) |
1032 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1175 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1033 | |
1176 | |
1034 | /* queue check watchers, to be executed first */ |
1177 | /* queue check watchers, to be executed first */ |
1035 | if (checkcnt) |
1178 | if (checkcnt) |
1036 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1179 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
… | |
… | |
1111 | return; |
1254 | return; |
1112 | |
1255 | |
1113 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1256 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1114 | |
1257 | |
1115 | ev_start (EV_A_ (W)w, 1); |
1258 | ev_start (EV_A_ (W)w, 1); |
1116 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
1259 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1117 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1260 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1118 | |
1261 | |
1119 | fd_change (EV_A_ fd); |
1262 | fd_change (EV_A_ fd); |
1120 | } |
1263 | } |
1121 | |
1264 | |
… | |
… | |
1141 | ((WT)w)->at += mn_now; |
1284 | ((WT)w)->at += mn_now; |
1142 | |
1285 | |
1143 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1286 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1144 | |
1287 | |
1145 | ev_start (EV_A_ (W)w, ++timercnt); |
1288 | ev_start (EV_A_ (W)w, ++timercnt); |
1146 | array_needsize (timers, timermax, timercnt, ); |
1289 | array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); |
1147 | timers [timercnt - 1] = w; |
1290 | timers [timercnt - 1] = w; |
1148 | upheap ((WT *)timers, timercnt - 1); |
1291 | upheap ((WT *)timers, timercnt - 1); |
1149 | |
1292 | |
1150 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1293 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1151 | } |
1294 | } |
… | |
… | |
1191 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1334 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1192 | { |
1335 | { |
1193 | if (ev_is_active (w)) |
1336 | if (ev_is_active (w)) |
1194 | return; |
1337 | return; |
1195 | |
1338 | |
|
|
1339 | if (w->reschedule_cb) |
|
|
1340 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
|
|
1341 | else if (w->interval) |
|
|
1342 | { |
1196 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1343 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1197 | |
|
|
1198 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1344 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1199 | if (w->interval) |
|
|
1200 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1345 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
|
|
1346 | } |
1201 | |
1347 | |
1202 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1348 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1203 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1349 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1204 | periodics [periodiccnt - 1] = w; |
1350 | periodics [periodiccnt - 1] = w; |
1205 | upheap ((WT *)periodics, periodiccnt - 1); |
1351 | upheap ((WT *)periodics, periodiccnt - 1); |
1206 | |
1352 | |
1207 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1353 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1208 | } |
1354 | } |
… | |
… | |
1224 | |
1370 | |
1225 | ev_stop (EV_A_ (W)w); |
1371 | ev_stop (EV_A_ (W)w); |
1226 | } |
1372 | } |
1227 | |
1373 | |
1228 | void |
1374 | void |
|
|
1375 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
|
|
1376 | { |
|
|
1377 | ev_periodic_stop (EV_A_ w); |
|
|
1378 | ev_periodic_start (EV_A_ w); |
|
|
1379 | } |
|
|
1380 | |
|
|
1381 | void |
1229 | ev_idle_start (EV_P_ struct ev_idle *w) |
1382 | ev_idle_start (EV_P_ struct ev_idle *w) |
1230 | { |
1383 | { |
1231 | if (ev_is_active (w)) |
1384 | if (ev_is_active (w)) |
1232 | return; |
1385 | return; |
1233 | |
1386 | |
1234 | ev_start (EV_A_ (W)w, ++idlecnt); |
1387 | ev_start (EV_A_ (W)w, ++idlecnt); |
1235 | array_needsize (idles, idlemax, idlecnt, ); |
1388 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); |
1236 | idles [idlecnt - 1] = w; |
1389 | idles [idlecnt - 1] = w; |
1237 | } |
1390 | } |
1238 | |
1391 | |
1239 | void |
1392 | void |
1240 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1393 | ev_idle_stop (EV_P_ struct ev_idle *w) |
… | |
… | |
1252 | { |
1405 | { |
1253 | if (ev_is_active (w)) |
1406 | if (ev_is_active (w)) |
1254 | return; |
1407 | return; |
1255 | |
1408 | |
1256 | ev_start (EV_A_ (W)w, ++preparecnt); |
1409 | ev_start (EV_A_ (W)w, ++preparecnt); |
1257 | array_needsize (prepares, preparemax, preparecnt, ); |
1410 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); |
1258 | prepares [preparecnt - 1] = w; |
1411 | prepares [preparecnt - 1] = w; |
1259 | } |
1412 | } |
1260 | |
1413 | |
1261 | void |
1414 | void |
1262 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1415 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
… | |
… | |
1274 | { |
1427 | { |
1275 | if (ev_is_active (w)) |
1428 | if (ev_is_active (w)) |
1276 | return; |
1429 | return; |
1277 | |
1430 | |
1278 | ev_start (EV_A_ (W)w, ++checkcnt); |
1431 | ev_start (EV_A_ (W)w, ++checkcnt); |
1279 | array_needsize (checks, checkmax, checkcnt, ); |
1432 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); |
1280 | checks [checkcnt - 1] = w; |
1433 | checks [checkcnt - 1] = w; |
1281 | } |
1434 | } |
1282 | |
1435 | |
1283 | void |
1436 | void |
1284 | ev_check_stop (EV_P_ struct ev_check *w) |
1437 | ev_check_stop (EV_P_ struct ev_check *w) |
… | |
… | |
1305 | return; |
1458 | return; |
1306 | |
1459 | |
1307 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1460 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1308 | |
1461 | |
1309 | ev_start (EV_A_ (W)w, 1); |
1462 | ev_start (EV_A_ (W)w, 1); |
1310 | array_needsize (signals, signalmax, w->signum, signals_init); |
1463 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
1311 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1464 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1312 | |
1465 | |
1313 | if (!((WL)w)->next) |
1466 | if (!((WL)w)->next) |
1314 | { |
1467 | { |
|
|
1468 | #if WIN32 |
|
|
1469 | signal (w->signum, sighandler); |
|
|
1470 | #else |
1315 | struct sigaction sa; |
1471 | struct sigaction sa; |
1316 | sa.sa_handler = sighandler; |
1472 | sa.sa_handler = sighandler; |
1317 | sigfillset (&sa.sa_mask); |
1473 | sigfillset (&sa.sa_mask); |
1318 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1474 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1319 | sigaction (w->signum, &sa, 0); |
1475 | sigaction (w->signum, &sa, 0); |
|
|
1476 | #endif |
1320 | } |
1477 | } |
1321 | } |
1478 | } |
1322 | |
1479 | |
1323 | void |
1480 | void |
1324 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1481 | ev_signal_stop (EV_P_ struct ev_signal *w) |
… | |
… | |
1374 | void (*cb)(int revents, void *arg) = once->cb; |
1531 | void (*cb)(int revents, void *arg) = once->cb; |
1375 | void *arg = once->arg; |
1532 | void *arg = once->arg; |
1376 | |
1533 | |
1377 | ev_io_stop (EV_A_ &once->io); |
1534 | ev_io_stop (EV_A_ &once->io); |
1378 | ev_timer_stop (EV_A_ &once->to); |
1535 | ev_timer_stop (EV_A_ &once->to); |
1379 | free (once); |
1536 | ev_free (once); |
1380 | |
1537 | |
1381 | cb (revents, arg); |
1538 | cb (revents, arg); |
1382 | } |
1539 | } |
1383 | |
1540 | |
1384 | static void |
1541 | static void |
… | |
… | |
1394 | } |
1551 | } |
1395 | |
1552 | |
1396 | void |
1553 | void |
1397 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1554 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1398 | { |
1555 | { |
1399 | struct ev_once *once = malloc (sizeof (struct ev_once)); |
1556 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
1400 | |
1557 | |
1401 | if (!once) |
1558 | if (!once) |
1402 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1559 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1403 | else |
1560 | else |
1404 | { |
1561 | { |