… | |
… | |
42 | #include <stdio.h> |
42 | #include <stdio.h> |
43 | |
43 | |
44 | #include <assert.h> |
44 | #include <assert.h> |
45 | #include <errno.h> |
45 | #include <errno.h> |
46 | #include <sys/types.h> |
46 | #include <sys/types.h> |
|
|
47 | #ifndef WIN32 |
47 | #include <sys/wait.h> |
48 | # include <sys/wait.h> |
|
|
49 | #endif |
48 | #include <sys/time.h> |
50 | #include <sys/time.h> |
49 | #include <time.h> |
51 | #include <time.h> |
50 | |
52 | |
51 | /**/ |
53 | /**/ |
52 | |
54 | |
… | |
… | |
62 | # define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ |
64 | # define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ |
63 | #endif |
65 | #endif |
64 | |
66 | |
65 | #ifndef EV_USE_EPOLL |
67 | #ifndef EV_USE_EPOLL |
66 | # define EV_USE_EPOLL 0 |
68 | # define EV_USE_EPOLL 0 |
|
|
69 | #endif |
|
|
70 | |
|
|
71 | #ifndef EV_USE_KQUEUE |
|
|
72 | # define EV_USE_KQUEUE 0 |
67 | #endif |
73 | #endif |
68 | |
74 | |
69 | #ifndef EV_USE_REALTIME |
75 | #ifndef EV_USE_REALTIME |
70 | # define EV_USE_REALTIME 1 |
76 | # define EV_USE_REALTIME 1 |
71 | #endif |
77 | #endif |
… | |
… | |
434 | } |
440 | } |
435 | |
441 | |
436 | static void |
442 | static void |
437 | siginit (void) |
443 | siginit (void) |
438 | { |
444 | { |
|
|
445 | #ifndef WIN32 |
439 | fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); |
446 | fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); |
440 | fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); |
447 | fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); |
441 | |
448 | |
442 | /* rather than sort out wether we really need nb, set it */ |
449 | /* rather than sort out wether we really need nb, set it */ |
443 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
450 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
444 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
451 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
|
|
452 | #endif |
445 | |
453 | |
446 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
454 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
447 | ev_io_start (&sigev); |
455 | ev_io_start (&sigev); |
448 | } |
456 | } |
449 | |
457 | |
… | |
… | |
460 | |
468 | |
461 | /*****************************************************************************/ |
469 | /*****************************************************************************/ |
462 | |
470 | |
463 | static struct ev_child *childs [PID_HASHSIZE]; |
471 | static struct ev_child *childs [PID_HASHSIZE]; |
464 | static struct ev_signal childev; |
472 | static struct ev_signal childev; |
|
|
473 | |
|
|
474 | #ifndef WIN32 |
465 | |
475 | |
466 | #ifndef WCONTINUED |
476 | #ifndef WCONTINUED |
467 | # define WCONTINUED 0 |
477 | # define WCONTINUED 0 |
468 | #endif |
478 | #endif |
469 | |
479 | |
… | |
… | |
480 | w->status = status; |
490 | w->status = status; |
481 | event ((W)w, EV_CHILD); |
491 | event ((W)w, EV_CHILD); |
482 | } |
492 | } |
483 | } |
493 | } |
484 | |
494 | |
485 | /*****************************************************************************/ |
495 | #endif |
486 | |
496 | |
|
|
497 | /*****************************************************************************/ |
|
|
498 | |
|
|
499 | #if EV_USE_KQUEUE |
|
|
500 | # include "ev_kqueue.c" |
|
|
501 | #endif |
487 | #if EV_USE_EPOLL |
502 | #if EV_USE_EPOLL |
488 | # include "ev_epoll.c" |
503 | # include "ev_epoll.c" |
489 | #endif |
504 | #endif |
490 | #if EV_USE_POLL |
505 | #if EV_USE_POLL |
491 | # include "ev_poll.c" |
506 | # include "ev_poll.c" |
… | |
… | |
539 | methods = atoi (getenv ("LIBEV_METHODS")); |
554 | methods = atoi (getenv ("LIBEV_METHODS")); |
540 | else |
555 | else |
541 | methods = EVMETHOD_ANY; |
556 | methods = EVMETHOD_ANY; |
542 | |
557 | |
543 | ev_method = 0; |
558 | ev_method = 0; |
|
|
559 | #if EV_USE_KQUEUE |
|
|
560 | if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods); |
|
|
561 | #endif |
544 | #if EV_USE_EPOLL |
562 | #if EV_USE_EPOLL |
545 | if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); |
563 | if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); |
546 | #endif |
564 | #endif |
547 | #if EV_USE_POLL |
565 | #if EV_USE_POLL |
548 | if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); |
566 | if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); |
… | |
… | |
554 | if (ev_method) |
572 | if (ev_method) |
555 | { |
573 | { |
556 | ev_watcher_init (&sigev, sigcb); |
574 | ev_watcher_init (&sigev, sigcb); |
557 | siginit (); |
575 | siginit (); |
558 | |
576 | |
|
|
577 | #ifndef WIN32 |
559 | ev_signal_init (&childev, childcb, SIGCHLD); |
578 | ev_signal_init (&childev, childcb, SIGCHLD); |
560 | ev_signal_start (&childev); |
579 | ev_signal_start (&childev); |
|
|
580 | #endif |
561 | } |
581 | } |
562 | } |
582 | } |
563 | |
583 | |
564 | return ev_method; |
584 | return ev_method; |
565 | } |
585 | } |
… | |
… | |
858 | } |
878 | } |
859 | |
879 | |
860 | static void |
880 | static void |
861 | ev_start (W w, int active) |
881 | ev_start (W w, int active) |
862 | { |
882 | { |
|
|
883 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
|
|
884 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
885 | |
863 | w->active = active; |
886 | w->active = active; |
864 | } |
887 | } |
865 | |
888 | |
866 | static void |
889 | static void |
867 | ev_stop (W w) |
890 | ev_stop (W w) |