… | |
… | |
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 | |
… | |
… | |
475 | |
485 | |
476 | while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) |
486 | while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) |
477 | for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) |
487 | for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) |
478 | if (w->pid == pid || !w->pid) |
488 | if (w->pid == pid || !w->pid) |
479 | { |
489 | { |
|
|
490 | w->rpid = pid; |
480 | w->status = status; |
491 | w->rstatus = status; |
481 | event ((W)w, EV_CHILD); |
492 | event ((W)w, EV_CHILD); |
482 | } |
493 | } |
483 | } |
494 | } |
484 | |
495 | |
485 | /*****************************************************************************/ |
496 | #endif |
486 | |
497 | |
|
|
498 | /*****************************************************************************/ |
|
|
499 | |
|
|
500 | #if EV_USE_KQUEUE |
|
|
501 | # include "ev_kqueue.c" |
|
|
502 | #endif |
487 | #if EV_USE_EPOLL |
503 | #if EV_USE_EPOLL |
488 | # include "ev_epoll.c" |
504 | # include "ev_epoll.c" |
489 | #endif |
505 | #endif |
490 | #if EV_USE_POLL |
506 | #if EV_USE_POLL |
491 | # include "ev_poll.c" |
507 | # include "ev_poll.c" |
… | |
… | |
539 | methods = atoi (getenv ("LIBEV_METHODS")); |
555 | methods = atoi (getenv ("LIBEV_METHODS")); |
540 | else |
556 | else |
541 | methods = EVMETHOD_ANY; |
557 | methods = EVMETHOD_ANY; |
542 | |
558 | |
543 | ev_method = 0; |
559 | ev_method = 0; |
|
|
560 | #if EV_USE_KQUEUE |
|
|
561 | if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods); |
|
|
562 | #endif |
544 | #if EV_USE_EPOLL |
563 | #if EV_USE_EPOLL |
545 | if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); |
564 | if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); |
546 | #endif |
565 | #endif |
547 | #if EV_USE_POLL |
566 | #if EV_USE_POLL |
548 | if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); |
567 | if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); |
… | |
… | |
554 | if (ev_method) |
573 | if (ev_method) |
555 | { |
574 | { |
556 | ev_watcher_init (&sigev, sigcb); |
575 | ev_watcher_init (&sigev, sigcb); |
557 | siginit (); |
576 | siginit (); |
558 | |
577 | |
|
|
578 | #ifndef WIN32 |
559 | ev_signal_init (&childev, childcb, SIGCHLD); |
579 | ev_signal_init (&childev, childcb, SIGCHLD); |
560 | ev_signal_start (&childev); |
580 | ev_signal_start (&childev); |
|
|
581 | #endif |
561 | } |
582 | } |
562 | } |
583 | } |
563 | |
584 | |
564 | return ev_method; |
585 | return ev_method; |
565 | } |
586 | } |
… | |
… | |
858 | } |
879 | } |
859 | |
880 | |
860 | static void |
881 | static void |
861 | ev_start (W w, int active) |
882 | ev_start (W w, int active) |
862 | { |
883 | { |
|
|
884 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
|
|
885 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
886 | |
863 | w->active = active; |
887 | w->active = active; |
864 | } |
888 | } |
865 | |
889 | |
866 | static void |
890 | static void |
867 | ev_stop (W w) |
891 | ev_stop (W w) |