xref: /lighttpd1.4/src/fdevent_impl.h (revision 66698469)
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 #ifndef FDEVENT_USE_POLL
20 #if defined HAVE_SELECT
21 # ifdef __WIN32
22 #  include <winsock2.h>
23 # endif
24 # define FDEVENT_USE_SELECT
25 # ifdef HAVE_SYS_SELECT_H
26 #  include <sys/select.h>
27 # endif
28 #endif
29 #endif
30 
31 #if defined HAVE_SYS_DEVPOLL_H && defined(__sun)
32 # define FDEVENT_USE_SOLARIS_DEVPOLL
33 struct pollfd;          /* declaration */
34 #endif
35 
36 #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)
37 # define FDEVENT_USE_SOLARIS_PORT
38 # include <port.h>
39 /* Illumos epoll not supported by lighttpd; POLLRDHUP != EPOLLRDHUP on Illumos*/
40 # undef FDEVENT_USE_LINUX_EPOLL
41 #endif
42 
43 #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
44 # define FDEVENT_USE_FREEBSD_KQUEUE
45 struct kevent;          /* declaration */
46 #endif
47 
48 #if defined HAVE_LIBEV
49 # define FDEVENT_USE_LIBEV
50 struct ev_loop;         /* declaration */
51 #endif
52 
53 #include "base_decls.h"
54 #include "fdevent.h"    /* (*fdevent_handler) */
55 
56 typedef enum {
57     FDEVENT_HANDLER_UNSET,
58     FDEVENT_HANDLER_SELECT,
59     FDEVENT_HANDLER_POLL,
60     FDEVENT_HANDLER_LINUX_SYSEPOLL,
61     FDEVENT_HANDLER_SOLARIS_DEVPOLL,
62     FDEVENT_HANDLER_SOLARIS_PORT,
63     FDEVENT_HANDLER_FREEBSD_KQUEUE,
64     FDEVENT_HANDLER_LIBEV
65 } fdevent_handler_t;
66 
67 /**
68  * array of unused fd's
69  *
70  */
71 
72 #ifdef FDEVENT_USE_POLL
73 typedef struct {
74     int *ptr;
75 
76     uint32_t used;
77     uint32_t size;
78 } buffer_int;
79 #endif
80 
81 struct fdevents {
82     fdnode **fdarray;
83     fdnode *pendclose;
84 
85     int (*event_set)(struct fdevents *ev, fdnode *fdn, int events);
86     int (*event_del)(struct fdevents *ev, fdnode *fdn);
87     int (*poll)(struct fdevents *ev, int timeout_ms);
88 
89     log_error_st *errh;
90     int *cur_fds;
91     uint32_t maxfds;
92   #ifdef FDEVENT_USE_LINUX_EPOLL
93     int epoll_fd;
94     struct epoll_event *epoll_events;
95   #endif
96   #ifdef FDEVENT_USE_SOLARIS_DEVPOLL
97     int devpoll_fd;
98     struct pollfd *devpollfds;
99   #endif
100   #ifdef FDEVENT_USE_SOLARIS_PORT
101     int port_fd;
102     port_event_t *port_events;
103   #endif
104   #ifdef FDEVENT_USE_FREEBSD_KQUEUE
105     int kq_fd;
106     struct kevent *kq_results;
107   #endif
108   #ifdef FDEVENT_USE_LIBEV
109     struct ev_loop *libev_loop;
110   #endif
111   #ifdef FDEVENT_USE_POLL
112     struct pollfd *pollfds;
113 
114     uint32_t size;
115     uint32_t used;
116 
117     buffer_int unused;
118   #endif
119   #ifdef FDEVENT_USE_SELECT
120     fd_set select_read;
121     fd_set select_write;
122     fd_set select_error;
123 
124     fd_set select_set_read;
125     fd_set select_set_write;
126     fd_set select_set_error;
127 
128     int select_max_fd;
129   #endif
130 
131     int (*reset)(struct fdevents *ev);
132     void (*free)(struct fdevents *ev);
133     const char *event_handler;
134     fdevent_handler_t type;
135 };
136 
137 #endif
138