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 size_t used; 73 size_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 struct server *srv; 86 size_t maxfds; 87 #ifdef FDEVENT_USE_LINUX_EPOLL 88 int epoll_fd; 89 struct epoll_event *epoll_events; 90 #endif 91 #ifdef FDEVENT_USE_SOLARIS_DEVPOLL 92 int devpoll_fd; 93 struct pollfd *devpollfds; 94 #endif 95 #ifdef FDEVENT_USE_SOLARIS_PORT 96 int port_fd; 97 port_event_t *port_events; 98 #endif 99 #ifdef FDEVENT_USE_FREEBSD_KQUEUE 100 int kq_fd; 101 struct kevent *kq_results; 102 #endif 103 #ifdef FDEVENT_USE_LIBEV 104 struct ev_loop *libev_loop; 105 #endif 106 #ifdef FDEVENT_USE_POLL 107 struct pollfd *pollfds; 108 109 size_t size; 110 size_t used; 111 112 buffer_int unused; 113 #endif 114 #ifdef FDEVENT_USE_SELECT 115 fd_set select_read; 116 fd_set select_write; 117 fd_set select_error; 118 119 fd_set select_set_read; 120 fd_set select_set_write; 121 fd_set select_set_error; 122 123 int select_max_fd; 124 #endif 125 126 int (*reset)(struct fdevents *ev); 127 void (*free)(struct fdevents *ev); 128 fdevent_handler_t type; 129 }; 130 131 __attribute_cold__ 132 int fdevent_select_init(struct fdevents *ev); 133 __attribute_cold__ 134 int fdevent_poll_init(struct fdevents *ev); 135 __attribute_cold__ 136 int fdevent_linux_sysepoll_init(struct fdevents *ev); 137 __attribute_cold__ 138 int fdevent_solaris_devpoll_init(struct fdevents *ev); 139 __attribute_cold__ 140 int fdevent_solaris_port_init(struct fdevents *ev); 141 __attribute_cold__ 142 int fdevent_freebsd_kqueue_init(struct fdevents *ev); 143 __attribute_cold__ 144 int fdevent_libev_init(struct fdevents *ev); 145 146 #endif 147