… | |
… | |
207 | #elif defined (MAXSIG) |
207 | #elif defined (MAXSIG) |
208 | # define EV_NSIG (MAXSIG+1) |
208 | # define EV_NSIG (MAXSIG+1) |
209 | #elif defined (MAX_SIG) |
209 | #elif defined (MAX_SIG) |
210 | # define EV_NSIG (MAX_SIG+1) |
210 | # define EV_NSIG (MAX_SIG+1) |
211 | #elif defined (SIGARRAYSIZE) |
211 | #elif defined (SIGARRAYSIZE) |
212 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
212 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
213 | #elif defined (_sys_nsig) |
213 | #elif defined (_sys_nsig) |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
215 | #else |
215 | #else |
216 | # error "unable to find value for NSIG, please report" |
216 | # error "unable to find value for NSIG, please report" |
217 | /* to make it compile regardless, just remove the above line */ |
217 | /* to make it compile regardless, just remove the above line, */ |
|
|
218 | /* but consider reporting it, too! :) */ |
218 | # define EV_NSIG 65 |
219 | # define EV_NSIG 65 |
219 | #endif |
220 | #endif |
220 | |
221 | |
221 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | # if __linux && __GLIBC__ >= 2 |
223 | # if __linux && __GLIBC__ >= 2 |
… | |
… | |
572 | { |
573 | { |
573 | #if __GLIBC__ |
574 | #if __GLIBC__ |
574 | return realloc (ptr, size); |
575 | return realloc (ptr, size); |
575 | #else |
576 | #else |
576 | /* some systems, notably openbsd and darwin, fail to properly |
577 | /* some systems, notably openbsd and darwin, fail to properly |
577 | * implement realloc (x, 0) (as required by both ansi c-98 and |
578 | * implement realloc (x, 0) (as required by both ansi c-89 and |
578 | * the single unix specification, so work around them here. |
579 | * the single unix specification, so work around them here. |
579 | */ |
580 | */ |
580 | |
581 | |
581 | if (size) |
582 | if (size) |
582 | return realloc (ptr, size); |
583 | return realloc (ptr, size); |
… | |
… | |
992 | ev_io_stop (EV_A_ w); |
993 | ev_io_stop (EV_A_ w); |
993 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
994 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
994 | } |
995 | } |
995 | } |
996 | } |
996 | |
997 | |
997 | /* check whether the given fd is atcually valid, for error recovery */ |
998 | /* check whether the given fd is actually valid, for error recovery */ |
998 | inline_size int |
999 | inline_size int |
999 | fd_valid (int fd) |
1000 | fd_valid (int fd) |
1000 | { |
1001 | { |
1001 | #ifdef _WIN32 |
1002 | #ifdef _WIN32 |
1002 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1003 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1042 | { |
1043 | { |
1043 | anfds [fd].events = 0; |
1044 | anfds [fd].events = 0; |
1044 | anfds [fd].emask = 0; |
1045 | anfds [fd].emask = 0; |
1045 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1046 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1046 | } |
1047 | } |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | /* used to prepare libev internal fd's */ |
|
|
1051 | /* this is not fork-safe */ |
|
|
1052 | inline_speed void |
|
|
1053 | fd_intern (int fd) |
|
|
1054 | { |
|
|
1055 | #ifdef _WIN32 |
|
|
1056 | unsigned long arg = 1; |
|
|
1057 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1058 | #else |
|
|
1059 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1060 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1061 | #endif |
1047 | } |
1062 | } |
1048 | |
1063 | |
1049 | /*****************************************************************************/ |
1064 | /*****************************************************************************/ |
1050 | |
1065 | |
1051 | /* |
1066 | /* |
… | |
… | |
1205 | |
1220 | |
1206 | static ANSIG signals [EV_NSIG - 1]; |
1221 | static ANSIG signals [EV_NSIG - 1]; |
1207 | |
1222 | |
1208 | /*****************************************************************************/ |
1223 | /*****************************************************************************/ |
1209 | |
1224 | |
1210 | /* used to prepare libev internal fd's */ |
1225 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1211 | /* this is not fork-safe */ |
|
|
1212 | inline_speed void |
|
|
1213 | fd_intern (int fd) |
|
|
1214 | { |
|
|
1215 | #ifdef _WIN32 |
|
|
1216 | unsigned long arg = 1; |
|
|
1217 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1218 | #else |
|
|
1219 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1220 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1221 | #endif |
|
|
1222 | } |
|
|
1223 | |
1226 | |
1224 | static void noinline |
1227 | static void noinline |
1225 | evpipe_init (EV_P) |
1228 | evpipe_init (EV_P) |
1226 | { |
1229 | { |
1227 | if (!ev_is_active (&pipe_w)) |
1230 | if (!ev_is_active (&pipe_w)) |
1228 | { |
1231 | { |
1229 | #if EV_USE_EVENTFD |
1232 | # if EV_USE_EVENTFD |
1230 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1233 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1231 | if (evfd < 0 && errno == EINVAL) |
1234 | if (evfd < 0 && errno == EINVAL) |
1232 | evfd = eventfd (0, 0); |
1235 | evfd = eventfd (0, 0); |
1233 | |
1236 | |
1234 | if (evfd >= 0) |
1237 | if (evfd >= 0) |
… | |
… | |
1236 | evpipe [0] = -1; |
1239 | evpipe [0] = -1; |
1237 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1240 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1238 | ev_io_set (&pipe_w, evfd, EV_READ); |
1241 | ev_io_set (&pipe_w, evfd, EV_READ); |
1239 | } |
1242 | } |
1240 | else |
1243 | else |
1241 | #endif |
1244 | # endif |
1242 | { |
1245 | { |
1243 | while (pipe (evpipe)) |
1246 | while (pipe (evpipe)) |
1244 | ev_syserr ("(libev) error creating signal/async pipe"); |
1247 | ev_syserr ("(libev) error creating signal/async pipe"); |
1245 | |
1248 | |
1246 | fd_intern (evpipe [0]); |
1249 | fd_intern (evpipe [0]); |
… | |
… | |
1257 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1260 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1258 | { |
1261 | { |
1259 | if (!*flag) |
1262 | if (!*flag) |
1260 | { |
1263 | { |
1261 | int old_errno = errno; /* save errno because write might clobber it */ |
1264 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1265 | char dummy; |
1262 | |
1266 | |
1263 | *flag = 1; |
1267 | *flag = 1; |
1264 | |
1268 | |
1265 | #if EV_USE_EVENTFD |
1269 | #if EV_USE_EVENTFD |
1266 | if (evfd >= 0) |
1270 | if (evfd >= 0) |
… | |
… | |
1268 | uint64_t counter = 1; |
1272 | uint64_t counter = 1; |
1269 | write (evfd, &counter, sizeof (uint64_t)); |
1273 | write (evfd, &counter, sizeof (uint64_t)); |
1270 | } |
1274 | } |
1271 | else |
1275 | else |
1272 | #endif |
1276 | #endif |
1273 | write (evpipe [1], &old_errno, 1); |
1277 | write (evpipe [1], &dummy, 1); |
1274 | |
1278 | |
1275 | errno = old_errno; |
1279 | errno = old_errno; |
1276 | } |
1280 | } |
1277 | } |
1281 | } |
1278 | |
1282 | |
… | |
… | |
1379 | break; |
1383 | break; |
1380 | } |
1384 | } |
1381 | } |
1385 | } |
1382 | #endif |
1386 | #endif |
1383 | |
1387 | |
|
|
1388 | #endif |
|
|
1389 | |
1384 | /*****************************************************************************/ |
1390 | /*****************************************************************************/ |
1385 | |
1391 | |
|
|
1392 | #if EV_CHILD_ENABLE |
1386 | static WL childs [EV_PID_HASHSIZE]; |
1393 | static WL childs [EV_PID_HASHSIZE]; |
1387 | |
|
|
1388 | #ifndef _WIN32 |
|
|
1389 | |
1394 | |
1390 | static ev_signal childev; |
1395 | static ev_signal childev; |
1391 | |
1396 | |
1392 | #ifndef WIFCONTINUED |
1397 | #ifndef WIFCONTINUED |
1393 | # define WIFCONTINUED(status) 0 |
1398 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1662 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1667 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1663 | #endif |
1668 | #endif |
1664 | |
1669 | |
1665 | ev_prepare_init (&pending_w, pendingcb); |
1670 | ev_prepare_init (&pending_w, pendingcb); |
1666 | |
1671 | |
|
|
1672 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1667 | ev_init (&pipe_w, pipecb); |
1673 | ev_init (&pipe_w, pipecb); |
1668 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1674 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1675 | #endif |
1669 | } |
1676 | } |
1670 | } |
1677 | } |
1671 | |
1678 | |
1672 | /* free up a loop structure */ |
1679 | /* free up a loop structure */ |
1673 | static void noinline |
1680 | static void noinline |
… | |
… | |
1923 | |
1930 | |
1924 | assert (checkmax >= checkcnt); |
1931 | assert (checkmax >= checkcnt); |
1925 | array_verify (EV_A_ (W *)checks, checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
1926 | |
1933 | |
1927 | # if 0 |
1934 | # if 0 |
|
|
1935 | #if EV_CHILD_ENABLE |
1928 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1936 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1929 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1937 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1938 | #endif |
1930 | # endif |
1939 | # endif |
1931 | #endif |
1940 | #endif |
1932 | } |
1941 | } |
1933 | #endif |
1942 | #endif |
1934 | |
1943 | |
… | |
… | |
1950 | |
1959 | |
1951 | loop_init (EV_A_ flags); |
1960 | loop_init (EV_A_ flags); |
1952 | |
1961 | |
1953 | if (ev_backend (EV_A)) |
1962 | if (ev_backend (EV_A)) |
1954 | { |
1963 | { |
1955 | #ifndef _WIN32 |
1964 | #if EV_CHILD_ENABLE |
1956 | ev_signal_init (&childev, childcb, SIGCHLD); |
1965 | ev_signal_init (&childev, childcb, SIGCHLD); |
1957 | ev_set_priority (&childev, EV_MAXPRI); |
1966 | ev_set_priority (&childev, EV_MAXPRI); |
1958 | ev_signal_start (EV_A_ &childev); |
1967 | ev_signal_start (EV_A_ &childev); |
1959 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1968 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1960 | #endif |
1969 | #endif |
… | |
… | |
1973 | EV_P = ev_default_loop_ptr; |
1982 | EV_P = ev_default_loop_ptr; |
1974 | #endif |
1983 | #endif |
1975 | |
1984 | |
1976 | ev_default_loop_ptr = 0; |
1985 | ev_default_loop_ptr = 0; |
1977 | |
1986 | |
1978 | #ifndef _WIN32 |
1987 | #if EV_CHILD_ENABLE |
1979 | ev_ref (EV_A); /* child watcher */ |
1988 | ev_ref (EV_A); /* child watcher */ |
1980 | ev_signal_stop (EV_A_ &childev); |
1989 | ev_signal_stop (EV_A_ &childev); |
1981 | #endif |
1990 | #endif |
1982 | |
1991 | |
1983 | loop_destroy (EV_A); |
1992 | loop_destroy (EV_A); |
… | |
… | |
2725 | |
2734 | |
2726 | #ifndef SA_RESTART |
2735 | #ifndef SA_RESTART |
2727 | # define SA_RESTART 0 |
2736 | # define SA_RESTART 0 |
2728 | #endif |
2737 | #endif |
2729 | |
2738 | |
|
|
2739 | #if EV_SIGNAL_ENABLE |
|
|
2740 | |
2730 | void noinline |
2741 | void noinline |
2731 | ev_signal_start (EV_P_ ev_signal *w) |
2742 | ev_signal_start (EV_P_ ev_signal *w) |
2732 | { |
2743 | { |
2733 | if (expect_false (ev_is_active (w))) |
2744 | if (expect_false (ev_is_active (w))) |
2734 | return; |
2745 | return; |
… | |
… | |
2840 | } |
2851 | } |
2841 | |
2852 | |
2842 | EV_FREQUENT_CHECK; |
2853 | EV_FREQUENT_CHECK; |
2843 | } |
2854 | } |
2844 | |
2855 | |
|
|
2856 | #endif |
|
|
2857 | |
|
|
2858 | #if EV_CHILD_ENABLE |
|
|
2859 | |
2845 | void |
2860 | void |
2846 | ev_child_start (EV_P_ ev_child *w) |
2861 | ev_child_start (EV_P_ ev_child *w) |
2847 | { |
2862 | { |
2848 | #if EV_MULTIPLICITY |
2863 | #if EV_MULTIPLICITY |
2849 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2864 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2871 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2886 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2872 | ev_stop (EV_A_ (W)w); |
2887 | ev_stop (EV_A_ (W)w); |
2873 | |
2888 | |
2874 | EV_FREQUENT_CHECK; |
2889 | EV_FREQUENT_CHECK; |
2875 | } |
2890 | } |
|
|
2891 | |
|
|
2892 | #endif |
2876 | |
2893 | |
2877 | #if EV_STAT_ENABLE |
2894 | #if EV_STAT_ENABLE |
2878 | |
2895 | |
2879 | # ifdef _WIN32 |
2896 | # ifdef _WIN32 |
2880 | # undef lstat |
2897 | # undef lstat |