… | |
… | |
154 | # define EV_USE_PORT 0 |
154 | # define EV_USE_PORT 0 |
155 | #endif |
155 | #endif |
156 | |
156 | |
157 | /**/ |
157 | /**/ |
158 | |
158 | |
159 | /* darwin simply cannot be helped */ |
|
|
160 | #ifdef __APPLE__ |
|
|
161 | # undef EV_USE_POLL |
|
|
162 | # undef EV_USE_KQUEUE |
|
|
163 | #endif |
|
|
164 | |
|
|
165 | #ifndef CLOCK_MONOTONIC |
159 | #ifndef CLOCK_MONOTONIC |
166 | # undef EV_USE_MONOTONIC |
160 | # undef EV_USE_MONOTONIC |
167 | # define EV_USE_MONOTONIC 0 |
161 | # define EV_USE_MONOTONIC 0 |
168 | #endif |
162 | #endif |
169 | |
163 | |
… | |
… | |
785 | || getgid () != getegid (); |
779 | || getgid () != getegid (); |
786 | #endif |
780 | #endif |
787 | } |
781 | } |
788 | |
782 | |
789 | unsigned int |
783 | unsigned int |
790 | ev_method (EV_P) |
784 | ev_supported_backends (void) |
791 | { |
785 | { |
792 | return method; |
786 | } |
|
|
787 | |
|
|
788 | unsigned int |
|
|
789 | ev_recommended_backends (void) |
|
|
790 | { |
|
|
791 | unsigned int flags; |
|
|
792 | |
|
|
793 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
|
|
794 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
|
|
795 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
796 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
|
|
797 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
|
|
798 | |
|
|
799 | return flags; |
|
|
800 | } |
|
|
801 | |
|
|
802 | unsigned int |
|
|
803 | ev_backend (EV_P) |
|
|
804 | { |
|
|
805 | unsigned int flags = ev_recommended_backends (); |
|
|
806 | |
|
|
807 | #ifndef __NetBSD__ |
|
|
808 | /* kqueue is borked on everything but netbsd apparently */ |
|
|
809 | /* it usually doesn't work correctly on anything but sockets and pipes */ |
|
|
810 | flags &= ~EVBACKEND_KQUEUE; |
|
|
811 | #endif |
|
|
812 | #ifdef __APPLE__ |
|
|
813 | // flags &= ~EVBACKEND_KQUEUE; for documentation |
|
|
814 | flags &= ~EVBACKEND_POLL; |
|
|
815 | #endif |
|
|
816 | |
|
|
817 | return flags; |
793 | } |
818 | } |
794 | |
819 | |
795 | static void |
820 | static void |
796 | loop_init (EV_P_ unsigned int flags) |
821 | loop_init (EV_P_ unsigned int flags) |
797 | { |
822 | { |
… | |
… | |
813 | if (!(flags & EVFLAG_NOENV) |
838 | if (!(flags & EVFLAG_NOENV) |
814 | && !enable_secure () |
839 | && !enable_secure () |
815 | && getenv ("LIBEV_FLAGS")) |
840 | && getenv ("LIBEV_FLAGS")) |
816 | flags = atoi (getenv ("LIBEV_FLAGS")); |
841 | flags = atoi (getenv ("LIBEV_FLAGS")); |
817 | |
842 | |
818 | if (!(flags & EVMETHOD_ALL)) |
843 | if (!(flags & 0x0000ffffUL)) |
819 | { |
844 | flags |= ev_recommended_backends (); |
820 | flags |= EVMETHOD_ALL; |
|
|
821 | #if EV_USE_KQUEUE && !defined (__NetBSD__) |
|
|
822 | /* kqueue is borked on everything but netbsd apparently */ |
|
|
823 | /* it usually doesn't work correctly on anything but sockets and pipes */ |
|
|
824 | flags &= ~EVMETHOD_KQUEUE; |
|
|
825 | #endif |
|
|
826 | } |
|
|
827 | |
845 | |
828 | method = 0; |
846 | method = 0; |
829 | #if EV_USE_PORT |
847 | #if EV_USE_PORT |
830 | if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); |
848 | if (!method && (flags & EVBACKEND_PORT )) method = port_init (EV_A_ flags); |
831 | #endif |
849 | #endif |
832 | #if EV_USE_KQUEUE |
850 | #if EV_USE_KQUEUE |
833 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
851 | if (!method && (flags & EVBACKEND_KQUEUE)) method = kqueue_init (EV_A_ flags); |
834 | #endif |
852 | #endif |
835 | #if EV_USE_EPOLL |
853 | #if EV_USE_EPOLL |
836 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
854 | if (!method && (flags & EVBACKEND_EPOLL )) method = epoll_init (EV_A_ flags); |
837 | #endif |
855 | #endif |
838 | #if EV_USE_POLL |
856 | #if EV_USE_POLL |
839 | if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); |
857 | if (!method && (flags & EVBACKEND_POLL )) method = poll_init (EV_A_ flags); |
840 | #endif |
858 | #endif |
841 | #if EV_USE_SELECT |
859 | #if EV_USE_SELECT |
842 | if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); |
860 | if (!method && (flags & EVBACKEND_SELECT)) method = select_init (EV_A_ flags); |
843 | #endif |
861 | #endif |
844 | |
862 | |
845 | ev_init (&sigev, sigcb); |
863 | ev_init (&sigev, sigcb); |
846 | ev_set_priority (&sigev, EV_MAXPRI); |
864 | ev_set_priority (&sigev, EV_MAXPRI); |
847 | } |
865 | } |
… | |
… | |
851 | loop_destroy (EV_P) |
869 | loop_destroy (EV_P) |
852 | { |
870 | { |
853 | int i; |
871 | int i; |
854 | |
872 | |
855 | #if EV_USE_PORT |
873 | #if EV_USE_PORT |
856 | if (method == EVMETHOD_PORT ) port_destroy (EV_A); |
874 | if (method == EVBACKEND_PORT ) port_destroy (EV_A); |
857 | #endif |
875 | #endif |
858 | #if EV_USE_KQUEUE |
876 | #if EV_USE_KQUEUE |
859 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
877 | if (method == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
860 | #endif |
878 | #endif |
861 | #if EV_USE_EPOLL |
879 | #if EV_USE_EPOLL |
862 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
880 | if (method == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
863 | #endif |
881 | #endif |
864 | #if EV_USE_POLL |
882 | #if EV_USE_POLL |
865 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
883 | if (method == EVBACKEND_POLL ) poll_destroy (EV_A); |
866 | #endif |
884 | #endif |
867 | #if EV_USE_SELECT |
885 | #if EV_USE_SELECT |
868 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
886 | if (method == EVBACKEND_SELECT) select_destroy (EV_A); |
869 | #endif |
887 | #endif |
870 | |
888 | |
871 | for (i = NUMPRI; i--; ) |
889 | for (i = NUMPRI; i--; ) |
872 | array_free (pending, [i]); |
890 | array_free (pending, [i]); |
873 | |
891 | |
… | |
… | |
886 | |
904 | |
887 | static void |
905 | static void |
888 | loop_fork (EV_P) |
906 | loop_fork (EV_P) |
889 | { |
907 | { |
890 | #if EV_USE_PORT |
908 | #if EV_USE_PORT |
891 | if (method == EVMETHOD_PORT ) port_fork (EV_A); |
909 | if (method == EVBACKEND_PORT ) port_fork (EV_A); |
892 | #endif |
910 | #endif |
893 | #if EV_USE_KQUEUE |
911 | #if EV_USE_KQUEUE |
894 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
912 | if (method == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
895 | #endif |
913 | #endif |
896 | #if EV_USE_EPOLL |
914 | #if EV_USE_EPOLL |
897 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
915 | if (method == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
898 | #endif |
916 | #endif |
899 | |
917 | |
900 | if (ev_is_active (&sigev)) |
918 | if (ev_is_active (&sigev)) |
901 | { |
919 | { |
902 | /* default loop */ |
920 | /* default loop */ |