Annotation of embedaddon/lighttpd/src/fdevent.h, revision 1.1.1.2
1.1 misho 1: #ifndef _FDEVENT_H_
2: #define _FDEVENT_H_
3:
4: #ifdef HAVE_CONFIG_H
5: # include "config.h"
6: #endif
7:
8: #include "settings.h"
9: #include "bitset.h"
10:
11: #if defined HAVE_STDINT_H
12: # include <stdint.h>
13: #elif defined HAVE_INTTYPES_H
14: # include <inttypes.h>
15: #endif
16:
17: #include <sys/types.h>
18:
19: /* select event-system */
20:
21: #if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)
22: # define USE_LINUX_EPOLL
23: #endif
24:
25: /* MacOS 10.3.x has poll.h under /usr/include/, all other unixes
26: * under /usr/include/sys/ */
27: #if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))
28: # define USE_POLL
29: #endif
30:
31: #if defined HAVE_SELECT
32: # ifdef __WIN32
33: # include <winsock2.h>
34: # endif
35: # define USE_SELECT
36: # ifdef HAVE_SYS_SELECT_H
37: # include <sys/select.h>
38: # endif
39: #endif
40:
41: #if defined HAVE_SYS_DEVPOLL_H && defined(__sun)
42: # define USE_SOLARIS_DEVPOLL
43: #endif
44:
45: #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)
46: # define USE_SOLARIS_PORT
47: # include <port.h>
48: #endif
49:
50: #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
51: # define USE_FREEBSD_KQUEUE
52: #endif
53:
54: #if defined HAVE_LIBEV
55: # define USE_LIBEV
56: #endif
57:
58: struct server;
59:
60: typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents);
61:
62: /* these are the POLL* values from <bits/poll.h> (linux poll)
63: */
64:
65: #define FDEVENT_IN BV(0)
66: #define FDEVENT_PRI BV(1)
67: #define FDEVENT_OUT BV(2)
68: #define FDEVENT_ERR BV(3)
69: #define FDEVENT_HUP BV(4)
70: #define FDEVENT_NVAL BV(5)
71:
72: typedef enum { FD_EVENT_TYPE_UNSET = -1,
73: FD_EVENT_TYPE_CONNECTION,
74: FD_EVENT_TYPE_FCGI_CONNECTION,
75: FD_EVENT_TYPE_DIRWATCH,
76: FD_EVENT_TYPE_CGI_CONNECTION
77: } fd_event_t;
78:
79: typedef enum { FDEVENT_HANDLER_UNSET,
80: FDEVENT_HANDLER_SELECT,
81: FDEVENT_HANDLER_POLL,
82: FDEVENT_HANDLER_LINUX_SYSEPOLL,
83: FDEVENT_HANDLER_SOLARIS_DEVPOLL,
84: FDEVENT_HANDLER_SOLARIS_PORT,
85: FDEVENT_HANDLER_FREEBSD_KQUEUE,
86: FDEVENT_HANDLER_LIBEV
87: } fdevent_handler_t;
88:
89:
90: typedef struct _fdnode {
91: fdevent_handler handler;
92: void *ctx;
93: void *handler_ctx;
94: int fd;
95: int events;
96: } fdnode;
97:
98: /**
99: * array of unused fd's
100: *
101: */
102:
103: typedef struct {
104: int *ptr;
105:
106: size_t used;
107: size_t size;
108: } buffer_int;
109:
110: /**
111: * fd-event handler for select(), poll() and rt-signals on Linux 2.4
112: *
113: */
114: typedef struct fdevents {
115: struct server *srv;
116: fdevent_handler_t type;
117:
118: fdnode **fdarray;
119: size_t maxfds;
120:
121: #ifdef USE_LINUX_EPOLL
122: int epoll_fd;
123: struct epoll_event *epoll_events;
124: #endif
125: #ifdef USE_POLL
126: struct pollfd *pollfds;
127:
128: size_t size;
129: size_t used;
130:
131: buffer_int unused;
132: #endif
133: #ifdef USE_SELECT
134: fd_set select_read;
135: fd_set select_write;
136: fd_set select_error;
137:
138: fd_set select_set_read;
139: fd_set select_set_write;
140: fd_set select_set_error;
141:
142: int select_max_fd;
143: #endif
144: #ifdef USE_SOLARIS_DEVPOLL
145: int devpoll_fd;
146: struct pollfd *devpollfds;
147: #endif
148: #ifdef USE_SOLARIS_PORT
149: port_event_t *port_events;
150: #endif
151: #ifdef USE_FREEBSD_KQUEUE
152: int kq_fd;
153: struct kevent *kq_results;
154: #endif
155: #ifdef USE_SOLARIS_PORT
156: int port_fd;
157: #endif
158: #ifdef USE_LIBEV
159: struct ev_loop *libev_loop;
160: #endif
161: int (*reset)(struct fdevents *ev);
162: void (*free)(struct fdevents *ev);
163:
164: int (*event_set)(struct fdevents *ev, int fde_ndx, int fd, int events);
165: int (*event_del)(struct fdevents *ev, int fde_ndx, int fd);
166: int (*event_get_revent)(struct fdevents *ev, size_t ndx);
167: int (*event_get_fd)(struct fdevents *ev, size_t ndx);
168:
169: int (*event_next_fdndx)(struct fdevents *ev, int ndx);
170:
171: int (*poll)(struct fdevents *ev, int timeout_ms);
172:
173: int (*fcntl_set)(struct fdevents *ev, int fd);
174: } fdevents;
175:
176: fdevents *fdevent_init(struct server *srv, size_t maxfds, fdevent_handler_t type);
177: int fdevent_reset(fdevents *ev); /* "init" after fork() */
178: void fdevent_free(fdevents *ev);
179:
180: int fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
181: int fdevent_event_del(fdevents *ev, int *fde_ndx, int fd);
182: int fdevent_event_get_revent(fdevents *ev, size_t ndx);
183: int fdevent_event_get_fd(fdevents *ev, size_t ndx);
184: fdevent_handler fdevent_get_handler(fdevents *ev, int fd);
185: void * fdevent_get_context(fdevents *ev, int fd);
186:
187: int fdevent_event_next_fdndx(fdevents *ev, int ndx);
188:
189: int fdevent_poll(fdevents *ev, int timeout_ms);
190:
191: int fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
192: int fdevent_unregister(fdevents *ev, int fd);
193:
1.1.1.2 ! misho 194: void fd_close_on_exec(int fd);
1.1 misho 195: int fdevent_fcntl_set(fdevents *ev, int fd);
196:
197: int fdevent_select_init(fdevents *ev);
198: int fdevent_poll_init(fdevents *ev);
199: int fdevent_linux_sysepoll_init(fdevents *ev);
200: int fdevent_solaris_devpoll_init(fdevents *ev);
201: int fdevent_solaris_port_init(fdevents *ev);
202: int fdevent_freebsd_kqueue_init(fdevents *ev);
203: int fdevent_libev_init(fdevents *ev);
204:
205: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>