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 #endif
40 
41 #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
42 # define FDEVENT_USE_FREEBSD_KQUEUE
43 struct kevent;          /* declaration */
44 #endif
45 
46 #if defined HAVE_LIBEV
47 # define FDEVENT_USE_LIBEV
48 struct ev_loop;         /* declaration */
49 #endif
50 
51 #include "base_decls.h"
52 #include "fdevent.h"    /* (*fdevent_handler) */
53 
54 typedef enum {
55     FDEVENT_HANDLER_UNSET,
56     FDEVENT_HANDLER_SELECT,
57     FDEVENT_HANDLER_POLL,
58     FDEVENT_HANDLER_LINUX_SYSEPOLL,
59     FDEVENT_HANDLER_SOLARIS_DEVPOLL,
60     FDEVENT_HANDLER_SOLARIS_PORT,
61     FDEVENT_HANDLER_FREEBSD_KQUEUE,
62     FDEVENT_HANDLER_LIBEV
63 } fdevent_handler_t;
64 
65 /**
66  * array of unused fd's
67  *
68  */
69 
70 #ifdef FDEVENT_USE_POLL
71 typedef struct {
72     int *ptr;
73 
74     uint32_t used;
75     uint32_t size;
76 } buffer_int;
77 #endif
78 
79 struct fdevents {
80     fdnode **fdarray;
81     fdnode *pendclose;
82 
83     int (*event_set)(struct fdevents *ev, fdnode *fdn, int events);
84     int (*event_del)(struct fdevents *ev, fdnode *fdn);
85     int (*poll)(struct fdevents *ev, int timeout_ms);
86 
87     log_error_st *errh;
88     int *cur_fds;
89     uint32_t maxfds;
90   #ifdef FDEVENT_USE_LINUX_EPOLL
91     int epoll_fd;
92     struct epoll_event *epoll_events;
93   #endif
94   #ifdef FDEVENT_USE_SOLARIS_DEVPOLL
95     int devpoll_fd;
96     struct pollfd *devpollfds;
97   #endif
98   #ifdef FDEVENT_USE_SOLARIS_PORT
99     int port_fd;
100     port_event_t *port_events;
101   #endif
102   #ifdef FDEVENT_USE_FREEBSD_KQUEUE
103     int kq_fd;
104     struct kevent *kq_results;
105   #endif
106   #ifdef FDEVENT_USE_LIBEV
107     struct ev_loop *libev_loop;
108   #endif
109   #ifdef FDEVENT_USE_POLL
110     struct pollfd *pollfds;
111 
112     uint32_t size;
113     uint32_t used;
114 
115     buffer_int unused;
116   #endif
117   #ifdef FDEVENT_USE_SELECT
118     fd_set select_read;
119     fd_set select_write;
120     fd_set select_error;
121 
122     fd_set select_set_read;
123     fd_set select_set_write;
124     fd_set select_set_error;
125 
126     int select_max_fd;
127   #endif
128 
129     int (*reset)(struct fdevents *ev);
130     void (*free)(struct fdevents *ev);
131     const char *event_handler;
132     fdevent_handler_t type;
133 };
134 
135 #endif
136