… | |
… | |
35 | * and other provisions required by the GPL. If you do not delete the |
35 | * and other provisions required by the GPL. If you do not delete the |
36 | * provisions above, a recipient may use your version of this file under |
36 | * provisions above, a recipient may use your version of this file under |
37 | * either the BSD or the GPL. |
37 | * either the BSD or the GPL. |
38 | */ |
38 | */ |
39 | |
39 | |
40 | #ifdef __cplusplus |
|
|
41 | extern "C" { |
|
|
42 | #endif |
|
|
43 | |
|
|
44 | /* this big block deduces configuration from config.h */ |
40 | /* this big block deduces configuration from config.h */ |
45 | #ifndef EV_STANDALONE |
41 | #ifndef EV_STANDALONE |
46 | # ifdef EV_CONFIG_H |
42 | # ifdef EV_CONFIG_H |
47 | # include EV_CONFIG_H |
43 | # include EV_CONFIG_H |
48 | # else |
44 | # else |
… | |
… | |
182 | # include EV_H |
178 | # include EV_H |
183 | #else |
179 | #else |
184 | # include "ev.h" |
180 | # include "ev.h" |
185 | #endif |
181 | #endif |
186 | |
182 | |
|
|
183 | EV_CPP(extern "C" {) |
|
|
184 | |
187 | #ifndef _WIN32 |
185 | #ifndef _WIN32 |
188 | # include <sys/time.h> |
186 | # include <sys/time.h> |
189 | # include <sys/wait.h> |
187 | # include <sys/wait.h> |
190 | # include <unistd.h> |
188 | # include <unistd.h> |
191 | #else |
189 | #else |
… | |
… | |
384 | # include <sys/select.h> |
382 | # include <sys/select.h> |
385 | # endif |
383 | # endif |
386 | #endif |
384 | #endif |
387 | |
385 | |
388 | #if EV_USE_INOTIFY |
386 | #if EV_USE_INOTIFY |
389 | # include <sys/utsname.h> |
|
|
390 | # include <sys/statfs.h> |
387 | # include <sys/statfs.h> |
391 | # include <sys/inotify.h> |
388 | # include <sys/inotify.h> |
392 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
389 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
393 | # ifndef IN_DONT_FOLLOW |
390 | # ifndef IN_DONT_FOLLOW |
394 | # undef EV_USE_INOTIFY |
391 | # undef EV_USE_INOTIFY |
… | |
… | |
411 | # define EFD_CLOEXEC O_CLOEXEC |
408 | # define EFD_CLOEXEC O_CLOEXEC |
412 | # else |
409 | # else |
413 | # define EFD_CLOEXEC 02000000 |
410 | # define EFD_CLOEXEC 02000000 |
414 | # endif |
411 | # endif |
415 | # endif |
412 | # endif |
416 | # ifdef __cplusplus |
|
|
417 | extern "C" { |
|
|
418 | # endif |
|
|
419 | int (eventfd) (unsigned int initval, int flags); |
413 | EV_CPP(extern "C") int (eventfd) (unsigned int initval, int flags); |
420 | # ifdef __cplusplus |
|
|
421 | } |
|
|
422 | # endif |
|
|
423 | #endif |
414 | #endif |
424 | |
415 | |
425 | #if EV_USE_SIGNALFD |
416 | #if EV_USE_SIGNALFD |
426 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
417 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
427 | # include <stdint.h> |
418 | # include <stdint.h> |
… | |
… | |
433 | # define SFD_CLOEXEC O_CLOEXEC |
424 | # define SFD_CLOEXEC O_CLOEXEC |
434 | # else |
425 | # else |
435 | # define SFD_CLOEXEC 02000000 |
426 | # define SFD_CLOEXEC 02000000 |
436 | # endif |
427 | # endif |
437 | # endif |
428 | # endif |
438 | # ifdef __cplusplus |
|
|
439 | extern "C" { |
|
|
440 | # endif |
|
|
441 | int signalfd (int fd, const sigset_t *mask, int flags); |
429 | EV_CPP (extern "C") int signalfd (int fd, const sigset_t *mask, int flags); |
442 | |
430 | |
443 | struct signalfd_siginfo |
431 | struct signalfd_siginfo |
444 | { |
432 | { |
445 | uint32_t ssi_signo; |
433 | uint32_t ssi_signo; |
446 | char pad[128 - sizeof (uint32_t)]; |
434 | char pad[128 - sizeof (uint32_t)]; |
447 | }; |
435 | }; |
448 | # ifdef __cplusplus |
|
|
449 | } |
|
|
450 | # endif |
|
|
451 | #endif |
436 | #endif |
452 | |
437 | |
453 | /**/ |
438 | /**/ |
454 | |
439 | |
455 | #if EV_VERIFY >= 3 |
440 | #if EV_VERIFY >= 3 |
… | |
… | |
537 | # include "ev_win32.c" |
522 | # include "ev_win32.c" |
538 | #endif |
523 | #endif |
539 | |
524 | |
540 | /*****************************************************************************/ |
525 | /*****************************************************************************/ |
541 | |
526 | |
|
|
527 | #ifdef __linux |
|
|
528 | # include <sys/utsname.h> |
|
|
529 | #endif |
|
|
530 | |
|
|
531 | static unsigned int noinline |
|
|
532 | ev_linux_version (void) |
|
|
533 | { |
|
|
534 | #ifdef __linux |
|
|
535 | struct utsname buf; |
|
|
536 | unsigned int v; |
|
|
537 | int i; |
|
|
538 | char *p = buf.release; |
|
|
539 | |
|
|
540 | if (uname (&buf)) |
|
|
541 | return 0; |
|
|
542 | |
|
|
543 | for (i = 3+1; --i; ) |
|
|
544 | { |
|
|
545 | unsigned int c = 0; |
|
|
546 | |
|
|
547 | for (;;) |
|
|
548 | { |
|
|
549 | if (*p >= '0' && *p <= '9') |
|
|
550 | c = c * 10 + *p++ - '0'; |
|
|
551 | else |
|
|
552 | { |
|
|
553 | p += *p == '.'; |
|
|
554 | break; |
|
|
555 | } |
|
|
556 | } |
|
|
557 | |
|
|
558 | v = (v << 8) | c; |
|
|
559 | } |
|
|
560 | |
|
|
561 | return v; |
|
|
562 | #else |
|
|
563 | return 0; |
|
|
564 | #endif |
|
|
565 | } |
|
|
566 | |
|
|
567 | /*****************************************************************************/ |
|
|
568 | |
542 | #if EV_AVOID_STDIO |
569 | #if EV_AVOID_STDIO |
543 | static void noinline |
570 | static void noinline |
544 | ev_printerr (const char *msg) |
571 | ev_printerr (const char *msg) |
545 | { |
572 | { |
546 | write (STDERR_FILENO, msg, strlen (msg)); |
573 | write (STDERR_FILENO, msg, strlen (msg)); |
… | |
… | |
641 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
668 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
642 | unsigned char unused; |
669 | unsigned char unused; |
643 | #if EV_USE_EPOLL |
670 | #if EV_USE_EPOLL |
644 | unsigned int egen; /* generation counter to counter epoll bugs */ |
671 | unsigned int egen; /* generation counter to counter epoll bugs */ |
645 | #endif |
672 | #endif |
646 | #if EV_SELECT_IS_WINSOCKET |
673 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
647 | SOCKET handle; |
674 | SOCKET handle; |
|
|
675 | #endif |
|
|
676 | #if EV_USE_IOCP |
|
|
677 | OVERLAPPED or, ow; |
648 | #endif |
678 | #endif |
649 | } ANFD; |
679 | } ANFD; |
650 | |
680 | |
651 | /* stores the pending event set for a given watcher */ |
681 | /* stores the pending event set for a given watcher */ |
652 | typedef struct |
682 | typedef struct |
… | |
… | |
948 | unsigned char o_events = anfd->events; |
978 | unsigned char o_events = anfd->events; |
949 | unsigned char o_reify = anfd->reify; |
979 | unsigned char o_reify = anfd->reify; |
950 | |
980 | |
951 | anfd->reify = 0; |
981 | anfd->reify = 0; |
952 | |
982 | |
953 | #if EV_SELECT_IS_WINSOCKET |
983 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
954 | if (o_reify & EV__IOFDSET) |
984 | if (o_reify & EV__IOFDSET) |
955 | { |
985 | { |
956 | unsigned long arg; |
986 | unsigned long arg; |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
987 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
958 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
988 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
|
|
989 | printf ("oi %d %x\n", fd, anfd->handle);//D |
959 | } |
990 | } |
960 | #endif |
991 | #endif |
961 | |
992 | |
962 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
993 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
963 | { |
994 | { |
… | |
… | |
1462 | |
1493 | |
1463 | #endif |
1494 | #endif |
1464 | |
1495 | |
1465 | /*****************************************************************************/ |
1496 | /*****************************************************************************/ |
1466 | |
1497 | |
|
|
1498 | #if EV_USE_IOCP |
|
|
1499 | # include "ev_iocp.c" |
|
|
1500 | #endif |
1467 | #if EV_USE_PORT |
1501 | #if EV_USE_PORT |
1468 | # include "ev_port.c" |
1502 | # include "ev_port.c" |
1469 | #endif |
1503 | #endif |
1470 | #if EV_USE_KQUEUE |
1504 | #if EV_USE_KQUEUE |
1471 | # include "ev_kqueue.c" |
1505 | # include "ev_kqueue.c" |
… | |
… | |
1544 | ev_embeddable_backends (void) |
1578 | ev_embeddable_backends (void) |
1545 | { |
1579 | { |
1546 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1580 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1547 | |
1581 | |
1548 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1582 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1549 | /* please fix it and tell me how to detect the fix */ |
1583 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
1550 | flags &= ~EVBACKEND_EPOLL; |
1584 | flags &= ~EVBACKEND_EPOLL; |
1551 | |
1585 | |
1552 | return flags; |
1586 | return flags; |
1553 | } |
1587 | } |
1554 | |
1588 | |
1555 | unsigned int |
1589 | unsigned int |
… | |
… | |
1668 | #endif |
1702 | #endif |
1669 | |
1703 | |
1670 | if (!(flags & 0x0000ffffU)) |
1704 | if (!(flags & 0x0000ffffU)) |
1671 | flags |= ev_recommended_backends (); |
1705 | flags |= ev_recommended_backends (); |
1672 | |
1706 | |
|
|
1707 | #if EV_USE_IOCP |
|
|
1708 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
|
|
1709 | #endif |
1673 | #if EV_USE_PORT |
1710 | #if EV_USE_PORT |
1674 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1711 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1675 | #endif |
1712 | #endif |
1676 | #if EV_USE_KQUEUE |
1713 | #if EV_USE_KQUEUE |
1677 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
1714 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
… | |
… | |
1729 | #endif |
1766 | #endif |
1730 | |
1767 | |
1731 | if (backend_fd >= 0) |
1768 | if (backend_fd >= 0) |
1732 | close (backend_fd); |
1769 | close (backend_fd); |
1733 | |
1770 | |
|
|
1771 | #if EV_USE_IOCP |
|
|
1772 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
|
|
1773 | #endif |
1734 | #if EV_USE_PORT |
1774 | #if EV_USE_PORT |
1735 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
1775 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
1736 | #endif |
1776 | #endif |
1737 | #if EV_USE_KQUEUE |
1777 | #if EV_USE_KQUEUE |
1738 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
1778 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
… | |
… | |
1966 | } |
2006 | } |
1967 | #endif |
2007 | #endif |
1968 | |
2008 | |
1969 | #if EV_MULTIPLICITY |
2009 | #if EV_MULTIPLICITY |
1970 | struct ev_loop * |
2010 | struct ev_loop * |
1971 | ev_default_loop_init (unsigned int flags) |
|
|
1972 | #else |
2011 | #else |
1973 | int |
2012 | int |
|
|
2013 | #endif |
1974 | ev_default_loop (unsigned int flags) |
2014 | ev_default_loop (unsigned int flags) |
1975 | #endif |
|
|
1976 | { |
2015 | { |
1977 | if (!ev_default_loop_ptr) |
2016 | if (!ev_default_loop_ptr) |
1978 | { |
2017 | { |
1979 | #if EV_MULTIPLICITY |
2018 | #if EV_MULTIPLICITY |
1980 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2019 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3062 | { |
3101 | { |
3063 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
3102 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
3064 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3103 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3065 | ofs += sizeof (struct inotify_event) + ev->len; |
3104 | ofs += sizeof (struct inotify_event) + ev->len; |
3066 | } |
3105 | } |
3067 | } |
|
|
3068 | |
|
|
3069 | inline_size unsigned int |
|
|
3070 | ev_linux_version (void) |
|
|
3071 | { |
|
|
3072 | struct utsname buf; |
|
|
3073 | unsigned int v; |
|
|
3074 | int i; |
|
|
3075 | char *p = buf.release; |
|
|
3076 | |
|
|
3077 | if (uname (&buf)) |
|
|
3078 | return 0; |
|
|
3079 | |
|
|
3080 | for (i = 3+1; --i; ) |
|
|
3081 | { |
|
|
3082 | unsigned int c = 0; |
|
|
3083 | |
|
|
3084 | for (;;) |
|
|
3085 | { |
|
|
3086 | if (*p >= '0' && *p <= '9') |
|
|
3087 | c = c * 10 + *p++ - '0'; |
|
|
3088 | else |
|
|
3089 | { |
|
|
3090 | p += *p == '.'; |
|
|
3091 | break; |
|
|
3092 | } |
|
|
3093 | } |
|
|
3094 | |
|
|
3095 | v = (v << 8) | c; |
|
|
3096 | } |
|
|
3097 | |
|
|
3098 | return v; |
|
|
3099 | } |
3106 | } |
3100 | |
3107 | |
3101 | inline_size void |
3108 | inline_size void |
3102 | ev_check_2625 (EV_P) |
3109 | ev_check_2625 (EV_P) |
3103 | { |
3110 | { |
… | |
… | |
3807 | |
3814 | |
3808 | #if EV_MULTIPLICITY |
3815 | #if EV_MULTIPLICITY |
3809 | #include "ev_wrap.h" |
3816 | #include "ev_wrap.h" |
3810 | #endif |
3817 | #endif |
3811 | |
3818 | |
3812 | #ifdef __cplusplus |
3819 | EV_CPP(}) |
3813 | } |
|
|
3814 | #endif |
|
|
3815 | |
3820 | |