… | |
… | |
286 | # include <sys/select.h> |
286 | # include <sys/select.h> |
287 | # endif |
287 | # endif |
288 | #endif |
288 | #endif |
289 | |
289 | |
290 | #if EV_USE_INOTIFY |
290 | #if EV_USE_INOTIFY |
|
|
291 | # include <sys/utsname.h> |
291 | # 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 |
292 | #endif |
298 | #endif |
293 | |
299 | |
294 | #if EV_SELECT_IS_WINSOCKET |
300 | #if EV_SELECT_IS_WINSOCKET |
295 | # include <winsock.h> |
301 | # include <winsock.h> |
296 | #endif |
302 | #endif |
… | |
… | |
2491 | |
2497 | |
2492 | static void noinline |
2498 | static void noinline |
2493 | 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) |
2494 | { |
2500 | { |
2495 | if (slot < 0) |
2501 | if (slot < 0) |
2496 | /* overflow, need to check for all hahs slots */ |
2502 | /* overflow, need to check for all hash slots */ |
2497 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2503 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2498 | infy_wd (EV_A_ slot, wd, ev); |
2504 | infy_wd (EV_A_ slot, wd, ev); |
2499 | else |
2505 | else |
2500 | { |
2506 | { |
2501 | WL w_; |
2507 | WL w_; |
… | |
… | |
2535 | infy_init (EV_P) |
2541 | infy_init (EV_P) |
2536 | { |
2542 | { |
2537 | if (fs_fd != -2) |
2543 | if (fs_fd != -2) |
2538 | return; |
2544 | return; |
2539 | |
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 | |
2540 | fs_fd = inotify_init (); |
2567 | fs_fd = inotify_init (); |
2541 | |
2568 | |
2542 | if (fs_fd >= 0) |
2569 | if (fs_fd >= 0) |
2543 | { |
2570 | { |
2544 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
2571 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
… | |
… | |
2573 | if (fs_fd >= 0) |
2600 | if (fs_fd >= 0) |
2574 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2601 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2575 | else |
2602 | else |
2576 | ev_timer_start (EV_A_ &w->timer); |
2603 | ev_timer_start (EV_A_ &w->timer); |
2577 | } |
2604 | } |
2578 | |
|
|
2579 | } |
2605 | } |
2580 | } |
2606 | } |
2581 | |
2607 | |
2582 | #endif |
2608 | #endif |
2583 | |
2609 | |
… | |
… | |
2619 | || w->prev.st_atime != w->attr.st_atime |
2645 | || w->prev.st_atime != w->attr.st_atime |
2620 | || w->prev.st_mtime != w->attr.st_mtime |
2646 | || w->prev.st_mtime != w->attr.st_mtime |
2621 | || w->prev.st_ctime != w->attr.st_ctime |
2647 | || w->prev.st_ctime != w->attr.st_ctime |
2622 | ) { |
2648 | ) { |
2623 | #if EV_USE_INOTIFY |
2649 | #if EV_USE_INOTIFY |
|
|
2650 | if (fs_fd >= 0) |
|
|
2651 | { |
2624 | infy_del (EV_A_ w); |
2652 | infy_del (EV_A_ w); |
2625 | infy_add (EV_A_ w); |
2653 | infy_add (EV_A_ w); |
2626 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
2654 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
|
|
2655 | } |
2627 | #endif |
2656 | #endif |
2628 | |
2657 | |
2629 | ev_feed_event (EV_A_ w, EV_STAT); |
2658 | ev_feed_event (EV_A_ w, EV_STAT); |
2630 | } |
2659 | } |
2631 | } |
2660 | } |
… | |
… | |
2833 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2862 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2834 | } |
2863 | } |
2835 | } |
2864 | } |
2836 | } |
2865 | } |
2837 | |
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 | |
2838 | #if 0 |
2879 | #if 0 |
2839 | static void |
2880 | static void |
2840 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2881 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2841 | { |
2882 | { |
2842 | ev_idle_stop (EV_A_ idle); |
2883 | ev_idle_stop (EV_A_ idle); |
… | |
… | |
2862 | |
2903 | |
2863 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2904 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2864 | ev_set_priority (&w->prepare, EV_MINPRI); |
2905 | ev_set_priority (&w->prepare, EV_MINPRI); |
2865 | ev_prepare_start (EV_A_ &w->prepare); |
2906 | ev_prepare_start (EV_A_ &w->prepare); |
2866 | |
2907 | |
|
|
2908 | ev_fork_init (&w->fork, embed_fork_cb); |
|
|
2909 | ev_fork_start (EV_A_ &w->fork); |
|
|
2910 | |
2867 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2911 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2868 | |
2912 | |
2869 | ev_start (EV_A_ (W)w, 1); |
2913 | ev_start (EV_A_ (W)w, 1); |
2870 | |
2914 | |
2871 | EV_FREQUENT_CHECK; |
2915 | EV_FREQUENT_CHECK; |
… | |
… | |
2878 | if (expect_false (!ev_is_active (w))) |
2922 | if (expect_false (!ev_is_active (w))) |
2879 | return; |
2923 | return; |
2880 | |
2924 | |
2881 | EV_FREQUENT_CHECK; |
2925 | EV_FREQUENT_CHECK; |
2882 | |
2926 | |
2883 | ev_io_stop (EV_A_ &w->io); |
2927 | ev_io_stop (EV_A_ &w->io); |
2884 | ev_prepare_stop (EV_A_ &w->prepare); |
2928 | ev_prepare_stop (EV_A_ &w->prepare); |
2885 | |
2929 | ev_fork_stop (EV_A_ &w->fork); |
2886 | ev_stop (EV_A_ (W)w); |
|
|
2887 | |
2930 | |
2888 | EV_FREQUENT_CHECK; |
2931 | EV_FREQUENT_CHECK; |
2889 | } |
2932 | } |
2890 | #endif |
2933 | #endif |
2891 | |
2934 | |
… | |
… | |
2998 | } |
3041 | } |
2999 | |
3042 | |
3000 | static void |
3043 | static void |
3001 | once_cb_io (EV_P_ ev_io *w, int revents) |
3044 | once_cb_io (EV_P_ ev_io *w, int revents) |
3002 | { |
3045 | { |
3003 | 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)); |
3004 | } |
3049 | } |
3005 | |
3050 | |
3006 | static void |
3051 | static void |
3007 | once_cb_to (EV_P_ ev_timer *w, int revents) |
3052 | once_cb_to (EV_P_ ev_timer *w, int revents) |
3008 | { |
3053 | { |
3009 | 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)); |
3010 | } |
3057 | } |
3011 | |
3058 | |
3012 | void |
3059 | void |
3013 | 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) |
3014 | { |
3061 | { |