… | |
… | |
154 | #ifndef _WIN32 |
154 | #ifndef _WIN32 |
155 | # include <sys/time.h> |
155 | # include <sys/time.h> |
156 | # include <sys/wait.h> |
156 | # include <sys/wait.h> |
157 | # include <unistd.h> |
157 | # include <unistd.h> |
158 | #else |
158 | #else |
|
|
159 | # include <io.h> |
159 | # define WIN32_LEAN_AND_MEAN |
160 | # define WIN32_LEAN_AND_MEAN |
160 | # include <windows.h> |
161 | # include <windows.h> |
161 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # endif |
164 | # endif |
… | |
… | |
564 | struct timeval tv; |
565 | struct timeval tv; |
565 | |
566 | |
566 | tv.tv_sec = (time_t)delay; |
567 | tv.tv_sec = (time_t)delay; |
567 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
568 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
568 | |
569 | |
|
|
570 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
|
|
571 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
|
|
572 | /* by older ones */ |
569 | select (0, 0, 0, 0, &tv); |
573 | select (0, 0, 0, 0, &tv); |
570 | #endif |
574 | #endif |
571 | } |
575 | } |
572 | } |
576 | } |
573 | |
577 | |
… | |
… | |
707 | events |= (unsigned char)w->events; |
711 | events |= (unsigned char)w->events; |
708 | |
712 | |
709 | #if EV_SELECT_IS_WINSOCKET |
713 | #if EV_SELECT_IS_WINSOCKET |
710 | if (events) |
714 | if (events) |
711 | { |
715 | { |
712 | unsigned long argp; |
716 | unsigned long arg; |
713 | #ifdef EV_FD_TO_WIN32_HANDLE |
717 | #ifdef EV_FD_TO_WIN32_HANDLE |
714 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
718 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
715 | #else |
719 | #else |
716 | anfd->handle = _get_osfhandle (fd); |
720 | anfd->handle = _get_osfhandle (fd); |
717 | #endif |
721 | #endif |
718 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
722 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
719 | } |
723 | } |
720 | #endif |
724 | #endif |
721 | |
725 | |
722 | { |
726 | { |
723 | unsigned char o_events = anfd->events; |
727 | unsigned char o_events = anfd->events; |
… | |
… | |
776 | { |
780 | { |
777 | int fd; |
781 | int fd; |
778 | |
782 | |
779 | for (fd = 0; fd < anfdmax; ++fd) |
783 | for (fd = 0; fd < anfdmax; ++fd) |
780 | if (anfds [fd].events) |
784 | if (anfds [fd].events) |
781 | if (!fd_valid (fd) == -1 && errno == EBADF) |
785 | if (!fd_valid (fd) && errno == EBADF) |
782 | fd_kill (EV_A_ fd); |
786 | fd_kill (EV_A_ fd); |
783 | } |
787 | } |
784 | |
788 | |
785 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
789 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
786 | static void noinline |
790 | static void noinline |
… | |
… | |
983 | |
987 | |
984 | void inline_speed |
988 | void inline_speed |
985 | fd_intern (int fd) |
989 | fd_intern (int fd) |
986 | { |
990 | { |
987 | #ifdef _WIN32 |
991 | #ifdef _WIN32 |
988 | int arg = 1; |
992 | unsigned long arg = 1; |
989 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
993 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
990 | #else |
994 | #else |
991 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
995 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
992 | fcntl (fd, F_SETFL, O_NONBLOCK); |
996 | fcntl (fd, F_SETFL, O_NONBLOCK); |
993 | #endif |
997 | #endif |
… | |
… | |
1507 | { |
1511 | { |
1508 | postfork = 1; /* must be in line with ev_default_fork */ |
1512 | postfork = 1; /* must be in line with ev_default_fork */ |
1509 | } |
1513 | } |
1510 | |
1514 | |
1511 | #if EV_VERIFY |
1515 | #if EV_VERIFY |
1512 | void noinline |
1516 | static void noinline |
1513 | verify_watcher (EV_P_ W w) |
1517 | verify_watcher (EV_P_ W w) |
1514 | { |
1518 | { |
1515 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1519 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
1516 | |
1520 | |
1517 | if (w->pending) |
1521 | if (w->pending) |
… | |
… | |
2567 | } |
2571 | } |
2568 | |
2572 | |
2569 | } |
2573 | } |
2570 | } |
2574 | } |
2571 | |
2575 | |
|
|
2576 | #endif |
|
|
2577 | |
|
|
2578 | #ifdef _WIN32 |
|
|
2579 | # define EV_LSTAT(p,b) _stati64 (p, b) |
|
|
2580 | #else |
|
|
2581 | # define EV_LSTAT(p,b) lstat (p, b) |
2572 | #endif |
2582 | #endif |
2573 | |
2583 | |
2574 | void |
2584 | void |
2575 | ev_stat_stat (EV_P_ ev_stat *w) |
2585 | ev_stat_stat (EV_P_ ev_stat *w) |
2576 | { |
2586 | { |
… | |
… | |
2972 | once_cb (EV_P_ struct ev_once *once, int revents) |
2982 | once_cb (EV_P_ struct ev_once *once, int revents) |
2973 | { |
2983 | { |
2974 | void (*cb)(int revents, void *arg) = once->cb; |
2984 | void (*cb)(int revents, void *arg) = once->cb; |
2975 | void *arg = once->arg; |
2985 | void *arg = once->arg; |
2976 | |
2986 | |
2977 | ev_io_stop (EV_A_ &once->io); |
2987 | ev_io_stop (EV_A_ &once->io); |
2978 | ev_timer_stop (EV_A_ &once->to); |
2988 | ev_timer_stop (EV_A_ &once->to); |
2979 | ev_free (once); |
2989 | ev_free (once); |
2980 | |
2990 | |
2981 | cb (revents, arg); |
2991 | cb (revents, arg); |
2982 | } |
2992 | } |