Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
vendor
nginx-1.4.2
src
event
ngx_event.h
Go to the documentation of this file.
1
2
/*
3
* Copyright (C) Igor Sysoev
4
* Copyright (C) Nginx, Inc.
5
*/
6
7
8
#ifndef _NGX_EVENT_H_INCLUDED_
9
#define _NGX_EVENT_H_INCLUDED_
10
11
12
#include <
ngx_config.h
>
13
#include <
ngx_core.h
>
14
15
16
#define NGX_INVALID_INDEX 0xd0d0d0d0
17
18
19
#if (NGX_HAVE_IOCP)
20
21
typedef
struct
{
22
WSAOVERLAPPED ovlp;
23
ngx_event_t
*event;
24
int
error
;
25
} ngx_event_ovlp_t;
26
27
#endif
28
29
30
typedef
struct
{
31
ngx_uint_t
lock
;
32
33
ngx_event_t
*
events
;
34
ngx_event_t
*
last
;
35
}
ngx_event_mutex_t
;
36
37
38
struct
ngx_event_s
{
39
void
*
data
;
40
41
unsigned
write
:1;
42
43
unsigned
accept
:1;
44
45
/* used to detect the stale events in kqueue, rtsig, and epoll */
46
unsigned
instance
:1;
47
48
/*
49
* the event was passed or would be passed to a kernel;
50
* in aio mode - operation was posted.
51
*/
52
unsigned
active
:1;
53
54
unsigned
disabled
:1;
55
56
/* the ready event; in aio mode 0 means that no operation can be posted */
57
unsigned
ready
:1;
58
59
unsigned
oneshot
:1;
60
61
/* aio operation is complete */
62
unsigned
complete
:1;
63
64
unsigned
eof
:1;
65
unsigned
error
:1;
66
67
unsigned
timedout
:1;
68
unsigned
timer_set
:1;
69
70
unsigned
delayed
:1;
71
72
unsigned
read_discarded
:1;
73
74
unsigned
unexpected_eof
:1;
75
76
unsigned
deferred_accept
:1;
77
78
/* the pending eof reported by kqueue or in aio chain operation */
79
unsigned
pending_eof
:1;
80
81
#if !(NGX_THREADS)
82
unsigned
posted_ready
:1;
83
#endif
84
85
#if (NGX_WIN32)
86
/* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was successful */
87
unsigned
accept_context_updated:1;
88
#endif
89
90
#if (NGX_HAVE_KQUEUE)
91
unsigned
kq_vnode:1;
92
93
/* the pending errno reported by kqueue */
94
int
kq_errno;
95
#endif
96
97
/*
98
* kqueue only:
99
* accept: number of sockets that wait to be accepted
100
* read: bytes to read when event is ready
101
* or lowat when event is set with NGX_LOWAT_EVENT flag
102
* write: available space in buffer when event is ready
103
* or lowat when event is set with NGX_LOWAT_EVENT flag
104
*
105
* iocp: TODO
106
*
107
* otherwise:
108
* accept: 1 if accept many, 0 otherwise
109
*/
110
111
#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
112
int
available
;
113
#else
114
unsigned
available
:1;
115
#endif
116
117
ngx_event_handler_pt
handler
;
118
119
120
#if (NGX_HAVE_AIO)
121
122
#if (NGX_HAVE_IOCP)
123
ngx_event_ovlp_t ovlp;
124
#else
125
struct
aiocb aiocb;
126
#endif
127
128
#endif
129
130
ngx_uint_t
index
;
131
132
ngx_log_t
*
log
;
133
134
ngx_rbtree_node_t
timer
;
135
136
unsigned
closed
:1;
137
138
/* to test on worker exit */
139
unsigned
channel
:1;
140
unsigned
resolver
:1;
141
142
#if (NGX_THREADS)
143
144
unsigned
locked:1;
145
146
unsigned
posted_ready
:1;
147
unsigned
posted_timedout:1;
148
unsigned
posted_eof:1;
149
150
#if (NGX_HAVE_KQUEUE)
151
/* the pending errno reported by kqueue */
152
int
posted_errno;
153
#endif
154
155
#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
156
int
posted_available;
157
#else
158
unsigned
posted_available:1;
159
#endif
160
161
ngx_atomic_t
*lock;
162
ngx_atomic_t
*own_lock;
163
164
#endif
165
166
/* the links of the posted queue */
167
ngx_event_t
*
next
;
168
ngx_event_t
**
prev
;
169
170
171
#if 0
172
173
/* the threads support */
174
175
/*
176
* the event thread context, we store it here
177
* if $(CC) does not understand __thread declaration
178
* and pthread_getspecific() is too costly
179
*/
180
181
void
*thr_ctx;
182
183
#if (NGX_EVENT_T_PADDING)
184
185
/* event should not cross cache line in SMP */
186
187
uint32_t padding[NGX_EVENT_T_PADDING];
188
#endif
189
#endif
190
};
191
192
193
#if (NGX_HAVE_FILE_AIO)
194
195
struct
ngx_event_aio_s {
196
void
*data;
197
ngx_event_handler_pt
handler;
198
ngx_file_t
*file;
199
200
ngx_fd_t
fd;
201
202
#if (NGX_HAVE_EVENTFD)
203
int64_t res;
204
#if (NGX_TEST_BUILD_EPOLL)
205
ngx_err_t
err;
206
size_t
nbytes;
207
#endif
208
#else
209
ngx_err_t
err;
210
size_t
nbytes;
211
#endif
212
213
#if (NGX_HAVE_AIO_SENDFILE)
214
off_t last_offset;
215
#endif
216
217
ngx_aiocb_t aiocb;
218
ngx_event_t
event;
219
};
220
221
#endif
222
223
224
typedef
struct
{
225
ngx_int_t
(*add)(
ngx_event_t
*ev,
ngx_int_t
event,
ngx_uint_t
flags);
226
ngx_int_t
(*del)(
ngx_event_t
*ev,
ngx_int_t
event,
ngx_uint_t
flags);
227
228
ngx_int_t
(*enable)(
ngx_event_t
*ev,
ngx_int_t
event,
ngx_uint_t
flags);
229
ngx_int_t
(*disable)(
ngx_event_t
*ev,
ngx_int_t
event,
ngx_uint_t
flags);
230
231
ngx_int_t
(*add_conn)(
ngx_connection_t
*c);
232
ngx_int_t
(*del_conn)(
ngx_connection_t
*c,
ngx_uint_t
flags);
233
234
ngx_int_t
(*process_changes)(
ngx_cycle_t
*cycle,
ngx_uint_t
nowait);
235
ngx_int_t
(*process_events)(
ngx_cycle_t
*cycle,
ngx_msec_t
timer,
236
ngx_uint_t
flags);
237
238
ngx_int_t
(*init)(
ngx_cycle_t
*cycle,
ngx_msec_t
timer);
239
void (*done)(
ngx_cycle_t
*cycle);
240
}
ngx_event_actions_t
;
241
242
243
extern
ngx_event_actions_t
ngx_event_actions
;
244
245
246
/*
247
* The event filter requires to read/write the whole data:
248
* select, poll, /dev/poll, kqueue, epoll.
249
*/
250
#define NGX_USE_LEVEL_EVENT 0x00000001
251
252
/*
253
* The event filter is deleted after a notification without an additional
254
* syscall: kqueue, epoll.
255
*/
256
#define NGX_USE_ONESHOT_EVENT 0x00000002
257
258
/*
259
* The event filter notifies only the changes and an initial level:
260
* kqueue, epoll.
261
*/
262
#define NGX_USE_CLEAR_EVENT 0x00000004
263
264
/*
265
* The event filter has kqueue features: the eof flag, errno,
266
* available data, etc.
267
*/
268
#define NGX_USE_KQUEUE_EVENT 0x00000008
269
270
/*
271
* The event filter supports low water mark: kqueue's NOTE_LOWAT.
272
* kqueue in FreeBSD 4.1-4.2 has no NOTE_LOWAT so we need a separate flag.
273
*/
274
#define NGX_USE_LOWAT_EVENT 0x00000010
275
276
/*
277
* The event filter requires to do i/o operation until EAGAIN: epoll, rtsig.
278
*/
279
#define NGX_USE_GREEDY_EVENT 0x00000020
280
281
/*
282
* The event filter is epoll.
283
*/
284
#define NGX_USE_EPOLL_EVENT 0x00000040
285
286
/*
287
* No need to add or delete the event filters: rtsig.
288
*/
289
#define NGX_USE_RTSIG_EVENT 0x00000080
290
291
/*
292
* No need to add or delete the event filters: overlapped, aio_read,
293
* aioread, io_submit.
294
*/
295
#define NGX_USE_AIO_EVENT 0x00000100
296
297
/*
298
* Need to add socket or handle only once: i/o completion port.
299
* It also requires NGX_HAVE_AIO and NGX_USE_AIO_EVENT to be set.
300
*/
301
#define NGX_USE_IOCP_EVENT 0x00000200
302
303
/*
304
* The event filter has no opaque data and requires file descriptors table:
305
* poll, /dev/poll, rtsig.
306
*/
307
#define NGX_USE_FD_EVENT 0x00000400
308
309
/*
310
* The event module handles periodic or absolute timer event by itself:
311
* kqueue in FreeBSD 4.4, NetBSD 2.0, and MacOSX 10.4, Solaris 10's event ports.
312
*/
313
#define NGX_USE_TIMER_EVENT 0x00000800
314
315
/*
316
* All event filters on file descriptor are deleted after a notification:
317
* Solaris 10's event ports.
318
*/
319
#define NGX_USE_EVENTPORT_EVENT 0x00001000
320
321
/*
322
* The event filter support vnode notifications: kqueue.
323
*/
324
#define NGX_USE_VNODE_EVENT 0x00002000
325
326
327
/*
328
* The event filter is deleted just before the closing file.
329
* Has no meaning for select and poll.
330
* kqueue, epoll, rtsig, eventport: allows to avoid explicit delete,
331
* because filter automatically is deleted
332
* on file close,
333
*
334
* /dev/poll: we need to flush POLLREMOVE event
335
* before closing file.
336
*/
337
#define NGX_CLOSE_EVENT 1
338
339
/*
340
* disable temporarily event filter, this may avoid locks
341
* in kernel malloc()/free(): kqueue.
342
*/
343
#define NGX_DISABLE_EVENT 2
344
345
/*
346
* event must be passed to kernel right now, do not wait until batch processing.
347
*/
348
#define NGX_FLUSH_EVENT 4
349
350
351
/* these flags have a meaning only for kqueue */
352
#define NGX_LOWAT_EVENT 0
353
#define NGX_VNODE_EVENT 0
354
355
356
#if (NGX_HAVE_KQUEUE)
357
358
#define NGX_READ_EVENT EVFILT_READ
359
#define NGX_WRITE_EVENT EVFILT_WRITE
360
361
#undef NGX_VNODE_EVENT
362
#define NGX_VNODE_EVENT EVFILT_VNODE
363
364
/*
365
* NGX_CLOSE_EVENT, NGX_LOWAT_EVENT, and NGX_FLUSH_EVENT are the module flags
366
* and they must not go into a kernel so we need to choose the value
367
* that must not interfere with any existent and future kqueue flags.
368
* kqueue has such values - EV_FLAG1, EV_EOF, and EV_ERROR:
369
* they are reserved and cleared on a kernel entrance.
370
*/
371
#undef NGX_CLOSE_EVENT
372
#define NGX_CLOSE_EVENT EV_EOF
373
374
#undef NGX_LOWAT_EVENT
375
#define NGX_LOWAT_EVENT EV_FLAG1
376
377
#undef NGX_FLUSH_EVENT
378
#define NGX_FLUSH_EVENT EV_ERROR
379
380
#define NGX_LEVEL_EVENT 0
381
#define NGX_ONESHOT_EVENT EV_ONESHOT
382
#define NGX_CLEAR_EVENT EV_CLEAR
383
384
#undef NGX_DISABLE_EVENT
385
#define NGX_DISABLE_EVENT EV_DISABLE
386
387
388
#elif (NGX_HAVE_DEVPOLL || NGX_HAVE_EVENTPORT)
389
390
#define NGX_READ_EVENT POLLIN
391
#define NGX_WRITE_EVENT POLLOUT
392
393
#define NGX_LEVEL_EVENT 0
394
#define NGX_ONESHOT_EVENT 1
395
396
397
#elif (NGX_HAVE_EPOLL)
398
399
#define NGX_READ_EVENT EPOLLIN
400
#define NGX_WRITE_EVENT EPOLLOUT
401
402
#define NGX_LEVEL_EVENT 0
403
#define NGX_CLEAR_EVENT EPOLLET
404
#define NGX_ONESHOT_EVENT 0x70000000
405
#if 0
406
#define NGX_ONESHOT_EVENT EPOLLONESHOT
407
#endif
408
409
410
#elif (NGX_HAVE_POLL)
411
412
#define NGX_READ_EVENT POLLIN
413
#define NGX_WRITE_EVENT POLLOUT
414
415
#define NGX_LEVEL_EVENT 0
416
#define NGX_ONESHOT_EVENT 1
417
418
419
#else
/* select */
420
421
#define NGX_READ_EVENT 0
422
#define NGX_WRITE_EVENT 1
423
424
#define NGX_LEVEL_EVENT 0
425
#define NGX_ONESHOT_EVENT 1
426
427
#endif
/* NGX_HAVE_KQUEUE */
428
429
430
#if (NGX_HAVE_IOCP)
431
#define NGX_IOCP_ACCEPT 0
432
#define NGX_IOCP_IO 1
433
#define NGX_IOCP_CONNECT 2
434
#endif
435
436
437
#ifndef NGX_CLEAR_EVENT
438
#define NGX_CLEAR_EVENT 0
/* dummy declaration */
439
#endif
440
441
442
#define ngx_process_changes ngx_event_actions.process_changes
443
#define ngx_process_events ngx_event_actions.process_events
444
#define ngx_done_events ngx_event_actions.done
445
446
#define ngx_add_event ngx_event_actions.add
447
#define ngx_del_event ngx_event_actions.del
448
#define ngx_add_conn ngx_event_actions.add_conn
449
#define ngx_del_conn ngx_event_actions.del_conn
450
451
#define ngx_add_timer ngx_event_add_timer
452
#define ngx_del_timer ngx_event_del_timer
453
454
455
extern
ngx_os_io_t
ngx_io
;
456
457
#define ngx_recv ngx_io.recv
458
#define ngx_recv_chain ngx_io.recv_chain
459
#define ngx_udp_recv ngx_io.udp_recv
460
#define ngx_send ngx_io.send
461
#define ngx_send_chain ngx_io.send_chain
462
463
464
#define NGX_EVENT_MODULE 0x544E5645
/* "EVNT" */
465
#define NGX_EVENT_CONF 0x02000000
466
467
468
typedef
struct
{
469
ngx_uint_t
connections
;
470
ngx_uint_t
use
;
471
472
ngx_flag_t
multi_accept
;
473
ngx_flag_t
accept_mutex
;
474
475
ngx_msec_t
accept_mutex_delay
;
476
477
u_char *
name
;
478
479
#if (NGX_DEBUG)
480
ngx_array_t
debug_connection;
481
#endif
482
}
ngx_event_conf_t
;
483
484
485
typedef
struct
{
486
ngx_str_t
*
name
;
487
488
void
*(*create_conf)(
ngx_cycle_t
*cycle);
489
char
*(*init_conf)(
ngx_cycle_t
*cycle,
void
*conf);
490
491
ngx_event_actions_t
actions
;
492
}
ngx_event_module_t
;
493
494
495
extern
ngx_atomic_t
*
ngx_connection_counter
;
496
497
extern
ngx_atomic_t
*
ngx_accept_mutex_ptr
;
498
extern
ngx_shmtx_t
ngx_accept_mutex
;
499
extern
ngx_uint_t
ngx_use_accept_mutex
;
500
extern
ngx_uint_t
ngx_accept_events
;
501
extern
ngx_uint_t
ngx_accept_mutex_held
;
502
extern
ngx_msec_t
ngx_accept_mutex_delay
;
503
extern
ngx_int_t
ngx_accept_disabled
;
504
505
506
#if (NGX_STAT_STUB)
507
508
extern
ngx_atomic_t
*ngx_stat_accepted;
509
extern
ngx_atomic_t
*ngx_stat_handled;
510
extern
ngx_atomic_t
*ngx_stat_requests;
511
extern
ngx_atomic_t
*ngx_stat_active;
512
extern
ngx_atomic_t
*ngx_stat_reading;
513
extern
ngx_atomic_t
*ngx_stat_writing;
514
extern
ngx_atomic_t
*ngx_stat_waiting;
515
516
#endif
517
518
519
#define NGX_UPDATE_TIME 1
520
#define NGX_POST_EVENTS 2
521
#define NGX_POST_THREAD_EVENTS 4
522
523
524
extern
sig_atomic_t
ngx_event_timer_alarm
;
525
extern
ngx_uint_t
ngx_event_flags
;
526
extern
ngx_module_t
ngx_events_module
;
527
extern
ngx_module_t
ngx_event_core_module
;
528
529
530
#define ngx_event_get_conf(conf_ctx, module) \
531
(*(ngx_get_conf(conf_ctx, ngx_events_module))) [module.ctx_index];
532
533
534
535
void
ngx_event_accept
(
ngx_event_t
*ev);
536
ngx_int_t
ngx_trylock_accept_mutex
(
ngx_cycle_t
*cycle);
537
u_char *
ngx_accept_log_error
(
ngx_log_t
*log, u_char *buf,
size_t
len);
538
539
540
void
ngx_process_events_and_timers
(
ngx_cycle_t
*cycle);
541
ngx_int_t
ngx_handle_read_event
(
ngx_event_t
*rev,
ngx_uint_t
flags);
542
ngx_int_t
ngx_handle_write_event
(
ngx_event_t
*wev,
size_t
lowat);
543
544
545
#if (NGX_WIN32)
546
void
ngx_event_acceptex(
ngx_event_t
*ev);
547
ngx_int_t
ngx_event_post_acceptex(
ngx_listening_t
*ls,
ngx_uint_t
n);
548
u_char *ngx_acceptex_log_error(
ngx_log_t
*log, u_char *buf,
size_t
len);
549
#endif
550
551
552
ngx_int_t
ngx_send_lowat
(
ngx_connection_t
*c,
size_t
lowat);
553
554
555
/* used in ngx_log_debugX() */
556
#define ngx_event_ident(p) ((ngx_connection_t *) (p))->fd
557
558
559
#include <
ngx_event_timer.h
>
560
#include <
ngx_event_posted.h
>
561
#include <
ngx_event_busy_lock.h
>
562
563
#if (NGX_WIN32)
564
#include <ngx_iocp_module.h>
565
#endif
566
567
568
#endif
/* _NGX_EVENT_H_INCLUDED_ */
Generated on Sun Nov 10 2013 09:49:07 for Groonga 3.0.9 Source Code Document by
1.8.1.2