… | |
… | |
154 | #ifndef _WIN32 |
154 | #ifndef _WIN32 |
155 | # include <sys/time.h> |
155 | # include <sys/time.h> |
156 | # include <sys/wait.h> |
156 | # include <sys/wait.h> |
157 | # include <unistd.h> |
157 | # include <unistd.h> |
158 | #else |
158 | #else |
|
|
159 | # include <io.h> |
159 | # define WIN32_LEAN_AND_MEAN |
160 | # define WIN32_LEAN_AND_MEAN |
160 | # include <windows.h> |
161 | # include <windows.h> |
161 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # endif |
164 | # endif |
164 | #endif |
165 | #endif |
165 | |
166 | |
166 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
167 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
167 | |
168 | |
168 | #ifndef EV_USE_MONOTONIC |
169 | #ifndef EV_USE_MONOTONIC |
|
|
170 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
|
|
171 | # define EV_USE_MONOTONIC 1 |
|
|
172 | # else |
169 | # define EV_USE_MONOTONIC 0 |
173 | # define EV_USE_MONOTONIC 0 |
|
|
174 | # endif |
170 | #endif |
175 | #endif |
171 | |
176 | |
172 | #ifndef EV_USE_REALTIME |
177 | #ifndef EV_USE_REALTIME |
173 | # define EV_USE_REALTIME 0 |
178 | # define EV_USE_REALTIME 0 |
174 | #endif |
179 | #endif |
175 | |
180 | |
176 | #ifndef EV_USE_NANOSLEEP |
181 | #ifndef EV_USE_NANOSLEEP |
|
|
182 | # if _POSIX_C_SOURCE >= 199309L |
|
|
183 | # define EV_USE_NANOSLEEP 1 |
|
|
184 | # else |
177 | # define EV_USE_NANOSLEEP 0 |
185 | # define EV_USE_NANOSLEEP 0 |
|
|
186 | # endif |
178 | #endif |
187 | #endif |
179 | |
188 | |
180 | #ifndef EV_USE_SELECT |
189 | #ifndef EV_USE_SELECT |
181 | # define EV_USE_SELECT 1 |
190 | # define EV_USE_SELECT 1 |
182 | #endif |
191 | #endif |
… | |
… | |
278 | # endif |
287 | # endif |
279 | #endif |
288 | #endif |
280 | |
289 | |
281 | #if EV_USE_INOTIFY |
290 | #if EV_USE_INOTIFY |
282 | # include <sys/inotify.h> |
291 | # include <sys/inotify.h> |
|
|
292 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
|
|
293 | # ifndef IN_DONT_FOLLOW |
|
|
294 | # undef EV_USE_INOTIFY |
|
|
295 | # define EV_USE_INOTIFY 0 |
|
|
296 | # endif |
283 | #endif |
297 | #endif |
284 | |
298 | |
285 | #if EV_SELECT_IS_WINSOCKET |
299 | #if EV_SELECT_IS_WINSOCKET |
286 | # include <winsock.h> |
300 | # include <winsock.h> |
287 | #endif |
301 | #endif |
… | |
… | |
556 | struct timeval tv; |
570 | struct timeval tv; |
557 | |
571 | |
558 | tv.tv_sec = (time_t)delay; |
572 | tv.tv_sec = (time_t)delay; |
559 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
573 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
560 | |
574 | |
|
|
575 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
|
|
576 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
|
|
577 | /* by older ones */ |
561 | select (0, 0, 0, 0, &tv); |
578 | select (0, 0, 0, 0, &tv); |
562 | #endif |
579 | #endif |
563 | } |
580 | } |
564 | } |
581 | } |
565 | |
582 | |
… | |
… | |
699 | events |= (unsigned char)w->events; |
716 | events |= (unsigned char)w->events; |
700 | |
717 | |
701 | #if EV_SELECT_IS_WINSOCKET |
718 | #if EV_SELECT_IS_WINSOCKET |
702 | if (events) |
719 | if (events) |
703 | { |
720 | { |
704 | unsigned long argp; |
721 | unsigned long arg; |
705 | #ifdef EV_FD_TO_WIN32_HANDLE |
722 | #ifdef EV_FD_TO_WIN32_HANDLE |
706 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
723 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
707 | #else |
724 | #else |
708 | anfd->handle = _get_osfhandle (fd); |
725 | anfd->handle = _get_osfhandle (fd); |
709 | #endif |
726 | #endif |
710 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
727 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
711 | } |
728 | } |
712 | #endif |
729 | #endif |
713 | |
730 | |
714 | { |
731 | { |
715 | unsigned char o_events = anfd->events; |
732 | unsigned char o_events = anfd->events; |
… | |
… | |
768 | { |
785 | { |
769 | int fd; |
786 | int fd; |
770 | |
787 | |
771 | for (fd = 0; fd < anfdmax; ++fd) |
788 | for (fd = 0; fd < anfdmax; ++fd) |
772 | if (anfds [fd].events) |
789 | if (anfds [fd].events) |
773 | if (!fd_valid (fd) == -1 && errno == EBADF) |
790 | if (!fd_valid (fd) && errno == EBADF) |
774 | fd_kill (EV_A_ fd); |
791 | fd_kill (EV_A_ fd); |
775 | } |
792 | } |
776 | |
793 | |
777 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
794 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
778 | static void noinline |
795 | static void noinline |
… | |
… | |
975 | |
992 | |
976 | void inline_speed |
993 | void inline_speed |
977 | fd_intern (int fd) |
994 | fd_intern (int fd) |
978 | { |
995 | { |
979 | #ifdef _WIN32 |
996 | #ifdef _WIN32 |
980 | int arg = 1; |
997 | unsigned long arg = 1; |
981 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
998 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
982 | #else |
999 | #else |
983 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
1000 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
984 | fcntl (fd, F_SETFL, O_NONBLOCK); |
1001 | fcntl (fd, F_SETFL, O_NONBLOCK); |
985 | #endif |
1002 | #endif |
… | |
… | |
1499 | { |
1516 | { |
1500 | postfork = 1; /* must be in line with ev_default_fork */ |
1517 | postfork = 1; /* must be in line with ev_default_fork */ |
1501 | } |
1518 | } |
1502 | |
1519 | |
1503 | #if EV_VERIFY |
1520 | #if EV_VERIFY |
1504 | void noinline |
1521 | static void noinline |
1505 | verify_watcher (EV_P_ W w) |
1522 | verify_watcher (EV_P_ W w) |
1506 | { |
1523 | { |
1507 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1524 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1508 | |
1525 | |
1509 | if (w->pending) |
1526 | if (w->pending) |
… | |
… | |
1897 | ev_unref (EV_P) |
1914 | ev_unref (EV_P) |
1898 | { |
1915 | { |
1899 | --activecnt; |
1916 | --activecnt; |
1900 | } |
1917 | } |
1901 | |
1918 | |
|
|
1919 | void |
|
|
1920 | ev_now_update (EV_P) |
|
|
1921 | { |
|
|
1922 | time_update (EV_A_ 1e100); |
|
|
1923 | } |
|
|
1924 | |
1902 | static int loop_done; |
1925 | static int loop_done; |
1903 | |
1926 | |
1904 | void |
1927 | void |
1905 | ev_loop (EV_P_ int flags) |
1928 | ev_loop (EV_P_ int flags) |
1906 | { |
1929 | { |
… | |
… | |
2559 | } |
2582 | } |
2560 | |
2583 | |
2561 | } |
2584 | } |
2562 | } |
2585 | } |
2563 | |
2586 | |
|
|
2587 | #endif |
|
|
2588 | |
|
|
2589 | #ifdef _WIN32 |
|
|
2590 | # define EV_LSTAT(p,b) _stati64 (p, b) |
|
|
2591 | #else |
|
|
2592 | # define EV_LSTAT(p,b) lstat (p, b) |
2564 | #endif |
2593 | #endif |
2565 | |
2594 | |
2566 | void |
2595 | void |
2567 | ev_stat_stat (EV_P_ ev_stat *w) |
2596 | ev_stat_stat (EV_P_ ev_stat *w) |
2568 | { |
2597 | { |
… | |
… | |
2809 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2838 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2810 | } |
2839 | } |
2811 | } |
2840 | } |
2812 | } |
2841 | } |
2813 | |
2842 | |
|
|
2843 | static void |
|
|
2844 | embed_fork_cb (EV_P_ ev_fork *fork_w, int revents) |
|
|
2845 | { |
|
|
2846 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
|
|
2847 | |
|
|
2848 | { |
|
|
2849 | struct ev_loop *loop = w->other; |
|
|
2850 | |
|
|
2851 | ev_loop_fork (EV_A); |
|
|
2852 | } |
|
|
2853 | } |
|
|
2854 | |
2814 | #if 0 |
2855 | #if 0 |
2815 | static void |
2856 | static void |
2816 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2857 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2817 | { |
2858 | { |
2818 | ev_idle_stop (EV_A_ idle); |
2859 | ev_idle_stop (EV_A_ idle); |
… | |
… | |
2838 | |
2879 | |
2839 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2880 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2840 | ev_set_priority (&w->prepare, EV_MINPRI); |
2881 | ev_set_priority (&w->prepare, EV_MINPRI); |
2841 | ev_prepare_start (EV_A_ &w->prepare); |
2882 | ev_prepare_start (EV_A_ &w->prepare); |
2842 | |
2883 | |
|
|
2884 | ev_fork_init (&w->fork, embed_fork_cb); |
|
|
2885 | ev_fork_start (EV_A_ &w->fork); |
|
|
2886 | |
2843 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2887 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2844 | |
2888 | |
2845 | ev_start (EV_A_ (W)w, 1); |
2889 | ev_start (EV_A_ (W)w, 1); |
2846 | |
2890 | |
2847 | EV_FREQUENT_CHECK; |
2891 | EV_FREQUENT_CHECK; |
… | |
… | |
2854 | if (expect_false (!ev_is_active (w))) |
2898 | if (expect_false (!ev_is_active (w))) |
2855 | return; |
2899 | return; |
2856 | |
2900 | |
2857 | EV_FREQUENT_CHECK; |
2901 | EV_FREQUENT_CHECK; |
2858 | |
2902 | |
2859 | ev_io_stop (EV_A_ &w->io); |
2903 | ev_io_stop (EV_A_ &w->io); |
2860 | ev_prepare_stop (EV_A_ &w->prepare); |
2904 | ev_prepare_stop (EV_A_ &w->prepare); |
2861 | |
2905 | ev_fork_stop (EV_A_ &w->fork); |
2862 | ev_stop (EV_A_ (W)w); |
|
|
2863 | |
2906 | |
2864 | EV_FREQUENT_CHECK; |
2907 | EV_FREQUENT_CHECK; |
2865 | } |
2908 | } |
2866 | #endif |
2909 | #endif |
2867 | |
2910 | |
… | |
… | |
2964 | once_cb (EV_P_ struct ev_once *once, int revents) |
3007 | once_cb (EV_P_ struct ev_once *once, int revents) |
2965 | { |
3008 | { |
2966 | void (*cb)(int revents, void *arg) = once->cb; |
3009 | void (*cb)(int revents, void *arg) = once->cb; |
2967 | void *arg = once->arg; |
3010 | void *arg = once->arg; |
2968 | |
3011 | |
2969 | ev_io_stop (EV_A_ &once->io); |
3012 | ev_io_stop (EV_A_ &once->io); |
2970 | ev_timer_stop (EV_A_ &once->to); |
3013 | ev_timer_stop (EV_A_ &once->to); |
2971 | ev_free (once); |
3014 | ev_free (once); |
2972 | |
3015 | |
2973 | cb (revents, arg); |
3016 | cb (revents, arg); |
2974 | } |
3017 | } |
2975 | |
3018 | |
2976 | static void |
3019 | static void |
2977 | once_cb_io (EV_P_ ev_io *w, int revents) |
3020 | once_cb_io (EV_P_ ev_io *w, int revents) |
2978 | { |
3021 | { |
2979 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
3022 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)); |
|
|
3023 | |
|
|
3024 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->to)); |
2980 | } |
3025 | } |
2981 | |
3026 | |
2982 | static void |
3027 | static void |
2983 | once_cb_to (EV_P_ ev_timer *w, int revents) |
3028 | once_cb_to (EV_P_ ev_timer *w, int revents) |
2984 | { |
3029 | { |
2985 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
3030 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)); |
|
|
3031 | |
|
|
3032 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
2986 | } |
3033 | } |
2987 | |
3034 | |
2988 | void |
3035 | void |
2989 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
3036 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
2990 | { |
3037 | { |