… | |
… | |
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 |
… | |
… | |
285 | # include <sys/select.h> |
286 | # include <sys/select.h> |
286 | # endif |
287 | # endif |
287 | #endif |
288 | #endif |
288 | |
289 | |
289 | #if EV_USE_INOTIFY |
290 | #if EV_USE_INOTIFY |
|
|
291 | # include <sys/utsname.h> |
290 | # include <sys/inotify.h> |
292 | # include <sys/inotify.h> |
|
|
293 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
|
|
294 | # ifndef IN_DONT_FOLLOW |
|
|
295 | # undef EV_USE_INOTIFY |
|
|
296 | # define EV_USE_INOTIFY 0 |
|
|
297 | # endif |
291 | #endif |
298 | #endif |
292 | |
299 | |
293 | #if EV_SELECT_IS_WINSOCKET |
300 | #if EV_SELECT_IS_WINSOCKET |
294 | # include <winsock.h> |
301 | # include <winsock.h> |
295 | #endif |
302 | #endif |
… | |
… | |
564 | struct timeval tv; |
571 | struct timeval tv; |
565 | |
572 | |
566 | tv.tv_sec = (time_t)delay; |
573 | tv.tv_sec = (time_t)delay; |
567 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
574 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
568 | |
575 | |
|
|
576 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
|
|
577 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
|
|
578 | /* by older ones */ |
569 | select (0, 0, 0, 0, &tv); |
579 | select (0, 0, 0, 0, &tv); |
570 | #endif |
580 | #endif |
571 | } |
581 | } |
572 | } |
582 | } |
573 | |
583 | |
… | |
… | |
707 | events |= (unsigned char)w->events; |
717 | events |= (unsigned char)w->events; |
708 | |
718 | |
709 | #if EV_SELECT_IS_WINSOCKET |
719 | #if EV_SELECT_IS_WINSOCKET |
710 | if (events) |
720 | if (events) |
711 | { |
721 | { |
712 | unsigned long argp; |
722 | unsigned long arg; |
713 | #ifdef EV_FD_TO_WIN32_HANDLE |
723 | #ifdef EV_FD_TO_WIN32_HANDLE |
714 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
724 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
715 | #else |
725 | #else |
716 | anfd->handle = _get_osfhandle (fd); |
726 | anfd->handle = _get_osfhandle (fd); |
717 | #endif |
727 | #endif |
718 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
728 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
719 | } |
729 | } |
720 | #endif |
730 | #endif |
721 | |
731 | |
722 | { |
732 | { |
723 | unsigned char o_events = anfd->events; |
733 | unsigned char o_events = anfd->events; |
… | |
… | |
776 | { |
786 | { |
777 | int fd; |
787 | int fd; |
778 | |
788 | |
779 | for (fd = 0; fd < anfdmax; ++fd) |
789 | for (fd = 0; fd < anfdmax; ++fd) |
780 | if (anfds [fd].events) |
790 | if (anfds [fd].events) |
781 | if (!fd_valid (fd) == -1 && errno == EBADF) |
791 | if (!fd_valid (fd) && errno == EBADF) |
782 | fd_kill (EV_A_ fd); |
792 | fd_kill (EV_A_ fd); |
783 | } |
793 | } |
784 | |
794 | |
785 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
795 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
786 | static void noinline |
796 | static void noinline |
… | |
… | |
983 | |
993 | |
984 | void inline_speed |
994 | void inline_speed |
985 | fd_intern (int fd) |
995 | fd_intern (int fd) |
986 | { |
996 | { |
987 | #ifdef _WIN32 |
997 | #ifdef _WIN32 |
988 | int arg = 1; |
998 | unsigned long arg = 1; |
989 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
999 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
990 | #else |
1000 | #else |
991 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
1001 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
992 | fcntl (fd, F_SETFL, O_NONBLOCK); |
1002 | fcntl (fd, F_SETFL, O_NONBLOCK); |
993 | #endif |
1003 | #endif |
… | |
… | |
1507 | { |
1517 | { |
1508 | postfork = 1; /* must be in line with ev_default_fork */ |
1518 | postfork = 1; /* must be in line with ev_default_fork */ |
1509 | } |
1519 | } |
1510 | |
1520 | |
1511 | #if EV_VERIFY |
1521 | #if EV_VERIFY |
1512 | void noinline |
1522 | static void noinline |
1513 | verify_watcher (EV_P_ W w) |
1523 | verify_watcher (EV_P_ W w) |
1514 | { |
1524 | { |
1515 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1525 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1516 | |
1526 | |
1517 | if (w->pending) |
1527 | if (w->pending) |
… | |
… | |
1905 | ev_unref (EV_P) |
1915 | ev_unref (EV_P) |
1906 | { |
1916 | { |
1907 | --activecnt; |
1917 | --activecnt; |
1908 | } |
1918 | } |
1909 | |
1919 | |
|
|
1920 | void |
|
|
1921 | ev_now_update (EV_P) |
|
|
1922 | { |
|
|
1923 | time_update (EV_A_ 1e100); |
|
|
1924 | } |
|
|
1925 | |
1910 | static int loop_done; |
1926 | static int loop_done; |
1911 | |
1927 | |
1912 | void |
1928 | void |
1913 | ev_loop (EV_P_ int flags) |
1929 | ev_loop (EV_P_ int flags) |
1914 | { |
1930 | { |
… | |
… | |
2481 | |
2497 | |
2482 | static void noinline |
2498 | static void noinline |
2483 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2499 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2484 | { |
2500 | { |
2485 | if (slot < 0) |
2501 | if (slot < 0) |
2486 | /* overflow, need to check for all hahs slots */ |
2502 | /* overflow, need to check for all hash slots */ |
2487 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2503 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2488 | infy_wd (EV_A_ slot, wd, ev); |
2504 | infy_wd (EV_A_ slot, wd, ev); |
2489 | else |
2505 | else |
2490 | { |
2506 | { |
2491 | WL w_; |
2507 | WL w_; |
… | |
… | |
2525 | infy_init (EV_P) |
2541 | infy_init (EV_P) |
2526 | { |
2542 | { |
2527 | if (fs_fd != -2) |
2543 | if (fs_fd != -2) |
2528 | return; |
2544 | return; |
2529 | |
2545 | |
|
|
2546 | /* kernels < 2.6.25 are borked |
|
|
2547 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
|
|
2548 | */ |
|
|
2549 | { |
|
|
2550 | struct utsname buf; |
|
|
2551 | int major, minor, micro; |
|
|
2552 | |
|
|
2553 | fs_fd = -1; |
|
|
2554 | |
|
|
2555 | if (uname (&buf)) |
|
|
2556 | return; |
|
|
2557 | |
|
|
2558 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
|
|
2559 | return; |
|
|
2560 | |
|
|
2561 | if (major < 2 |
|
|
2562 | || (major == 2 && minor < 6) |
|
|
2563 | || (major == 2 && minor == 6 && micro < 25)) |
|
|
2564 | return; |
|
|
2565 | } |
|
|
2566 | |
2530 | fs_fd = inotify_init (); |
2567 | fs_fd = inotify_init (); |
2531 | |
2568 | |
2532 | if (fs_fd >= 0) |
2569 | if (fs_fd >= 0) |
2533 | { |
2570 | { |
2534 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
2571 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
… | |
… | |
2563 | if (fs_fd >= 0) |
2600 | if (fs_fd >= 0) |
2564 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2601 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2565 | else |
2602 | else |
2566 | ev_timer_start (EV_A_ &w->timer); |
2603 | ev_timer_start (EV_A_ &w->timer); |
2567 | } |
2604 | } |
2568 | |
|
|
2569 | } |
2605 | } |
2570 | } |
2606 | } |
2571 | |
2607 | |
|
|
2608 | #endif |
|
|
2609 | |
|
|
2610 | #ifdef _WIN32 |
|
|
2611 | # define EV_LSTAT(p,b) _stati64 (p, b) |
|
|
2612 | #else |
|
|
2613 | # define EV_LSTAT(p,b) lstat (p, b) |
2572 | #endif |
2614 | #endif |
2573 | |
2615 | |
2574 | void |
2616 | void |
2575 | ev_stat_stat (EV_P_ ev_stat *w) |
2617 | ev_stat_stat (EV_P_ ev_stat *w) |
2576 | { |
2618 | { |
… | |
… | |
2603 | || w->prev.st_atime != w->attr.st_atime |
2645 | || w->prev.st_atime != w->attr.st_atime |
2604 | || w->prev.st_mtime != w->attr.st_mtime |
2646 | || w->prev.st_mtime != w->attr.st_mtime |
2605 | || w->prev.st_ctime != w->attr.st_ctime |
2647 | || w->prev.st_ctime != w->attr.st_ctime |
2606 | ) { |
2648 | ) { |
2607 | #if EV_USE_INOTIFY |
2649 | #if EV_USE_INOTIFY |
|
|
2650 | if (fs_fd >= 0) |
|
|
2651 | { |
2608 | infy_del (EV_A_ w); |
2652 | infy_del (EV_A_ w); |
2609 | infy_add (EV_A_ w); |
2653 | infy_add (EV_A_ w); |
2610 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
2654 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
|
|
2655 | } |
2611 | #endif |
2656 | #endif |
2612 | |
2657 | |
2613 | ev_feed_event (EV_A_ w, EV_STAT); |
2658 | ev_feed_event (EV_A_ w, EV_STAT); |
2614 | } |
2659 | } |
2615 | } |
2660 | } |
… | |
… | |
2817 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2862 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2818 | } |
2863 | } |
2819 | } |
2864 | } |
2820 | } |
2865 | } |
2821 | |
2866 | |
|
|
2867 | static void |
|
|
2868 | embed_fork_cb (EV_P_ ev_fork *fork_w, int revents) |
|
|
2869 | { |
|
|
2870 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
|
|
2871 | |
|
|
2872 | { |
|
|
2873 | struct ev_loop *loop = w->other; |
|
|
2874 | |
|
|
2875 | ev_loop_fork (EV_A); |
|
|
2876 | } |
|
|
2877 | } |
|
|
2878 | |
2822 | #if 0 |
2879 | #if 0 |
2823 | static void |
2880 | static void |
2824 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2881 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2825 | { |
2882 | { |
2826 | ev_idle_stop (EV_A_ idle); |
2883 | ev_idle_stop (EV_A_ idle); |
… | |
… | |
2846 | |
2903 | |
2847 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2904 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2848 | ev_set_priority (&w->prepare, EV_MINPRI); |
2905 | ev_set_priority (&w->prepare, EV_MINPRI); |
2849 | ev_prepare_start (EV_A_ &w->prepare); |
2906 | ev_prepare_start (EV_A_ &w->prepare); |
2850 | |
2907 | |
|
|
2908 | ev_fork_init (&w->fork, embed_fork_cb); |
|
|
2909 | ev_fork_start (EV_A_ &w->fork); |
|
|
2910 | |
2851 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2911 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2852 | |
2912 | |
2853 | ev_start (EV_A_ (W)w, 1); |
2913 | ev_start (EV_A_ (W)w, 1); |
2854 | |
2914 | |
2855 | EV_FREQUENT_CHECK; |
2915 | EV_FREQUENT_CHECK; |
… | |
… | |
2862 | if (expect_false (!ev_is_active (w))) |
2922 | if (expect_false (!ev_is_active (w))) |
2863 | return; |
2923 | return; |
2864 | |
2924 | |
2865 | EV_FREQUENT_CHECK; |
2925 | EV_FREQUENT_CHECK; |
2866 | |
2926 | |
2867 | ev_io_stop (EV_A_ &w->io); |
2927 | ev_io_stop (EV_A_ &w->io); |
2868 | ev_prepare_stop (EV_A_ &w->prepare); |
2928 | ev_prepare_stop (EV_A_ &w->prepare); |
2869 | |
2929 | ev_fork_stop (EV_A_ &w->fork); |
2870 | ev_stop (EV_A_ (W)w); |
|
|
2871 | |
2930 | |
2872 | EV_FREQUENT_CHECK; |
2931 | EV_FREQUENT_CHECK; |
2873 | } |
2932 | } |
2874 | #endif |
2933 | #endif |
2875 | |
2934 | |
… | |
… | |
2972 | once_cb (EV_P_ struct ev_once *once, int revents) |
3031 | once_cb (EV_P_ struct ev_once *once, int revents) |
2973 | { |
3032 | { |
2974 | void (*cb)(int revents, void *arg) = once->cb; |
3033 | void (*cb)(int revents, void *arg) = once->cb; |
2975 | void *arg = once->arg; |
3034 | void *arg = once->arg; |
2976 | |
3035 | |
2977 | ev_io_stop (EV_A_ &once->io); |
3036 | ev_io_stop (EV_A_ &once->io); |
2978 | ev_timer_stop (EV_A_ &once->to); |
3037 | ev_timer_stop (EV_A_ &once->to); |
2979 | ev_free (once); |
3038 | ev_free (once); |
2980 | |
3039 | |
2981 | cb (revents, arg); |
3040 | cb (revents, arg); |
2982 | } |
3041 | } |
2983 | |
3042 | |
2984 | static void |
3043 | static void |
2985 | once_cb_io (EV_P_ ev_io *w, int revents) |
3044 | once_cb_io (EV_P_ ev_io *w, int revents) |
2986 | { |
3045 | { |
2987 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
3046 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)); |
|
|
3047 | |
|
|
3048 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->to)); |
2988 | } |
3049 | } |
2989 | |
3050 | |
2990 | static void |
3051 | static void |
2991 | once_cb_to (EV_P_ ev_timer *w, int revents) |
3052 | once_cb_to (EV_P_ ev_timer *w, int revents) |
2992 | { |
3053 | { |
2993 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
3054 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)); |
|
|
3055 | |
|
|
3056 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
2994 | } |
3057 | } |
2995 | |
3058 | |
2996 | void |
3059 | void |
2997 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
3060 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
2998 | { |
3061 | { |