… | |
… | |
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 |
… | |
… | |
568 | } |
569 | } |
569 | |
570 | |
570 | static void * |
571 | static void * |
571 | ev_realloc_emul (void *ptr, long size) |
572 | ev_realloc_emul (void *ptr, long size) |
572 | { |
573 | { |
|
|
574 | #if __GLIBC__ |
|
|
575 | return realloc (ptr, size); |
|
|
576 | #else |
573 | /* some systems, notably openbsd and darwin, fail to properly |
577 | /* some systems, notably openbsd and darwin, fail to properly |
574 | * 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 |
575 | * the single unix specification, so work around them here. |
579 | * the single unix specification, so work around them here. |
576 | */ |
580 | */ |
|
|
581 | |
577 | if (size) |
582 | if (size) |
578 | return realloc (ptr, size); |
583 | return realloc (ptr, size); |
579 | |
584 | |
580 | free (ptr); |
585 | free (ptr); |
581 | return 0; |
586 | return 0; |
|
|
587 | #endif |
582 | } |
588 | } |
583 | |
589 | |
584 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
590 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
585 | |
591 | |
586 | void |
592 | void |
… | |
… | |
987 | ev_io_stop (EV_A_ w); |
993 | ev_io_stop (EV_A_ w); |
988 | 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); |
989 | } |
995 | } |
990 | } |
996 | } |
991 | |
997 | |
992 | /* check whether the given fd is atcually valid, for error recovery */ |
998 | /* check whether the given fd is actually valid, for error recovery */ |
993 | inline_size int |
999 | inline_size int |
994 | fd_valid (int fd) |
1000 | fd_valid (int fd) |
995 | { |
1001 | { |
996 | #ifdef _WIN32 |
1002 | #ifdef _WIN32 |
997 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1003 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1037 | { |
1043 | { |
1038 | anfds [fd].events = 0; |
1044 | anfds [fd].events = 0; |
1039 | anfds [fd].emask = 0; |
1045 | anfds [fd].emask = 0; |
1040 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1046 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1041 | } |
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 |
1042 | } |
1062 | } |
1043 | |
1063 | |
1044 | /*****************************************************************************/ |
1064 | /*****************************************************************************/ |
1045 | |
1065 | |
1046 | /* |
1066 | /* |
… | |
… | |
1200 | |
1220 | |
1201 | static ANSIG signals [EV_NSIG - 1]; |
1221 | static ANSIG signals [EV_NSIG - 1]; |
1202 | |
1222 | |
1203 | /*****************************************************************************/ |
1223 | /*****************************************************************************/ |
1204 | |
1224 | |
1205 | /* used to prepare libev internal fd's */ |
1225 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1206 | /* this is not fork-safe */ |
|
|
1207 | inline_speed void |
|
|
1208 | fd_intern (int fd) |
|
|
1209 | { |
|
|
1210 | #ifdef _WIN32 |
|
|
1211 | unsigned long arg = 1; |
|
|
1212 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1213 | #else |
|
|
1214 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1215 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1216 | #endif |
|
|
1217 | } |
|
|
1218 | |
1226 | |
1219 | static void noinline |
1227 | static void noinline |
1220 | evpipe_init (EV_P) |
1228 | evpipe_init (EV_P) |
1221 | { |
1229 | { |
1222 | if (!ev_is_active (&pipe_w)) |
1230 | if (!ev_is_active (&pipe_w)) |
1223 | { |
1231 | { |
1224 | #if EV_USE_EVENTFD |
1232 | # if EV_USE_EVENTFD |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1233 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1226 | if (evfd < 0 && errno == EINVAL) |
1234 | if (evfd < 0 && errno == EINVAL) |
1227 | evfd = eventfd (0, 0); |
1235 | evfd = eventfd (0, 0); |
1228 | |
1236 | |
1229 | if (evfd >= 0) |
1237 | if (evfd >= 0) |
… | |
… | |
1231 | evpipe [0] = -1; |
1239 | evpipe [0] = -1; |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1240 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1241 | ev_io_set (&pipe_w, evfd, EV_READ); |
1234 | } |
1242 | } |
1235 | else |
1243 | else |
1236 | #endif |
1244 | # endif |
1237 | { |
1245 | { |
1238 | while (pipe (evpipe)) |
1246 | while (pipe (evpipe)) |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1247 | ev_syserr ("(libev) error creating signal/async pipe"); |
1240 | |
1248 | |
1241 | fd_intern (evpipe [0]); |
1249 | fd_intern (evpipe [0]); |
… | |
… | |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1260 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1253 | { |
1261 | { |
1254 | if (!*flag) |
1262 | if (!*flag) |
1255 | { |
1263 | { |
1256 | 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; |
1257 | |
1266 | |
1258 | *flag = 1; |
1267 | *flag = 1; |
1259 | |
1268 | |
1260 | #if EV_USE_EVENTFD |
1269 | #if EV_USE_EVENTFD |
1261 | if (evfd >= 0) |
1270 | if (evfd >= 0) |
… | |
… | |
1263 | uint64_t counter = 1; |
1272 | uint64_t counter = 1; |
1264 | write (evfd, &counter, sizeof (uint64_t)); |
1273 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | } |
1274 | } |
1266 | else |
1275 | else |
1267 | #endif |
1276 | #endif |
1268 | write (evpipe [1], &old_errno, 1); |
1277 | write (evpipe [1], &dummy, 1); |
1269 | |
1278 | |
1270 | errno = old_errno; |
1279 | errno = old_errno; |
1271 | } |
1280 | } |
1272 | } |
1281 | } |
1273 | |
1282 | |
… | |
… | |
1374 | break; |
1383 | break; |
1375 | } |
1384 | } |
1376 | } |
1385 | } |
1377 | #endif |
1386 | #endif |
1378 | |
1387 | |
|
|
1388 | #endif |
|
|
1389 | |
1379 | /*****************************************************************************/ |
1390 | /*****************************************************************************/ |
1380 | |
1391 | |
|
|
1392 | #if EV_CHILD_ENABLE |
1381 | static WL childs [EV_PID_HASHSIZE]; |
1393 | static WL childs [EV_PID_HASHSIZE]; |
1382 | |
|
|
1383 | #ifndef _WIN32 |
|
|
1384 | |
1394 | |
1385 | static ev_signal childev; |
1395 | static ev_signal childev; |
1386 | |
1396 | |
1387 | #ifndef WIFCONTINUED |
1397 | #ifndef WIFCONTINUED |
1388 | # define WIFCONTINUED(status) 0 |
1398 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1657 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1667 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1658 | #endif |
1668 | #endif |
1659 | |
1669 | |
1660 | ev_prepare_init (&pending_w, pendingcb); |
1670 | ev_prepare_init (&pending_w, pendingcb); |
1661 | |
1671 | |
|
|
1672 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1662 | ev_init (&pipe_w, pipecb); |
1673 | ev_init (&pipe_w, pipecb); |
1663 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1674 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1675 | #endif |
1664 | } |
1676 | } |
1665 | } |
1677 | } |
1666 | |
1678 | |
1667 | /* free up a loop structure */ |
1679 | /* free up a loop structure */ |
1668 | static void noinline |
1680 | static void noinline |
… | |
… | |
1918 | |
1930 | |
1919 | assert (checkmax >= checkcnt); |
1931 | assert (checkmax >= checkcnt); |
1920 | array_verify (EV_A_ (W *)checks, checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
1921 | |
1933 | |
1922 | # if 0 |
1934 | # if 0 |
|
|
1935 | #if EV_CHILD_ENABLE |
1923 | 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) |
1924 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1937 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1938 | #endif |
1925 | # endif |
1939 | # endif |
1926 | #endif |
1940 | #endif |
1927 | } |
1941 | } |
1928 | #endif |
1942 | #endif |
1929 | |
1943 | |
… | |
… | |
1945 | |
1959 | |
1946 | loop_init (EV_A_ flags); |
1960 | loop_init (EV_A_ flags); |
1947 | |
1961 | |
1948 | if (ev_backend (EV_A)) |
1962 | if (ev_backend (EV_A)) |
1949 | { |
1963 | { |
1950 | #ifndef _WIN32 |
1964 | #if EV_CHILD_ENABLE |
1951 | ev_signal_init (&childev, childcb, SIGCHLD); |
1965 | ev_signal_init (&childev, childcb, SIGCHLD); |
1952 | ev_set_priority (&childev, EV_MAXPRI); |
1966 | ev_set_priority (&childev, EV_MAXPRI); |
1953 | ev_signal_start (EV_A_ &childev); |
1967 | ev_signal_start (EV_A_ &childev); |
1954 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1968 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1955 | #endif |
1969 | #endif |
… | |
… | |
1968 | EV_P = ev_default_loop_ptr; |
1982 | EV_P = ev_default_loop_ptr; |
1969 | #endif |
1983 | #endif |
1970 | |
1984 | |
1971 | ev_default_loop_ptr = 0; |
1985 | ev_default_loop_ptr = 0; |
1972 | |
1986 | |
1973 | #ifndef _WIN32 |
1987 | #if EV_CHILD_ENABLE |
1974 | ev_ref (EV_A); /* child watcher */ |
1988 | ev_ref (EV_A); /* child watcher */ |
1975 | ev_signal_stop (EV_A_ &childev); |
1989 | ev_signal_stop (EV_A_ &childev); |
1976 | #endif |
1990 | #endif |
1977 | |
1991 | |
1978 | loop_destroy (EV_A); |
1992 | loop_destroy (EV_A); |
… | |
… | |
2720 | |
2734 | |
2721 | #ifndef SA_RESTART |
2735 | #ifndef SA_RESTART |
2722 | # define SA_RESTART 0 |
2736 | # define SA_RESTART 0 |
2723 | #endif |
2737 | #endif |
2724 | |
2738 | |
|
|
2739 | #if EV_SIGNAL_ENABLE |
|
|
2740 | |
2725 | void noinline |
2741 | void noinline |
2726 | ev_signal_start (EV_P_ ev_signal *w) |
2742 | ev_signal_start (EV_P_ ev_signal *w) |
2727 | { |
2743 | { |
2728 | if (expect_false (ev_is_active (w))) |
2744 | if (expect_false (ev_is_active (w))) |
2729 | return; |
2745 | return; |
… | |
… | |
2835 | } |
2851 | } |
2836 | |
2852 | |
2837 | EV_FREQUENT_CHECK; |
2853 | EV_FREQUENT_CHECK; |
2838 | } |
2854 | } |
2839 | |
2855 | |
|
|
2856 | #endif |
|
|
2857 | |
|
|
2858 | #if EV_CHILD_ENABLE |
|
|
2859 | |
2840 | void |
2860 | void |
2841 | ev_child_start (EV_P_ ev_child *w) |
2861 | ev_child_start (EV_P_ ev_child *w) |
2842 | { |
2862 | { |
2843 | #if EV_MULTIPLICITY |
2863 | #if EV_MULTIPLICITY |
2844 | 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)); |
… | |
… | |
2866 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2886 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2867 | ev_stop (EV_A_ (W)w); |
2887 | ev_stop (EV_A_ (W)w); |
2868 | |
2888 | |
2869 | EV_FREQUENT_CHECK; |
2889 | EV_FREQUENT_CHECK; |
2870 | } |
2890 | } |
|
|
2891 | |
|
|
2892 | #endif |
2871 | |
2893 | |
2872 | #if EV_STAT_ENABLE |
2894 | #if EV_STAT_ENABLE |
2873 | |
2895 | |
2874 | # ifdef _WIN32 |
2896 | # ifdef _WIN32 |
2875 | # undef lstat |
2897 | # undef lstat |