Mercurial > hg > nginx-quic
annotate src/event/modules/ngx_epoll_module.c @ 4877:f2e450929c1f
OCSP stapling: log error data in ngx_ssl_error().
It's hard to debug OCSP_basic_verify() failures without the actual error
string it records in the error data field.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 01 Oct 2012 12:50:36 +0000 |
parents | 4c36e15651f7 |
children | 36b58ddb566d |
rev | line source |
---|---|
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
5 */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
469 | 13 #if (NGX_TEST_BUILD_EPOLL) |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 /* epoll declarations */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
17 #define EPOLLIN 0x001 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
18 #define EPOLLPRI 0x002 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
19 #define EPOLLOUT 0x004 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
20 #define EPOLLRDNORM 0x040 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
21 #define EPOLLRDBAND 0x080 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
22 #define EPOLLWRNORM 0x100 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
23 #define EPOLLWRBAND 0x200 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
24 #define EPOLLMSG 0x400 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
25 #define EPOLLERR 0x008 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
26 #define EPOLLHUP 0x010 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
27 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
28 #define EPOLLET 0x80000000 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
29 #define EPOLLONESHOT 0x40000000 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 #define EPOLL_CTL_ADD 1 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 #define EPOLL_CTL_DEL 2 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 #define EPOLL_CTL_MOD 3 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 typedef union epoll_data { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 void *ptr; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 int fd; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 uint32_t u32; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 uint64_t u64; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 } epoll_data_t; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 struct epoll_event { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 uint32_t events; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 epoll_data_t data; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
47 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
48 int epoll_create(int size); |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
49 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 int epoll_create(int size) |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
55 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
56 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
57 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
63 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
64 int epoll_wait(int epfd, struct epoll_event *events, int nevents, int timeout); |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
65 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 int epoll_wait(int epfd, struct epoll_event *events, int nevents, int timeout) |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
71 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
72 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
73 #define SYS_io_setup 245 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
74 #define SYS_io_destroy 246 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
75 #define SYS_io_getevents 247 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
76 #define SYS_eventfd 323 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
77 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
78 typedef u_int aio_context_t; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
79 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
80 struct io_event { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
81 uint64_t data; /* the data field from the iocb */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
82 uint64_t obj; /* what iocb this event came from */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
83 int64_t res; /* result code for this event */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
84 int64_t res2; /* secondary result */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
85 }; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
86 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
87 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
88 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 #endif |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 typedef struct { |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
93 ngx_uint_t events; |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
94 ngx_uint_t aio_requests; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 } ngx_epoll_conf_t; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
563 | 98 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 static void ngx_epoll_done(ngx_cycle_t *cycle); |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
100 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event, |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
101 ngx_uint_t flags); |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
102 static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event, |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
103 ngx_uint_t flags); |
499 | 104 static ngx_int_t ngx_epoll_add_connection(ngx_connection_t *c); |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
105 static ngx_int_t ngx_epoll_del_connection(ngx_connection_t *c, |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
106 ngx_uint_t flags); |
563 | 107 static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
108 ngx_uint_t flags); | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
110 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
111 static void ngx_epoll_eventfd_handler(ngx_event_t *ev); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
112 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
113 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 static int ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 static struct epoll_event *event_list; |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
119 static ngx_uint_t nevents; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
121 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
122 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
123 int ngx_eventfd = -1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
124 aio_context_t ngx_aio_ctx = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
125 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
126 static ngx_event_t ngx_eventfd_event; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
127 static ngx_connection_t ngx_eventfd_conn; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
128 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
129 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 static ngx_str_t epoll_name = ngx_string("epoll"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 static ngx_command_t ngx_epoll_commands[] = { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 |
499 | 135 { ngx_string("epoll_events"), |
136 NGX_EVENT_CONF|NGX_CONF_TAKE1, | |
137 ngx_conf_set_num_slot, | |
138 0, | |
139 offsetof(ngx_epoll_conf_t, events), | |
140 NULL }, | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
142 { ngx_string("worker_aio_requests"), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
143 NGX_EVENT_CONF|NGX_CONF_TAKE1, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
144 ngx_conf_set_num_slot, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
145 0, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
146 offsetof(ngx_epoll_conf_t, aio_requests), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
147 NULL }, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
148 |
499 | 149 ngx_null_command |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 ngx_event_module_t ngx_epoll_module_ctx = { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 &epoll_name, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 ngx_epoll_create_conf, /* create configuration */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 ngx_epoll_init_conf, /* init configuration */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 { |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
159 ngx_epoll_add_event, /* add an event */ |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
160 ngx_epoll_del_event, /* delete an event */ |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
161 ngx_epoll_add_event, /* enable an event */ |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
162 ngx_epoll_del_event, /* disable an event */ |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
163 ngx_epoll_add_connection, /* add an connection */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
164 ngx_epoll_del_connection, /* delete an connection */ |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
165 NULL, /* process the changes */ |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 ngx_epoll_process_events, /* process the events */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 ngx_epoll_init, /* init the events */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 ngx_epoll_done, /* done the events */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 ngx_module_t ngx_epoll_module = { |
509 | 173 NGX_MODULE_V1, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 &ngx_epoll_module_ctx, /* module context */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 ngx_epoll_commands, /* module directives */ |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
176 NGX_EVENT_MODULE, /* module type */ |
541 | 177 NULL, /* init master */ |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
178 NULL, /* init module */ |
541 | 179 NULL, /* init process */ |
180 NULL, /* init thread */ | |
181 NULL, /* exit thread */ | |
182 NULL, /* exit process */ | |
183 NULL, /* exit master */ | |
184 NGX_MODULE_V1_PADDING | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
188 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
189 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
190 /* |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
191 * We call io_setup(), io_destroy() io_submit(), and io_getevents() directly |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
192 * as syscalls instead of libaio usage, because the library header file |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
193 * supports eventfd() since 0.3.107 version only. |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
194 * |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
195 * Also we do not use eventfd() in glibc, because glibc supports it |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
196 * since 2.8 version and glibc maps two syscalls eventfd() and eventfd2() |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
197 * into single eventfd() function with different number of parameters. |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
198 */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
199 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
200 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
201 io_setup(u_int nr_reqs, aio_context_t *ctx) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
202 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
203 return syscall(SYS_io_setup, nr_reqs, ctx); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
204 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
205 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
206 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
207 static int |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
208 io_destroy(aio_context_t ctx) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
209 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
210 return syscall(SYS_io_destroy, ctx); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
211 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
212 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
213 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
214 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
215 io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
216 struct timespec *tmo) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
217 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
218 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
219 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
220 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
221 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
222 static void |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
223 ngx_epoll_aio_init(ngx_cycle_t *cycle, ngx_epoll_conf_t *epcf) |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
224 { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
225 int n; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
226 struct epoll_event ee; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
227 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
228 ngx_eventfd = syscall(SYS_eventfd, 0); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
229 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
230 if (ngx_eventfd == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
231 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
232 "eventfd() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
233 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
234 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
235 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
236 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
237 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
238 "eventfd: %d", ngx_eventfd); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
239 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
240 n = 1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
241 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
242 if (ioctl(ngx_eventfd, FIONBIO, &n) == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
243 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
244 "ioctl(eventfd, FIONBIO) failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
245 goto failed; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
246 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
247 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
248 if (io_setup(epcf->aio_requests, &ngx_aio_ctx) == -1) { |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
249 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
250 "io_setup() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
251 goto failed; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
252 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
253 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
254 ngx_eventfd_event.data = &ngx_eventfd_conn; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
255 ngx_eventfd_event.handler = ngx_epoll_eventfd_handler; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
256 ngx_eventfd_event.log = cycle->log; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
257 ngx_eventfd_event.active = 1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
258 ngx_eventfd_conn.fd = ngx_eventfd; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
259 ngx_eventfd_conn.read = &ngx_eventfd_event; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
260 ngx_eventfd_conn.log = cycle->log; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
261 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
262 ee.events = EPOLLIN|EPOLLET; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
263 ee.data.ptr = &ngx_eventfd_conn; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
264 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
265 if (epoll_ctl(ep, EPOLL_CTL_ADD, ngx_eventfd, &ee) != -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
266 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
267 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
268 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
269 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
270 "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
271 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
272 if (io_destroy(ngx_aio_ctx) == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
273 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
274 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
275 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
276 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
277 failed: |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
278 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
279 if (close(ngx_eventfd) == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
280 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
281 "eventfd close() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
282 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
283 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
284 ngx_eventfd = -1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
285 ngx_aio_ctx = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
286 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
287 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
288 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
289 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
290 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
291 |
499 | 292 static ngx_int_t |
563 | 293 ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer) |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
295 ngx_epoll_conf_t *epcf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
299 if (ep == -1) { |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
300 ep = epoll_create(cycle->connection_n / 2); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 if (ep == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
304 "epoll_create() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
305 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 } |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
307 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
308 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
309 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
310 ngx_epoll_aio_init(cycle, epcf); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
311 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
312 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
313 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
314 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 if (nevents < epcf->events) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
316 if (event_list) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
317 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
318 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
319 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
320 event_list = ngx_alloc(sizeof(struct epoll_event) * epcf->events, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
321 cycle->log); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
322 if (event_list == NULL) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
323 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
324 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
326 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
327 nevents = epcf->events; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
328 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
329 ngx_io = ngx_os_io; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
330 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
331 ngx_event_actions = ngx_epoll_module_ctx.actions; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 |
469 | 333 #if (NGX_HAVE_CLEAR_EVENT) |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
334 ngx_event_flags = NGX_USE_CLEAR_EVENT |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
335 #else |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
336 ngx_event_flags = NGX_USE_LEVEL_EVENT |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
337 #endif |
455 | 338 |NGX_USE_GREEDY_EVENT |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
339 |NGX_USE_EPOLL_EVENT; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
340 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
341 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
342 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
343 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
344 |
499 | 345 static void |
346 ngx_epoll_done(ngx_cycle_t *cycle) | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
347 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
348 if (close(ep) == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
349 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 "epoll close() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
351 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
355 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
356 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
357 if (ngx_eventfd != -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
358 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
359 if (io_destroy(ngx_aio_ctx) == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
360 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
361 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
362 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
363 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
364 if (close(ngx_eventfd) == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
365 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
366 "eventfd close() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
367 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
368 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
369 ngx_eventfd = -1; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
370 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
371 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
372 ngx_aio_ctx = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
373 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
374 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
375 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
376 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
377 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
378 event_list = NULL; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
379 nevents = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
380 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
381 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
382 |
499 | 383 static ngx_int_t |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
384 ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags) |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
385 { |
483 | 386 int op; |
387 uint32_t events, prev; | |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
388 ngx_event_t *e; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
389 ngx_connection_t *c; |
258
733dffa1fe97
nginx-0.0.2-2004-02-11-10:19:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
390 struct epoll_event ee; |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
391 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
392 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
393 |
483 | 394 events = (uint32_t) event; |
395 | |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
396 if (event == NGX_READ_EVENT) { |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
397 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
398 prev = EPOLLOUT; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
399 #if (NGX_READ_EVENT != EPOLLIN) |
483 | 400 events = EPOLLIN; |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
401 #endif |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
402 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
403 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
404 e = c->read; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
405 prev = EPOLLIN; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
406 #if (NGX_WRITE_EVENT != EPOLLOUT) |
483 | 407 events = EPOLLOUT; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
408 #endif |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
409 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
410 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
411 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
412 op = EPOLL_CTL_MOD; |
483 | 413 events |= prev; |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
414 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
415 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
416 op = EPOLL_CTL_ADD; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
417 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
418 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
419 ee.events = events | (uint32_t) flags; |
581 | 420 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
421 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
422 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 423 "epoll add event: fd:%d op:%d ev:%08XD", |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
424 c->fd, op, ee.events); |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
425 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
426 if (epoll_ctl(ep, op, c->fd, &ee) == -1) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
427 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
428 "epoll_ctl(%d, %d) failed", op, c->fd); |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
429 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
430 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
431 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
432 ev->active = 1; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
433 #if 0 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
434 ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
435 #endif |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
436 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
437 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
438 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
439 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
440 |
499 | 441 static ngx_int_t |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
442 ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags) |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
443 { |
483 | 444 int op; |
445 uint32_t prev; | |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
446 ngx_event_t *e; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
447 ngx_connection_t *c; |
258
733dffa1fe97
nginx-0.0.2-2004-02-11-10:19:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
448 struct epoll_event ee; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
449 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
450 /* |
483 | 451 * when the file descriptor is closed, the epoll automatically deletes |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
452 * it from its queue, so we do not need to delete explicitly the event |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
453 * before the closing the file descriptor |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
454 */ |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
455 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
456 if (flags & NGX_CLOSE_EVENT) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
457 ev->active = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
458 return NGX_OK; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
459 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
460 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
461 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
462 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
463 if (event == NGX_READ_EVENT) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
464 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
465 prev = EPOLLOUT; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
466 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
467 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
468 e = c->read; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
469 prev = EPOLLIN; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
470 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
471 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
472 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
473 op = EPOLL_CTL_MOD; |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
474 ee.events = prev | (uint32_t) flags; |
581 | 475 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
476 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
477 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
478 op = EPOLL_CTL_DEL; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
479 ee.events = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
480 ee.data.ptr = NULL; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
481 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
482 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
483 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 484 "epoll del event: fd:%d op:%d ev:%08XD", |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
485 c->fd, op, ee.events); |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
486 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
487 if (epoll_ctl(ep, op, c->fd, &ee) == -1) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
488 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
489 "epoll_ctl(%d, %d) failed", op, c->fd); |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
490 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
491 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
492 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
493 ev->active = 0; |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
494 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
495 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
496 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
497 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
498 |
499 | 499 static ngx_int_t |
500 ngx_epoll_add_connection(ngx_connection_t *c) | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
501 { |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
502 struct epoll_event ee; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
503 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
504 ee.events = EPOLLIN|EPOLLOUT|EPOLLET; |
581 | 505 ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
506 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
507 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
461 | 508 "epoll add connection: fd:%d ev:%08XD", c->fd, ee.events); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
509 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
510 if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) { |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
511 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
512 "epoll_ctl(EPOLL_CTL_ADD, %d) failed", c->fd); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
513 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
514 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
515 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
516 c->read->active = 1; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
517 c->write->active = 1; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
518 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
519 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
520 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
521 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
522 |
499 | 523 static ngx_int_t |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
524 ngx_epoll_del_connection(ngx_connection_t *c, ngx_uint_t flags) |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
525 { |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
526 int op; |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
527 struct epoll_event ee; |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
528 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
529 /* |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
530 * when the file descriptor is closed the epoll automatically deletes |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
531 * it from its queue so we do not need to delete explicitly the event |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
532 * before the closing the file descriptor |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
533 */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
534 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
535 if (flags & NGX_CLOSE_EVENT) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
536 c->read->active = 0; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
537 c->write->active = 0; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
538 return NGX_OK; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
539 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
540 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
541 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
542 "epoll del connection: fd:%d", c->fd); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
543 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
544 op = EPOLL_CTL_DEL; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
545 ee.events = 0; |
581 | 546 ee.data.ptr = NULL; |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
547 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
548 if (epoll_ctl(ep, op, c->fd, &ee) == -1) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
549 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
550 "epoll_ctl(%d, %d) failed", op, c->fd); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
551 return NGX_ERROR; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
552 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
553 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
554 c->read->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
555 c->write->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
556 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
557 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
558 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
559 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
560 |
499 | 561 static ngx_int_t |
563 | 562 ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
563 { |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
564 int events; |
483 | 565 uint32_t revents; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
566 ngx_int_t instance, i; |
563 | 567 ngx_uint_t level; |
309
2e899477243a
nginx-0.0.3-2004-04-09-20:03:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
568 ngx_err_t err; |
563 | 569 ngx_event_t *rev, *wev, **queue; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
570 ngx_connection_t *c; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
571 |
316
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
572 /* NGX_TIMER_INFINITE == INFTIM */ |
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
573 |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
259
diff
changeset
|
574 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
557 | 575 "epoll timer: %M", timer); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
576 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
577 events = epoll_wait(ep, event_list, (int) nevents, timer); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
578 |
3043 | 579 err = (events == -1) ? ngx_errno : 0; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
580 |
3473
0299cf5856fc
do not update time in the timer signal handler,
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
581 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
582 ngx_time_update(); |
563 | 583 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
584 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
585 if (err) { |
563 | 586 if (err == NGX_EINTR) { |
587 | |
588 if (ngx_event_timer_alarm) { | |
589 ngx_event_timer_alarm = 0; | |
590 return NGX_OK; | |
591 } | |
577 | 592 |
563 | 593 level = NGX_LOG_INFO; |
577 | 594 |
595 } else { | |
563 | 596 level = NGX_LOG_ALERT; |
597 } | |
598 | |
599 ngx_log_error(level, cycle->log, err, "epoll_wait() failed"); | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
600 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
601 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
602 |
563 | 603 if (events == 0) { |
567 | 604 if (timer != NGX_TIMER_INFINITE) { |
605 return NGX_OK; | |
606 } | |
607 | |
608 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
609 "epoll_wait() returned no events without timeout"); | |
610 return NGX_ERROR; | |
563 | 611 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
612 |
563 | 613 ngx_mutex_lock(ngx_posted_events_mutex); |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
614 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
615 for (i = 0; i < events; i++) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
616 c = event_list[i].data.ptr; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
617 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
618 instance = (uintptr_t) c & 1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
619 c = (ngx_connection_t *) ((uintptr_t) c & (uintptr_t) ~1); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
620 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
621 rev = c->read; |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
259
diff
changeset
|
622 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
623 if (c->fd == -1 || rev->instance != instance) { |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
624 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
625 /* |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
626 * the stale event from a file descriptor |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
627 * that was just closed in this iteration |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
628 */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
629 |
312
f5431a4bbc7d
nginx-0.0.3-2004-04-13-09:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
630 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 631 "epoll: stale event %p", c); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
632 continue; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
633 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
634 |
483 | 635 revents = event_list[i].events; |
636 | |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
637 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 638 "epoll: fd:%d ev:%04XD d:%p", |
577 | 639 c->fd, revents, event_list[i].data.ptr); |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
640 |
483 | 641 if (revents & (EPOLLERR|EPOLLHUP)) { |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
642 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 643 "epoll_wait() error on fd:%d ev:%04XD", |
483 | 644 c->fd, revents); |
645 } | |
646 | |
663 | 647 #if 0 |
483 | 648 if (revents & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
649 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
483 | 650 "strange epoll_wait() events fd:%d ev:%04XD", |
651 c->fd, revents); | |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
652 } |
663 | 653 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
654 |
483 | 655 if ((revents & (EPOLLERR|EPOLLHUP)) |
656 && (revents & (EPOLLIN|EPOLLOUT)) == 0) | |
657 { | |
658 /* | |
659 * if the error events were returned without EPOLLIN or EPOLLOUT, | |
660 * then add these flags to handle the events at least in one | |
661 * active handler | |
662 */ | |
663 | |
664 revents |= EPOLLIN|EPOLLOUT; | |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
665 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
666 |
563 | 667 if ((revents & EPOLLIN) && rev->active) { |
668 | |
669 if ((flags & NGX_POST_THREAD_EVENTS) && !rev->accept) { | |
670 rev->posted_ready = 1; | |
671 | |
672 } else { | |
673 rev->ready = 1; | |
674 } | |
675 | |
676 if (flags & NGX_POST_EVENTS) { | |
677 queue = (ngx_event_t **) (rev->accept ? | |
678 &ngx_posted_accept_events : &ngx_posted_events); | |
679 | |
680 ngx_locked_post_event(rev, queue); | |
681 | |
682 } else { | |
683 rev->handler(rev); | |
684 } | |
685 } | |
686 | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
687 wev = c->write; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
688 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
689 if ((revents & EPOLLOUT) && wev->active) { |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
690 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
691 if (c->fd == -1 || wev->instance != instance) { |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
692 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
693 /* |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
694 * the stale event from a file descriptor |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
695 * that was just closed in this iteration |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
696 */ |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
697 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
698 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
699 "epoll: stale event %p", c); |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
700 continue; |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
701 } |
483 | 702 |
563 | 703 if (flags & NGX_POST_THREAD_EVENTS) { |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
704 wev->posted_ready = 1; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
705 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
706 } else { |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
707 wev->ready = 1; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
708 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
709 |
563 | 710 if (flags & NGX_POST_EVENTS) { |
711 ngx_locked_post_event(wev, &ngx_posted_events); | |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
712 |
563 | 713 } else { |
714 wev->handler(wev); | |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
715 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
716 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
717 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
718 |
563 | 719 ngx_mutex_unlock(ngx_posted_events_mutex); |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
720 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
721 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
722 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
723 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
724 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
725 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
726 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
727 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
728 ngx_epoll_eventfd_handler(ngx_event_t *ev) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
729 { |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
730 int n, events; |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
731 long i; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
732 uint64_t ready; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
733 ngx_err_t err; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
734 ngx_event_t *e; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
735 ngx_event_aio_t *aio; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
736 struct io_event event[64]; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
737 struct timespec ts; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
738 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
739 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "eventfd handler"); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
740 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
741 n = read(ngx_eventfd, &ready, 8); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
742 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
743 err = ngx_errno; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
744 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
745 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, "eventfd: %d", n); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
746 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
747 if (n != 8) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
748 if (n == -1) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
749 if (err == NGX_EAGAIN) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
750 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
751 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
752 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
753 ngx_log_error(NGX_LOG_ALERT, ev->log, err, "read(eventfd) failed"); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
754 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
755 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
756 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
757 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
758 "read(eventfd) returned only %d bytes", n); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
759 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
760 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
761 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
762 ts.tv_sec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
763 ts.tv_nsec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
764 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
765 while (ready) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
766 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
767 events = io_getevents(ngx_aio_ctx, 1, 64, event, &ts); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
768 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
769 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
770 "io_getevents: %l", events); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
771 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
772 if (events > 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
773 ready -= events; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
774 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
775 for (i = 0; i < events; i++) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
776 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
777 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
778 "io_event: %uXL %uXL %L %L", |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
779 event[i].data, event[i].obj, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
780 event[i].res, event[i].res2); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
781 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
782 e = (ngx_event_t *) (uintptr_t) event[i].data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
783 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
784 e->complete = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
785 e->active = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
786 e->ready = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
787 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
788 aio = e->data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
789 aio->res = event[i].res; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
790 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
791 ngx_post_event(e, &ngx_posted_events); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
792 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
793 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
794 continue; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
795 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
796 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
797 if (events == 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
798 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
799 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
800 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
801 /* events == -1 */ |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
802 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
803 "io_getevents() failed"); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
804 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
805 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
806 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
807 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
808 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
809 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
810 |
499 | 811 static void * |
812 ngx_epoll_create_conf(ngx_cycle_t *cycle) | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
813 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
814 ngx_epoll_conf_t *epcf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
815 |
501 | 816 epcf = ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t)); |
817 if (epcf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2062
diff
changeset
|
818 return NULL; |
501 | 819 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
820 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
821 epcf->events = NGX_CONF_UNSET; |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
822 epcf->aio_requests = NGX_CONF_UNSET; |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
823 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
824 return epcf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
825 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
826 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
827 |
499 | 828 static char * |
829 ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf) | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
830 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
831 ngx_epoll_conf_t *epcf = conf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
832 |
663 | 833 ngx_conf_init_uint_value(epcf->events, 512); |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
834 ngx_conf_init_uint_value(epcf->aio_requests, 32); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
835 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
836 return NGX_CONF_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
837 } |