… | |
… | |
302 | # define EV_USE_EVENTFD 0 |
302 | # define EV_USE_EVENTFD 0 |
303 | # endif |
303 | # endif |
304 | #endif |
304 | #endif |
305 | |
305 | |
306 | #ifndef EV_USE_SIGNALFD |
306 | #ifndef EV_USE_SIGNALFD |
307 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9)) |
307 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
308 | # define EV_USE_SIGNALFD 1 |
308 | # define EV_USE_SIGNALFD 1 |
309 | # else |
309 | # else |
310 | # define EV_USE_SIGNALFD 0 |
310 | # define EV_USE_SIGNALFD 0 |
311 | # endif |
311 | # endif |
312 | #endif |
312 | #endif |
… | |
… | |
402 | } |
402 | } |
403 | # endif |
403 | # endif |
404 | #endif |
404 | #endif |
405 | |
405 | |
406 | #if EV_USE_SIGNALFD |
406 | #if EV_USE_SIGNALFD |
407 | # include <sys/signalfd.h> |
407 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
|
|
408 | # include <stdint.h> |
|
|
409 | # ifndef SFD_NONBLOCK |
|
|
410 | # define SFD_NONBLOCK O_NONBLOCK |
408 | #endif |
411 | # endif |
|
|
412 | # ifndef SFD_CLOEXEC |
|
|
413 | # ifdef O_CLOEXEC |
|
|
414 | # define SFD_CLOEXEC O_CLOEXEC |
|
|
415 | # else |
|
|
416 | # define SFD_CLOEXEC 02000000 |
|
|
417 | # endif |
|
|
418 | # endif |
|
|
419 | # ifdef __cplusplus |
|
|
420 | extern "C" { |
|
|
421 | # endif |
|
|
422 | int signalfd (int fd, const sigset_t *mask, int flags); |
|
|
423 | |
|
|
424 | struct signalfd_siginfo |
|
|
425 | { |
|
|
426 | uint32_t ssi_signo; |
|
|
427 | char pad[128 - sizeof (uint32_t)]; |
|
|
428 | }; |
|
|
429 | # ifdef __cplusplus |
|
|
430 | } |
|
|
431 | # endif |
|
|
432 | #endif |
|
|
433 | |
409 | |
434 | |
410 | /**/ |
435 | /**/ |
411 | |
436 | |
412 | #if EV_VERIFY >= 3 |
437 | #if EV_VERIFY >= 3 |
413 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
438 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
… | |
… | |
476 | |
501 | |
477 | #if EV_USE_MONOTONIC |
502 | #if EV_USE_MONOTONIC |
478 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
503 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
479 | #endif |
504 | #endif |
480 | |
505 | |
|
|
506 | #ifndef EV_FD_TO_WIN32_HANDLE |
|
|
507 | # define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) |
|
|
508 | #endif |
|
|
509 | #ifndef EV_WIN32_HANDLE_TO_FD |
|
|
510 | # define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (fd, 0) |
|
|
511 | #endif |
|
|
512 | #ifndef EV_WIN32_CLOSE_FD |
|
|
513 | # define EV_WIN32_CLOSE_FD(fd) close (fd) |
|
|
514 | #endif |
|
|
515 | |
481 | #ifdef _WIN32 |
516 | #ifdef _WIN32 |
482 | # include "ev_win32.c" |
517 | # include "ev_win32.c" |
483 | #endif |
518 | #endif |
484 | |
519 | |
485 | /*****************************************************************************/ |
520 | /*****************************************************************************/ |
… | |
… | |
876 | |
911 | |
877 | #if EV_SELECT_IS_WINSOCKET |
912 | #if EV_SELECT_IS_WINSOCKET |
878 | if (events) |
913 | if (events) |
879 | { |
914 | { |
880 | unsigned long arg; |
915 | unsigned long arg; |
881 | #ifdef EV_FD_TO_WIN32_HANDLE |
|
|
882 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
916 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
883 | #else |
|
|
884 | anfd->handle = _get_osfhandle (fd); |
|
|
885 | #endif |
|
|
886 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
917 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
887 | } |
918 | } |
888 | #endif |
919 | #endif |
889 | |
920 | |
890 | { |
921 | { |
… | |
… | |
1621 | close (evfd); |
1652 | close (evfd); |
1622 | #endif |
1653 | #endif |
1623 | |
1654 | |
1624 | if (evpipe [0] >= 0) |
1655 | if (evpipe [0] >= 0) |
1625 | { |
1656 | { |
1626 | close (evpipe [0]); |
1657 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1627 | close (evpipe [1]); |
1658 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1628 | } |
1659 | } |
1629 | } |
1660 | } |
1630 | |
1661 | |
1631 | #if EV_USE_SIGNALFD |
1662 | #if EV_USE_SIGNALFD |
1632 | if (ev_is_active (&sigfd_w)) |
1663 | if (ev_is_active (&sigfd_w)) |
… | |
… | |
1728 | close (evfd); |
1759 | close (evfd); |
1729 | #endif |
1760 | #endif |
1730 | |
1761 | |
1731 | if (evpipe [0] >= 0) |
1762 | if (evpipe [0] >= 0) |
1732 | { |
1763 | { |
1733 | close (evpipe [0]); |
1764 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1734 | close (evpipe [1]); |
1765 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1735 | } |
1766 | } |
1736 | |
1767 | |
1737 | evpipe_init (EV_A); |
1768 | evpipe_init (EV_A); |
1738 | /* now iterate over everything, in case we missed something */ |
1769 | /* now iterate over everything, in case we missed something */ |
1739 | pipecb (EV_A_ &pipe_w, EV_READ); |
1770 | pipecb (EV_A_ &pipe_w, EV_READ); |
… | |
… | |
2861 | } |
2892 | } |
2862 | } |
2893 | } |
2863 | |
2894 | |
2864 | if (w->wd >= 0) |
2895 | if (w->wd >= 0) |
2865 | { |
2896 | { |
|
|
2897 | struct statfs sfs; |
|
|
2898 | |
2866 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2899 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2867 | |
2900 | |
2868 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2901 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2869 | /* unless the filesystem it known to be local, we therefore still poll */ |
2902 | /* unless the filesystem it known to be local, we therefore still poll */ |
2870 | /* also do poll on <2.6.25, but with normal frequency */ |
2903 | /* also do poll on <2.6.25, but with normal frequency */ |
2871 | struct statfs sfs; |
|
|
2872 | |
2904 | |
2873 | if (fs_2625 && !statfs (w->path, &sfs)) |
2905 | if (fs_2625 && !statfs (w->path, &sfs)) |
2874 | if (sfs.f_type == 0x1373 /* devfs */ |
2906 | if (sfs.f_type == 0x1373 /* devfs */ |
2875 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
2907 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
2876 | || sfs.f_type == 0x3153464a /* jfs */ |
2908 | || sfs.f_type == 0x3153464a /* jfs */ |
… | |
… | |
2965 | return; |
2997 | return; |
2966 | |
2998 | |
2967 | fs_2625 = 1; |
2999 | fs_2625 = 1; |
2968 | } |
3000 | } |
2969 | |
3001 | |
|
|
3002 | inline_size int |
|
|
3003 | infy_newfd (void) |
|
|
3004 | { |
|
|
3005 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
|
|
3006 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
|
|
3007 | if (fd >= 0) |
|
|
3008 | return fd; |
|
|
3009 | #endif |
|
|
3010 | return inotify_init (); |
|
|
3011 | } |
|
|
3012 | |
2970 | inline_size void |
3013 | inline_size void |
2971 | infy_init (EV_P) |
3014 | infy_init (EV_P) |
2972 | { |
3015 | { |
2973 | if (fs_fd != -2) |
3016 | if (fs_fd != -2) |
2974 | return; |
3017 | return; |
2975 | |
3018 | |
2976 | fs_fd = -1; |
3019 | fs_fd = -1; |
2977 | |
3020 | |
2978 | check_2625 (EV_A); |
3021 | check_2625 (EV_A); |
2979 | |
3022 | |
2980 | fs_fd = inotify_init (); |
3023 | fs_fd = infy_newfd (); |
2981 | |
3024 | |
2982 | if (fs_fd >= 0) |
3025 | if (fs_fd >= 0) |
2983 | { |
3026 | { |
|
|
3027 | fd_intern (fs_fd); |
2984 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3028 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
2985 | ev_set_priority (&fs_w, EV_MAXPRI); |
3029 | ev_set_priority (&fs_w, EV_MAXPRI); |
2986 | ev_io_start (EV_A_ &fs_w); |
3030 | ev_io_start (EV_A_ &fs_w); |
2987 | } |
3031 | } |
2988 | } |
3032 | } |
… | |
… | |
2993 | int slot; |
3037 | int slot; |
2994 | |
3038 | |
2995 | if (fs_fd < 0) |
3039 | if (fs_fd < 0) |
2996 | return; |
3040 | return; |
2997 | |
3041 | |
|
|
3042 | ev_io_stop (EV_A_ &fs_w); |
2998 | close (fs_fd); |
3043 | close (fs_fd); |
2999 | fs_fd = inotify_init (); |
3044 | fs_fd = infy_newfd (); |
|
|
3045 | |
|
|
3046 | if (fs_fd >= 0) |
|
|
3047 | { |
|
|
3048 | fd_intern (fs_fd); |
|
|
3049 | ev_io_set (&fs_w, fs_fd, EV_READ); |
|
|
3050 | ev_io_start (EV_A_ &fs_w); |
|
|
3051 | } |
3000 | |
3052 | |
3001 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3053 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3002 | { |
3054 | { |
3003 | WL w_ = fs_hash [slot].head; |
3055 | WL w_ = fs_hash [slot].head; |
3004 | fs_hash [slot].head = 0; |
3056 | fs_hash [slot].head = 0; |