Mercurial > hg > nginx-quic
comparison src/event/ngx_event.h @ 144:ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 12 Oct 2003 16:49:16 +0000 |
parents | 5526213be452 |
children | fb61ba77beba |
comparison
equal
deleted
inserted
replaced
143:5526213be452 | 144:ef8c87afcfc5 |
---|---|
22 | 22 |
23 struct ngx_event_s { | 23 struct ngx_event_s { |
24 void *data; | 24 void *data; |
25 void (*event_handler)(ngx_event_t *ev); | 25 void (*event_handler)(ngx_event_t *ev); |
26 | 26 |
27 #if 0 | |
28 int (*close_handler)(ngx_event_t *ev); | |
29 #endif | |
30 void *context; | 27 void *context; |
31 char *action; | 28 char *action; |
32 | 29 |
33 unsigned int index; | 30 unsigned int index; |
34 | 31 |
35 ngx_event_t *prev; /* queue in mutex(), aio_read(), aio_write() */ | 32 ngx_event_t *prev; /* queue in mutex(), aio_read(), aio_write() */ |
36 ngx_event_t *next; /* */ | 33 ngx_event_t *next; /* */ |
37 | 34 |
38 #if 0 | |
39 int (*timer_handler)(ngx_event_t *ev); | |
40 #endif | |
41 ngx_event_t *timer_prev; | 35 ngx_event_t *timer_prev; |
42 ngx_event_t *timer_next; | 36 ngx_event_t *timer_next; |
43 | 37 |
44 ngx_msec_t timer_delta; | 38 ngx_msec_t timer_delta; |
45 ngx_msec_t timer; | 39 ngx_msec_t timer; |
59 #if 0 | 53 #if 0 |
60 unsigned listening:1; | 54 unsigned listening:1; |
61 #endif | 55 #endif |
62 unsigned write:1; | 56 unsigned write:1; |
63 | 57 |
64 unsigned instance:1; /* used to detect stale events in kqueue, | 58 /* used to detect stale events in kqueue, rt signals and epoll */ |
65 rt signals and epoll */ | 59 unsigned instance:1; |
66 | 60 |
61 /* | |
62 * event was passed or would be passed to a kernel; | |
63 * the posted aio operation. | |
64 */ | |
67 unsigned active:1; | 65 unsigned active:1; |
66 | |
67 /* ready event; the complete aio operation */ | |
68 unsigned ready:1; | 68 unsigned ready:1; |
69 | |
69 unsigned timedout:1; | 70 unsigned timedout:1; |
71 unsigned timer_set:1; | |
72 | |
73 #if 1 | |
70 unsigned blocked:1; | 74 unsigned blocked:1; |
71 unsigned timer_set:1; | 75 #endif |
72 unsigned delayed:1; | 76 unsigned delayed:1; |
73 | 77 |
74 unsigned process:1; | |
75 unsigned read_discarded:1; | 78 unsigned read_discarded:1; |
76 | 79 |
77 unsigned ignore_econnreset:1; | 80 unsigned ignore_econnreset:1; |
78 unsigned unexpected_eof:1; | 81 unsigned unexpected_eof:1; |
79 | 82 |
154 int (*init)(ngx_cycle_t *cycle); | 157 int (*init)(ngx_cycle_t *cycle); |
155 void (*done)(ngx_cycle_t *cycle); | 158 void (*done)(ngx_cycle_t *cycle); |
156 } ngx_event_actions_t; | 159 } ngx_event_actions_t; |
157 | 160 |
158 | 161 |
159 /* The event filter requires to read/write the whole data - | 162 /* |
160 select, poll, /dev/poll, kqueue. */ | 163 * The event filter requires to read/write the whole data - |
161 #define NGX_HAVE_LEVEL_EVENT 0x00000001 | 164 * select, poll, /dev/poll, kqueue. |
162 | 165 */ |
163 /* The event filter is deleted after a notification without an additional | 166 #define NGX_USE_LEVEL_EVENT 0x00000001 |
164 syscall - select, poll, kqueue. */ | 167 |
165 #define NGX_HAVE_ONESHOT_EVENT 0x00000002 | 168 /* |
166 | 169 * The event filter is deleted after a notification without an additional |
167 /* The event filter notifies only the changes and an initial level - kqueue */ | 170 * syscall - select, poll, kqueue. |
168 #define NGX_HAVE_CLEAR_EVENT 0x00000004 | 171 */ |
169 | 172 #define NGX_USE_ONESHOT_EVENT 0x00000002 |
170 /* The event filter has kqueue features - the eof flag, errno, | 173 |
171 available data, etc */ | 174 /* |
172 #define NGX_HAVE_KQUEUE_EVENT 0x00000008 | 175 * The event filter notifies only the changes and an initial level - kqueue. |
173 | 176 */ |
174 /* The event filter supports low water mark - kqueue's NOTE_LOWAT. | 177 #define NGX_USE_CLEAR_EVENT 0x00000004 |
175 kqueue in FreeBSD 4.1-4.2 has no NOTE_LOWAT so we need a separate flag */ | 178 |
176 #define NGX_HAVE_LOWAT_EVENT 0x00000010 | 179 /* |
177 | 180 * The event filter has kqueue features - the eof flag, errno, |
178 /* The event filter notifies only the changes (the edges) | 181 * available data, etc |
179 but not an initial level - epoll */ | 182 */ |
180 #define NGX_HAVE_EDGE_EVENT 0x00000020 | 183 #define NGX_HAVE_KQUEUE_EVENT 0x00000008 |
181 | 184 |
182 /* No need to add or delete the event filters - rt signals */ | 185 /* |
183 #define NGX_HAVE_SIGIO_EVENT 0x00000040 | 186 * The event filter supports low water mark - kqueue's NOTE_LOWAT. |
184 | 187 * kqueue in FreeBSD 4.1-4.2 has no NOTE_LOWAT so we need a separate flag. |
185 /* No need to add or delete the event filters - overlapped, aio_read, aioread */ | 188 */ |
186 #define NGX_HAVE_AIO_EVENT 0x00000080 | 189 #define NGX_HAVE_LOWAT_EVENT 0x00000010 |
187 | 190 |
188 /* Need to add socket or handle only once - i/o completion port. | 191 /* |
189 It also requires HAVE_AIO_EVENT and NGX_HAVE_AIO_EVENT to be set */ | 192 * The event filter notifies only the changes (the edges) |
190 #define NGX_HAVE_IOCP_EVENT 0x00000100 | 193 * but not an initial level - epoll. |
191 | 194 */ |
192 | 195 #define NGX_USE_EDGE_EVENT 0x00000020 |
193 #define NGX_USE_LEVEL_EVENT 0x00010000 | 196 |
194 #define NGX_USE_AIO_EVENT 0x00020000 | 197 /* |
195 | 198 * No need to add or delete the event filters - rt signals. |
196 | 199 */ |
197 /* Event filter is deleted before closing file. | 200 #define NGX_USE_SIGIO_EVENT 0x00000040 |
198 Has no meaning for select, poll, epoll. | 201 |
199 | 202 /* |
200 kqueue: kqueue deletes event filters for file that closed | 203 * No need to add or delete the event filters - overlapped, aio_read, |
201 so we need only to delete filters in user-level batch array | 204 * aioread, io_submit. |
202 /dev/poll: we need to flush POLLREMOVE event before closing file */ | 205 */ |
206 #define NGX_USE_AIO_EVENT 0x00000080 | |
207 | |
208 /* | |
209 * Need to add socket or handle only once - i/o completion port. | |
210 * It also requires HAVE_AIO_EVENT and NGX_HAVE_AIO_EVENT to be set. | |
211 */ | |
212 #define NGX_USE_IOCP_EVENT 0x00000100 | |
213 | |
214 | |
215 | |
216 /* | |
217 * The event filter is deleted before the closing file. | |
218 * Has no meaning for select, poll, epoll. | |
219 * | |
220 * kqueue: kqueue deletes event filters for file that closed | |
221 * so we need only to delete filters in user-level batch array | |
222 * /dev/poll: we need to flush POLLREMOVE event before closing file | |
223 */ | |
203 | 224 |
204 #define NGX_CLOSE_EVENT 1 | 225 #define NGX_CLOSE_EVENT 1 |
205 | 226 |
206 | 227 |
207 #if (HAVE_KQUEUE) | 228 #if (HAVE_KQUEUE) |
208 | 229 |
209 #define NGX_READ_EVENT EVFILT_READ | 230 #define NGX_READ_EVENT EVFILT_READ |
210 #define NGX_WRITE_EVENT EVFILT_WRITE | 231 #define NGX_WRITE_EVENT EVFILT_WRITE |
211 | 232 |
212 /* NGX_CLOSE_EVENT is the module flag and it would not go into a kernel | 233 /* |
213 so we need to choose the value that would not interfere with any existent | 234 * NGX_CLOSE_EVENT is the module flag and it would not go into a kernel |
214 and future flags. kqueue has such values - EV_FLAG1, EV_EOF and EV_ERROR. | 235 * so we need to choose the value that would not interfere with any existent |
215 They are reserved and cleared on a kernel entrance */ | 236 * and future flags. kqueue has such values - EV_FLAG1, EV_EOF and EV_ERROR. |
237 * They are reserved and cleared on a kernel entrance. | |
238 */ | |
216 #undef NGX_CLOSE_EVENT | 239 #undef NGX_CLOSE_EVENT |
217 #define NGX_CLOSE_EVENT EV_FLAG1 | 240 #define NGX_CLOSE_EVENT EV_FLAG1 |
218 | 241 |
219 #define NGX_LEVEL_EVENT 0 | 242 #define NGX_LEVEL_EVENT 0 |
220 #define NGX_ONESHOT_EVENT EV_ONESHOT | 243 #define NGX_ONESHOT_EVENT EV_ONESHOT |
381 | 404 |
382 | 405 |
383 | 406 |
384 ngx_inline static int ngx_handle_read_event(ngx_event_t *rev) | 407 ngx_inline static int ngx_handle_read_event(ngx_event_t *rev) |
385 { | 408 { |
386 if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) { | 409 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT)) { |
387 | 410 |
388 /* aio, iocp, epoll */ | 411 /* aio, iocp, epoll */ |
389 | 412 |
390 return NGX_OK; | 413 return NGX_OK; |
391 } | 414 } |
392 | 415 |
393 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { | 416 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { |
394 | 417 |
395 /* kqueue */ | 418 /* kqueue */ |
396 | 419 |
397 if (!rev->active && !rev->ready) { | 420 if (!rev->active && !rev->ready) { |
398 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_CLEAR_EVENT) | 421 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_CLEAR_EVENT) |
424 | 447 |
425 return NGX_OK; | 448 return NGX_OK; |
426 } | 449 } |
427 | 450 |
428 | 451 |
452 ngx_inline static int ngx_handle_level_read_event(ngx_event_t *rev) | |
453 { | |
454 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | |
455 if (!rev->active && !rev->ready) { | |
456 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) | |
457 == NGX_ERROR) { | |
458 return NGX_ERROR; | |
459 } | |
460 | |
461 return NGX_OK; | |
462 } | |
463 | |
464 if (rev->active && rev->ready) { | |
465 if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { | |
466 return NGX_ERROR; | |
467 } | |
468 | |
469 return NGX_OK; | |
470 } | |
471 } | |
472 | |
473 return NGX_OK; | |
474 } | |
475 | |
476 | |
429 ngx_inline static int ngx_handle_write_event(ngx_event_t *wev, int lowat) | 477 ngx_inline static int ngx_handle_write_event(ngx_event_t *wev, int lowat) |
430 { | 478 { |
431 if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) { | 479 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT)) { |
432 | 480 |
433 /* aio, iocp, epoll */ | 481 /* aio, iocp, epoll */ |
434 | 482 |
435 return NGX_OK; | 483 return NGX_OK; |
436 } | 484 } |
437 | 485 |
438 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { | 486 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { |
439 | 487 |
440 /* kqueue */ | 488 /* kqueue */ |
441 | 489 |
442 #if (HAVE_LOWAT_EVENT) /* kqueue's NOTE_LOWAT */ | 490 #if (HAVE_LOWAT_EVENT) /* kqueue's NOTE_LOWAT */ |
443 | 491 |
476 | 524 |
477 return NGX_OK; | 525 return NGX_OK; |
478 } | 526 } |
479 | 527 |
480 | 528 |
529 ngx_inline static int ngx_handle_level_write_event(ngx_event_t *wev) | |
530 { | |
531 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | |
532 if (!wev->active && !wev->ready) { | |
533 if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT) | |
534 == NGX_ERROR) { | |
535 return NGX_ERROR; | |
536 } | |
537 | |
538 return NGX_OK; | |
539 } | |
540 | |
541 if (wev->active && wev->ready) { | |
542 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { | |
543 return NGX_ERROR; | |
544 } | |
545 | |
546 return NGX_OK; | |
547 } | |
548 } | |
549 | |
550 return NGX_OK; | |
551 } | |
552 | |
481 | 553 |
482 /* ***************************** */ | 554 /* ***************************** */ |
483 | 555 |
484 | 556 |
485 #endif /* _NGX_EVENT_H_INCLUDED_ */ | 557 #endif /* _NGX_EVENT_H_INCLUDED_ */ |