1 #ifndef INCLUDED_FDEVENT_IMPL_H 2 #define INCLUDED_FDEVENT_IMPL_H 3 #include "first.h" 4 5 /* select event-system */ 6 7 #if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H) 8 # define FDEVENT_USE_LINUX_EPOLL 9 struct epoll_event; /* declaration */ 10 #endif 11 12 /* MacOS 10.3.x has poll.h under /usr/include/, all other unixes 13 * under /usr/include/sys/ */ 14 #if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H)) 15 # define FDEVENT_USE_POLL 16 struct pollfd; /* declaration */ 17 #endif 18 19 #if defined HAVE_SELECT 20 # ifdef __WIN32 21 # include <winsock2.h> 22 # endif 23 # define FDEVENT_USE_SELECT 24 # ifdef HAVE_SYS_SELECT_H 25 # include <sys/select.h> 26 # endif 27 #endif 28 29 #if defined HAVE_SYS_DEVPOLL_H && defined(__sun) 30 # define FDEVENT_USE_SOLARIS_DEVPOLL 31 struct pollfd; /* declaration */ 32 #endif 33 34 #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun) 35 # define FDEVENT_USE_SOLARIS_PORT 36 # include <port.h> 37 #endif 38 39 #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE 40 # define FDEVENT_USE_FREEBSD_KQUEUE 41 struct kevent; /* declaration */ 42 #endif 43 44 #if defined HAVE_LIBEV 45 # define FDEVENT_USE_LIBEV 46 struct ev_loop; /* declaration */ 47 #endif 48 49 #include "base_decls.h" 50 #include "fdevent.h" /* (*fdevent_handler) */ 51 52 typedef enum { 53 FDEVENT_HANDLER_UNSET, 54 FDEVENT_HANDLER_SELECT, 55 FDEVENT_HANDLER_POLL, 56 FDEVENT_HANDLER_LINUX_SYSEPOLL, 57 FDEVENT_HANDLER_SOLARIS_DEVPOLL, 58 FDEVENT_HANDLER_SOLARIS_PORT, 59 FDEVENT_HANDLER_FREEBSD_KQUEUE, 60 FDEVENT_HANDLER_LIBEV 61 } fdevent_handler_t; 62 63 /** 64 * array of unused fd's 65 * 66 */ 67 68 #ifdef FDEVENT_USE_POLL 69 typedef struct { 70 int *ptr; 71 72 uint32_t used; 73 uint32_t size; 74 } buffer_int; 75 #endif 76 77 struct fdevents { 78 fdnode **fdarray; 79 fdnode *pendclose; 80 81 int (*event_set)(struct fdevents *ev, fdnode *fdn, int events); 82 int (*event_del)(struct fdevents *ev, fdnode *fdn); 83 int (*poll)(struct fdevents *ev, int timeout_ms); 84 85 log_error_st *errh; 86 int *cur_fds; 87 uint32_t maxfds; 88 #ifdef FDEVENT_USE_LINUX_EPOLL 89 int epoll_fd; 90 struct epoll_event *epoll_events; 91 #endif 92 #ifdef FDEVENT_USE_SOLARIS_DEVPOLL 93 int devpoll_fd; 94 struct pollfd *devpollfds; 95 #endif 96 #ifdef FDEVENT_USE_SOLARIS_PORT 97 int port_fd; 98 port_event_t *port_events; 99 #endif 100 #ifdef FDEVENT_USE_FREEBSD_KQUEUE 101 int kq_fd; 102 struct kevent *kq_results; 103 #endif 104 #ifdef FDEVENT_USE_LIBEV 105 struct ev_loop *libev_loop; 106 #endif 107 #ifdef FDEVENT_USE_POLL 108 struct pollfd *pollfds; 109 110 uint32_t size; 111 uint32_t used; 112 113 buffer_int unused; 114 #endif 115 #ifdef FDEVENT_USE_SELECT 116 fd_set select_read; 117 fd_set select_write; 118 fd_set select_error; 119 120 fd_set select_set_read; 121 fd_set select_set_write; 122 fd_set select_set_error; 123 124 int select_max_fd; 125 #endif 126 127 int (*reset)(struct fdevents *ev); 128 void (*free)(struct fdevents *ev); 129 const char *event_handler; 130 fdevent_handler_t type; 131 }; 132 133 __attribute_cold__ 134 int fdevent_select_init(struct fdevents *ev); 135 __attribute_cold__ 136 int fdevent_poll_init(struct fdevents *ev); 137 __attribute_cold__ 138 int fdevent_linux_sysepoll_init(struct fdevents *ev); 139 __attribute_cold__ 140 int fdevent_solaris_devpoll_init(struct fdevents *ev); 141 __attribute_cold__ 142 int fdevent_solaris_port_init(struct fdevents *ev); 143 __attribute_cold__ 144 int fdevent_freebsd_kqueue_init(struct fdevents *ev); 145 __attribute_cold__ 146 int fdevent_libev_init(struct fdevents *ev); 147 148 #endif 149