… | |
… | |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 | #ifndef EV_STANDALONE |
31 | #ifndef EV_STANDALONE |
32 | # include "config.h" |
32 | # include "config.h" |
|
|
33 | |
|
|
34 | # if HAVE_CLOCK_GETTIME |
|
|
35 | # define EV_USE_MONOTONIC 1 |
|
|
36 | # define EV_USE_REALTIME 1 |
|
|
37 | # endif |
|
|
38 | |
|
|
39 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
40 | # define EV_USE_SELECT 1 |
|
|
41 | # endif |
|
|
42 | |
|
|
43 | # if HAVE_POLL && HAVE_POLL_H |
|
|
44 | # define EV_USE_POLL 1 |
|
|
45 | # endif |
|
|
46 | |
|
|
47 | # if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
|
|
48 | # define EV_USE_EPOLL 1 |
|
|
49 | # endif |
|
|
50 | |
|
|
51 | # if HAVE_KQUEUE && HAVE_WORKING_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H |
|
|
52 | # define EV_USE_KQUEUE 1 |
|
|
53 | # endif |
|
|
54 | |
33 | #endif |
55 | #endif |
34 | |
56 | |
35 | #include <math.h> |
57 | #include <math.h> |
36 | #include <stdlib.h> |
58 | #include <stdlib.h> |
37 | #include <unistd.h> |
59 | #include <unistd.h> |
… | |
… | |
58 | |
80 | |
59 | #ifndef EV_USE_SELECT |
81 | #ifndef EV_USE_SELECT |
60 | # define EV_USE_SELECT 1 |
82 | # define EV_USE_SELECT 1 |
61 | #endif |
83 | #endif |
62 | |
84 | |
63 | #ifndef EV_USEV_POLL |
85 | #ifndef EV_USE_POLL |
64 | # define EV_USEV_POLL 0 /* poll is usually slower than select, and not as well tested */ |
86 | # define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ |
65 | #endif |
87 | #endif |
66 | |
88 | |
67 | #ifndef EV_USE_EPOLL |
89 | #ifndef EV_USE_EPOLL |
68 | # define EV_USE_EPOLL 0 |
90 | # define EV_USE_EPOLL 0 |
69 | #endif |
91 | #endif |
… | |
… | |
349 | /* this should be highly optimised to not do anything but set a flag */ |
371 | /* this should be highly optimised to not do anything but set a flag */ |
350 | for (fd = 0; fd < anfdmax; ++fd) |
372 | for (fd = 0; fd < anfdmax; ++fd) |
351 | if (anfds [fd].events) |
373 | if (anfds [fd].events) |
352 | { |
374 | { |
353 | anfds [fd].events = 0; |
375 | anfds [fd].events = 0; |
354 | fd_change (fd); |
376 | fd_change (EV_A_ fd); |
355 | } |
377 | } |
356 | } |
378 | } |
357 | |
379 | |
358 | /*****************************************************************************/ |
380 | /*****************************************************************************/ |
359 | |
381 | |
… | |
… | |
409 | static ANSIG *signals; |
431 | static ANSIG *signals; |
410 | static int signalmax; |
432 | static int signalmax; |
411 | |
433 | |
412 | static int sigpipe [2]; |
434 | static int sigpipe [2]; |
413 | static sig_atomic_t volatile gotsig; |
435 | static sig_atomic_t volatile gotsig; |
|
|
436 | static struct ev_io sigev; |
414 | |
437 | |
415 | static void |
438 | static void |
416 | signals_init (ANSIG *base, int count) |
439 | signals_init (ANSIG *base, int count) |
417 | { |
440 | { |
418 | while (count--) |
441 | while (count--) |
… | |
… | |
475 | } |
498 | } |
476 | |
499 | |
477 | /*****************************************************************************/ |
500 | /*****************************************************************************/ |
478 | |
501 | |
479 | #ifndef WIN32 |
502 | #ifndef WIN32 |
|
|
503 | |
|
|
504 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
505 | static struct ev_signal childev; |
480 | |
506 | |
481 | #ifndef WCONTINUED |
507 | #ifndef WCONTINUED |
482 | # define WCONTINUED 0 |
508 | # define WCONTINUED 0 |
483 | #endif |
509 | #endif |
484 | |
510 | |
… | |
… | |
520 | # include "ev_kqueue.c" |
546 | # include "ev_kqueue.c" |
521 | #endif |
547 | #endif |
522 | #if EV_USE_EPOLL |
548 | #if EV_USE_EPOLL |
523 | # include "ev_epoll.c" |
549 | # include "ev_epoll.c" |
524 | #endif |
550 | #endif |
525 | #if EV_USEV_POLL |
551 | #if EV_USE_POLL |
526 | # include "ev_poll.c" |
552 | # include "ev_poll.c" |
527 | #endif |
553 | #endif |
528 | #if EV_USE_SELECT |
554 | #if EV_USE_SELECT |
529 | # include "ev_select.c" |
555 | # include "ev_select.c" |
530 | #endif |
556 | #endif |
… | |
… | |
588 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
614 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
589 | #endif |
615 | #endif |
590 | #if EV_USE_EPOLL |
616 | #if EV_USE_EPOLL |
591 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
617 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
592 | #endif |
618 | #endif |
593 | #if EV_USEV_POLL |
619 | #if EV_USE_POLL |
594 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
620 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
595 | #endif |
621 | #endif |
596 | #if EV_USE_SELECT |
622 | #if EV_USE_SELECT |
597 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
623 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
598 | #endif |
624 | #endif |
… | |
… | |
606 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
632 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
607 | #endif |
633 | #endif |
608 | #if EV_USE_EPOLL |
634 | #if EV_USE_EPOLL |
609 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
635 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
610 | #endif |
636 | #endif |
611 | #if EV_USEV_POLL |
637 | #if EV_USE_POLL |
612 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
638 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
613 | #endif |
639 | #endif |
614 | #if EV_USE_SELECT |
640 | #if EV_USE_SELECT |
615 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
641 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
616 | #endif |
642 | #endif |
… | |
… | |
637 | { |
663 | { |
638 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
664 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
639 | |
665 | |
640 | loop_init (EV_A_ methods); |
666 | loop_init (EV_A_ methods); |
641 | |
667 | |
642 | if (ev_methods (EV_A)) |
668 | if (ev_method (EV_A)) |
643 | return loop; |
669 | return loop; |
644 | |
670 | |
645 | return 0; |
671 | return 0; |
646 | } |
672 | } |
647 | |
673 | |
… | |
… | |
724 | |
750 | |
725 | loop_destroy (EV_A); |
751 | loop_destroy (EV_A); |
726 | } |
752 | } |
727 | |
753 | |
728 | void |
754 | void |
729 | ev_default_fork (EV_P) |
755 | ev_default_fork (void) |
730 | { |
756 | { |
|
|
757 | #if EV_MULTIPLICITY |
|
|
758 | struct ev_loop *loop = default_loop; |
|
|
759 | #endif |
|
|
760 | |
731 | loop_fork (EV_A); |
761 | loop_fork (EV_A); |
732 | |
762 | |
733 | ev_io_stop (EV_A_ &sigev); |
763 | ev_io_stop (EV_A_ &sigev); |
734 | close (sigpipe [0]); |
764 | close (sigpipe [0]); |
735 | close (sigpipe [1]); |
765 | close (sigpipe [1]); |