Mercurial > hg > nginx
annotate src/event/modules/ngx_epoll_module.c @ 7851:aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Previously, anything with any of the two high bits set were interpreted
as compression pointers. This is incorrect, as RFC 1035 clearly states
that "The 10 and 01 combinations are reserved for future use". Further,
the 01 combination is actually allocated for EDNS extended label type
(see RFC 2671 and RFC 6891), not really used though.
Fix is to reject unrecognized label types rather than misinterpreting
them as compression pointers.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 May 2021 15:17:41 +0300 |
parents | efd71d49bde0 |
children | 0ad3dde83947 |
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 |
6634
18f6120e3b7a
Style: sorted epoll flags.
Valentin Bartenev <vbart@nginx.com>
parents:
6542
diff
changeset
|
20 #define EPOLLERR 0x008 |
18f6120e3b7a
Style: sorted epoll flags.
Valentin Bartenev <vbart@nginx.com>
parents:
6542
diff
changeset
|
21 #define EPOLLHUP 0x010 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
22 #define EPOLLRDNORM 0x040 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
23 #define EPOLLRDBAND 0x080 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
24 #define EPOLLWRNORM 0x100 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
25 #define EPOLLWRBAND 0x200 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
26 #define EPOLLMSG 0x400 |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
27 |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
28 #define EPOLLRDHUP 0x2000 |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
29 |
6635
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
30 #define EPOLLEXCLUSIVE 0x10000000 |
6634
18f6120e3b7a
Style: sorted epoll flags.
Valentin Bartenev <vbart@nginx.com>
parents:
6542
diff
changeset
|
31 #define EPOLLONESHOT 0x40000000 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
32 #define EPOLLET 0x80000000 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 #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
|
35 #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
|
36 #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
|
37 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 typedef union epoll_data { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 void *ptr; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 int fd; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 uint32_t u32; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 uint64_t u64; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 } epoll_data_t; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 struct epoll_event { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 uint32_t events; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 epoll_data_t data; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
50 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
51 int epoll_create(int size); |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
52 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 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
|
54 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
58 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
59 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
|
60 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 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
|
62 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
66 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
67 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
|
68 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 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
|
70 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 return -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
74 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
75 #define SYS_eventfd 323 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
76 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
77 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
78 #if (NGX_HAVE_FILE_AIO) |
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 #define SYS_io_setup 245 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
81 #define SYS_io_destroy 246 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
82 #define SYS_io_getevents 247 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
83 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
84 typedef u_int aio_context_t; |
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 struct io_event { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
87 uint64_t data; /* the data field from the iocb */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
88 uint64_t obj; /* what iocb this event came from */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
89 int64_t res; /* result code for this event */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
90 int64_t res2; /* secondary result */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
91 }; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
92 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
93 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
94 #endif |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
95 #endif /* 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
|
96 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 typedef struct { |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
99 ngx_uint_t events; |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
100 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
|
101 } ngx_epoll_conf_t; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
563 | 104 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer); |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
105 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
106 static ngx_int_t ngx_epoll_notify_init(ngx_log_t *log); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
107 static void ngx_epoll_notify_handler(ngx_event_t *ev); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
108 #endif |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
109 #if (NGX_HAVE_EPOLLRDHUP) |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
110 static void ngx_epoll_test_rdhup(ngx_cycle_t *cycle); |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
111 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 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
|
113 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
|
114 ngx_uint_t flags); |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
115 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
|
116 ngx_uint_t flags); |
499 | 117 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
|
118 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
|
119 ngx_uint_t flags); |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
120 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
121 static ngx_int_t ngx_epoll_notify(ngx_event_handler_pt handler); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
122 #endif |
563 | 123 static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
124 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
|
125 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
126 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
127 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
|
128 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
129 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 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
|
131 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
|
132 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 static int ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 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
|
135 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
|
136 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
137 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
138 static int notify_fd = -1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
139 static ngx_event_t notify_event; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
140 static ngx_connection_t notify_conn; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
141 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
142 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
143 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
144 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
145 int ngx_eventfd = -1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
146 aio_context_t ngx_aio_ctx = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
147 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
148 static ngx_event_t ngx_eventfd_event; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
149 static ngx_connection_t ngx_eventfd_conn; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
150 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
151 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
153 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
154 ngx_uint_t ngx_use_epoll_rdhup; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
155 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
156 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 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
|
158 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 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
|
160 |
499 | 161 { ngx_string("epoll_events"), |
162 NGX_EVENT_CONF|NGX_CONF_TAKE1, | |
163 ngx_conf_set_num_slot, | |
164 0, | |
165 offsetof(ngx_epoll_conf_t, events), | |
166 NULL }, | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
168 { ngx_string("worker_aio_requests"), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
169 NGX_EVENT_CONF|NGX_CONF_TAKE1, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
170 ngx_conf_set_num_slot, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
171 0, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
172 offsetof(ngx_epoll_conf_t, aio_requests), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
173 NULL }, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
174 |
499 | 175 ngx_null_command |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6806
diff
changeset
|
179 static ngx_event_module_t ngx_epoll_module_ctx = { |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 &epoll_name, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 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
|
182 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
|
183 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 { |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 ngx_epoll_del_connection, /* delete an connection */ |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
191 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
192 ngx_epoll_notify, /* trigger a notify */ |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
193 #else |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
194 NULL, /* trigger a notify */ |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
195 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 ngx_module_t ngx_epoll_module = { |
509 | 203 NGX_MODULE_V1, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 &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
|
205 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
|
206 NGX_EVENT_MODULE, /* module type */ |
541 | 207 NULL, /* init master */ |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
208 NULL, /* init module */ |
541 | 209 NULL, /* init process */ |
210 NULL, /* init thread */ | |
211 NULL, /* exit thread */ | |
212 NULL, /* exit process */ | |
213 NULL, /* exit master */ | |
214 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
|
215 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
218 #if (NGX_HAVE_FILE_AIO) |
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 /* |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
221 * 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
|
222 * 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
|
223 * supports eventfd() since 0.3.107 version only. |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
224 */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
225 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
226 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
227 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
|
228 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
229 return syscall(SYS_io_setup, nr_reqs, ctx); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
230 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
231 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
232 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
233 static int |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
234 io_destroy(aio_context_t ctx) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
235 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
236 return syscall(SYS_io_destroy, ctx); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
237 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
238 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
239 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
240 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
241 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
|
242 struct timespec *tmo) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
243 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
244 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
|
245 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
246 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
247 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
248 static void |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
249 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
|
250 { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
251 int n; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
252 struct epoll_event ee; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
253 |
5707
31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
Ruslan Ermilov <ru@nginx.com>
parents:
5372
diff
changeset
|
254 #if (NGX_HAVE_SYS_EVENTFD_H) |
31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
Ruslan Ermilov <ru@nginx.com>
parents:
5372
diff
changeset
|
255 ngx_eventfd = eventfd(0, 0); |
31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
Ruslan Ermilov <ru@nginx.com>
parents:
5372
diff
changeset
|
256 #else |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
257 ngx_eventfd = syscall(SYS_eventfd, 0); |
5707
31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
Ruslan Ermilov <ru@nginx.com>
parents:
5372
diff
changeset
|
258 #endif |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
259 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
260 if (ngx_eventfd == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
261 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
|
262 "eventfd() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
263 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
264 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
265 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
266 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
267 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
|
268 "eventfd: %d", ngx_eventfd); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
269 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
270 n = 1; |
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 (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
|
273 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
|
274 "ioctl(eventfd, FIONBIO) failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
275 goto failed; |
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 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
278 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
|
279 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
|
280 "io_setup() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
281 goto 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_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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
292 ee.events = EPOLLIN|EPOLLET; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
293 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
|
294 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
295 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
|
296 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
297 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
298 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
299 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
|
300 "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
|
301 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
302 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
|
303 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
|
304 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
305 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
306 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
307 failed: |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
308 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
309 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
|
310 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
|
311 "eventfd close() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
312 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
313 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
314 ngx_eventfd = -1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
315 ngx_aio_ctx = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
316 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
317 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
318 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
319 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
320 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
321 |
499 | 322 static ngx_int_t |
563 | 323 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
|
324 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 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
|
326 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
327 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
|
328 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
329 if (ep == -1) { |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
330 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
|
331 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 if (ep == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 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
|
334 "epoll_create() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
335 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
336 } |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
337 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
338 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
339 if (ngx_epoll_notify_init(cycle->log) != NGX_OK) { |
6144
d0a84ae2fb48
Events: made a failure to create a notification channel non-fatal.
Ruslan Ermilov <ru@nginx.com>
parents:
6061
diff
changeset
|
340 ngx_epoll_module_ctx.actions.notify = NULL; |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
341 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
342 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
343 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
344 #if (NGX_HAVE_FILE_AIO) |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
345 ngx_epoll_aio_init(cycle, epcf); |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
346 #endif |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
347 |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
348 #if (NGX_HAVE_EPOLLRDHUP) |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
349 ngx_epoll_test_rdhup(cycle); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
350 #endif |
245
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 if (nevents < epcf->events) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 if (event_list) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
355 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
357 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
358 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
|
359 cycle->log); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
360 if (event_list == NULL) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
361 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
362 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
363 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
364 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
365 nevents = epcf->events; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
366 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
367 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
|
368 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
369 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
|
370 |
469 | 371 #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
|
372 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
|
373 #else |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
374 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
|
375 #endif |
455 | 376 |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
|
377 |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
|
378 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
379 return NGX_OK; |
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 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
383 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
384 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
385 static ngx_int_t |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
386 ngx_epoll_notify_init(ngx_log_t *log) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
387 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
388 struct epoll_event ee; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
389 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
390 #if (NGX_HAVE_SYS_EVENTFD_H) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
391 notify_fd = eventfd(0, 0); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
392 #else |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
393 notify_fd = syscall(SYS_eventfd, 0); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
394 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
395 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
396 if (notify_fd == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
397 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "eventfd() failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
398 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
399 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
400 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
401 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
402 "notify eventfd: %d", notify_fd); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
403 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
404 notify_event.handler = ngx_epoll_notify_handler; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
405 notify_event.log = log; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
406 notify_event.active = 1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
407 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
408 notify_conn.fd = notify_fd; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
409 notify_conn.read = ¬ify_event; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
410 notify_conn.log = log; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
411 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
412 ee.events = EPOLLIN|EPOLLET; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
413 ee.data.ptr = ¬ify_conn; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
414 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
415 if (epoll_ctl(ep, EPOLL_CTL_ADD, notify_fd, &ee) == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
416 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
417 "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
418 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
419 if (close(notify_fd) == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
420 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
421 "eventfd close() failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
422 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
423 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
424 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
425 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
426 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
427 return NGX_OK; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
428 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
429 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
430 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
431 static void |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
432 ngx_epoll_notify_handler(ngx_event_t *ev) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
433 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
434 ssize_t n; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
435 uint64_t count; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
436 ngx_err_t err; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
437 ngx_event_handler_pt handler; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
438 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
439 if (++ev->index == NGX_MAX_UINT32_VALUE) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
440 ev->index = 0; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
441 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
442 n = read(notify_fd, &count, sizeof(uint64_t)); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
443 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
444 err = ngx_errno; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
445 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
446 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
447 "read() eventfd %d: %z count:%uL", notify_fd, n, count); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
448 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
449 if ((size_t) n != sizeof(uint64_t)) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
450 ngx_log_error(NGX_LOG_ALERT, ev->log, err, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
451 "read() eventfd %d failed", notify_fd); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
452 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
453 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
454 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
455 handler = ev->data; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
456 handler(ev); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
457 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
458 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
459 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
460 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
461 |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
462 #if (NGX_HAVE_EPOLLRDHUP) |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
463 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
464 static void |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
465 ngx_epoll_test_rdhup(ngx_cycle_t *cycle) |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
466 { |
6541
282448777dc2
Events: changed ngx_epoll_test_rdhup() to use existing epollfd.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6540
diff
changeset
|
467 int s[2], events; |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
468 struct epoll_event ee; |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
469 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
470 if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) { |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
471 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
472 "socketpair() failed"); |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
473 return; |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
474 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
475 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
476 ee.events = EPOLLET|EPOLLIN|EPOLLRDHUP; |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
477 |
6541
282448777dc2
Events: changed ngx_epoll_test_rdhup() to use existing epollfd.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6540
diff
changeset
|
478 if (epoll_ctl(ep, EPOLL_CTL_ADD, s[0], &ee) == -1) { |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
479 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
480 "epoll_ctl() failed"); |
6542
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
481 goto failed; |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
482 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
483 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
484 if (close(s[1]) == -1) { |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
485 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
486 "close() failed"); |
6542
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
487 s[1] = -1; |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
488 goto failed; |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
489 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
490 |
6542
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
491 s[1] = -1; |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
492 |
6541
282448777dc2
Events: changed ngx_epoll_test_rdhup() to use existing epollfd.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6540
diff
changeset
|
493 events = epoll_wait(ep, &ee, 1, 5000); |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
494 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
495 if (events == -1) { |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
496 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
497 "epoll_wait() failed"); |
6542
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
498 goto failed; |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
499 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
500 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
501 if (events) { |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
502 ngx_use_epoll_rdhup = ee.events & EPOLLRDHUP; |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
503 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
504 } else { |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
505 ngx_log_error(NGX_LOG_ALERT, cycle->log, NGX_ETIMEDOUT, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
506 "epoll_wait() timed out"); |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
507 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
508 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
509 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
510 "testing the EPOLLRDHUP flag: %s", |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
511 ngx_use_epoll_rdhup ? "success" : "fail"); |
6542
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
512 |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
513 failed: |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
514 |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
515 if (s[1] != -1 && close(s[1]) == -1) { |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
516 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
517 "close() failed"); |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
518 } |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
519 |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
520 if (close(s[0]) == -1) { |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
521 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
522 "close() failed"); |
c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6541
diff
changeset
|
523 } |
6540
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
524 } |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
525 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
526 #endif |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
527 |
a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6537
diff
changeset
|
528 |
499 | 529 static void |
530 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
|
531 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
532 if (close(ep) == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
533 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
|
534 "epoll close() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
535 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
536 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
537 ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
538 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
539 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
540 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
541 if (close(notify_fd) == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
542 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
543 "eventfd close() failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
544 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
545 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
546 notify_fd = -1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
547 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
548 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
549 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
550 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
551 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
552 if (ngx_eventfd != -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
553 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
554 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
|
555 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
|
556 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
557 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
558 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
559 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
|
560 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
|
561 "eventfd close() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
562 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
563 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
564 ngx_eventfd = -1; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
565 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
566 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
567 ngx_aio_ctx = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
568 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
569 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
570 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
571 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
572 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
573 event_list = NULL; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
574 nevents = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
575 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
576 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
577 |
499 | 578 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
|
579 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
|
580 { |
483 | 581 int op; |
582 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
|
583 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
|
584 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
|
585 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
|
586 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
587 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
588 |
483 | 589 events = (uint32_t) event; |
590 | |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
591 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
|
592 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
593 prev = EPOLLOUT; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
594 #if (NGX_READ_EVENT != EPOLLIN|EPOLLRDHUP) |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
595 events = EPOLLIN|EPOLLRDHUP; |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
596 #endif |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
597 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
598 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
599 e = c->read; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
600 prev = EPOLLIN|EPOLLRDHUP; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
601 #if (NGX_WRITE_EVENT != EPOLLOUT) |
483 | 602 events = EPOLLOUT; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
603 #endif |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
604 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
605 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
606 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
607 op = EPOLL_CTL_MOD; |
483 | 608 events |= prev; |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
609 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
610 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
611 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
|
612 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
613 |
6635
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
614 #if (NGX_HAVE_EPOLLEXCLUSIVE && NGX_HAVE_EPOLLRDHUP) |
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
615 if (flags & NGX_EXCLUSIVE_EVENT) { |
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
616 events &= ~EPOLLRDHUP; |
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
617 } |
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
618 #endif |
6acaa638fa07
Events: support for EPOLLEXCLUSIVE.
Valentin Bartenev <vbart@nginx.com>
parents:
6634
diff
changeset
|
619 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
620 ee.events = events | (uint32_t) flags; |
581 | 621 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
|
622 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
623 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 624 "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
|
625 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
|
626 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
627 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
|
628 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
|
629 "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
|
630 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
631 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
632 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
633 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
|
634 #if 0 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
635 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
|
636 #endif |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
637 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
638 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
639 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
640 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
641 |
499 | 642 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
|
643 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
|
644 { |
483 | 645 int op; |
646 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
|
647 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
|
648 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
|
649 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
|
650 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
651 /* |
483 | 652 * 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
|
653 * 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
|
654 * 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
|
655 */ |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
656 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
657 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
|
658 ev->active = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
659 return NGX_OK; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
660 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
661 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
662 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
663 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
664 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
|
665 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
666 prev = EPOLLOUT; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
667 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
668 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
669 e = c->read; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
670 prev = EPOLLIN|EPOLLRDHUP; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
671 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
672 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
673 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
674 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
|
675 ee.events = prev | (uint32_t) flags; |
581 | 676 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
|
677 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
678 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
679 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
|
680 ee.events = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
681 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
|
682 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
683 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
684 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 685 "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
|
686 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
|
687 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
688 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
|
689 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
|
690 "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
|
691 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
692 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
693 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
694 ev->active = 0; |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
695 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
696 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
697 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
698 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
699 |
499 | 700 static ngx_int_t |
701 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
|
702 { |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
703 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
|
704 |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
705 ee.events = EPOLLIN|EPOLLOUT|EPOLLET|EPOLLRDHUP; |
581 | 706 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
|
707 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
708 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
461 | 709 "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
|
710 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
711 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
|
712 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
|
713 "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
|
714 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
715 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
716 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
717 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
|
718 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
|
719 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
720 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
721 } |
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 |
499 | 724 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
|
725 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
|
726 { |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
727 int op; |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
728 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
|
729 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
730 /* |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
731 * 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
|
732 * 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
|
733 * 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
|
734 */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
735 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
736 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
|
737 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
|
738 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
|
739 return NGX_OK; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
740 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
741 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
742 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
|
743 "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
|
744 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
745 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
|
746 ee.events = 0; |
581 | 747 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
|
748 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
749 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
|
750 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
|
751 "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
|
752 return NGX_ERROR; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
753 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
754 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
755 c->read->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
756 c->write->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
757 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
758 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
759 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
760 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
761 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
762 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
763 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
764 static ngx_int_t |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
765 ngx_epoll_notify(ngx_event_handler_pt handler) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
766 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
767 static uint64_t inc = 1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
768 |
6061
953ef81705e1
Events: fixed possible crash on start or reload.
Valentin Bartenev <vbart@nginx.com>
parents:
6030
diff
changeset
|
769 notify_event.data = handler; |
953ef81705e1
Events: fixed possible crash on start or reload.
Valentin Bartenev <vbart@nginx.com>
parents:
6030
diff
changeset
|
770 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
771 if ((size_t) write(notify_fd, &inc, sizeof(uint64_t)) != sizeof(uint64_t)) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
772 ngx_log_error(NGX_LOG_ALERT, notify_event.log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
773 "write() to eventfd %d failed", notify_fd); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
774 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
775 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
776 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
777 return NGX_OK; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
778 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
779 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
780 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
781 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
782 |
499 | 783 static ngx_int_t |
563 | 784 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
|
785 { |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
786 int events; |
483 | 787 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
|
788 ngx_int_t instance, i; |
563 | 789 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
|
790 ngx_err_t err; |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
791 ngx_event_t *rev, *wev; |
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
792 ngx_queue_t *queue; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
793 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
|
794 |
316
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
795 /* 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
|
796 |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
259
diff
changeset
|
797 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
557 | 798 "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
|
799 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
800 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
|
801 |
3043 | 802 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
|
803 |
3473
0299cf5856fc
do not update time in the timer signal handler,
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
804 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
|
805 ngx_time_update(); |
563 | 806 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
807 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
808 if (err) { |
563 | 809 if (err == NGX_EINTR) { |
810 | |
811 if (ngx_event_timer_alarm) { | |
812 ngx_event_timer_alarm = 0; | |
813 return NGX_OK; | |
814 } | |
577 | 815 |
563 | 816 level = NGX_LOG_INFO; |
577 | 817 |
818 } else { | |
563 | 819 level = NGX_LOG_ALERT; |
820 } | |
821 | |
822 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
|
823 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
824 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
825 |
563 | 826 if (events == 0) { |
567 | 827 if (timer != NGX_TIMER_INFINITE) { |
828 return NGX_OK; | |
829 } | |
830 | |
831 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
832 "epoll_wait() returned no events without timeout"); | |
833 return NGX_ERROR; | |
563 | 834 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
835 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
836 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
|
837 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
|
838 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
839 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
|
840 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
|
841 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
842 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
|
843 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
844 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
|
845 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
846 /* |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
847 * 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
|
848 * 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
|
849 */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
850 |
312
f5431a4bbc7d
nginx-0.0.3-2004-04-13-09:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
851 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 852 "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
|
853 continue; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
854 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
855 |
483 | 856 revents = event_list[i].events; |
857 | |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
858 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 859 "epoll: fd:%d ev:%04XD d:%p", |
577 | 860 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
|
861 |
483 | 862 if (revents & (EPOLLERR|EPOLLHUP)) { |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
863 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 864 "epoll_wait() error on fd:%d ev:%04XD", |
483 | 865 c->fd, revents); |
6806
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
866 |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
867 /* |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
868 * if the error events were returned, add EPOLLIN and EPOLLOUT |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
869 * to handle the events at least in one active handler |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
870 */ |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
871 |
75dbab4ea930
Events: improved error event handling for UDP sockets.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6635
diff
changeset
|
872 revents |= EPOLLIN|EPOLLOUT; |
483 | 873 } |
874 | |
663 | 875 #if 0 |
483 | 876 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
|
877 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
483 | 878 "strange epoll_wait() events fd:%d ev:%04XD", |
879 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
|
880 } |
663 | 881 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
882 |
563 | 883 if ((revents & EPOLLIN) && rev->active) { |
884 | |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
885 #if (NGX_HAVE_EPOLLRDHUP) |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
886 if (revents & EPOLLRDHUP) { |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
887 rev->pending_eof = 1; |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
888 } |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
889 #endif |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
890 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
891 rev->ready = 1; |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6922
diff
changeset
|
892 rev->available = -1; |
563 | 893 |
894 if (flags & NGX_POST_EVENTS) { | |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
895 queue = rev->accept ? &ngx_posted_accept_events |
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
896 : &ngx_posted_events; |
563 | 897 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
898 ngx_post_event(rev, queue); |
563 | 899 |
900 } else { | |
901 rev->handler(rev); | |
902 } | |
903 } | |
904 | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
905 wev = c->write; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
906 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
907 if ((revents & EPOLLOUT) && wev->active) { |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
908 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
909 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
|
910 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
911 /* |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
912 * the stale event from a file descriptor |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
913 * that was just closed in this iteration |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
914 */ |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
915 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
916 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
|
917 "epoll: stale event %p", c); |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
918 continue; |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
919 } |
483 | 920 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
921 wev->ready = 1; |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6144
diff
changeset
|
922 #if (NGX_THREADS) |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6144
diff
changeset
|
923 wev->complete = 1; |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6144
diff
changeset
|
924 #endif |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
925 |
563 | 926 if (flags & NGX_POST_EVENTS) { |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
927 ngx_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
|
928 |
563 | 929 } else { |
930 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
|
931 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
932 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
933 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
934 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
935 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
936 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
937 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
938 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
939 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
940 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
941 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
942 ngx_epoll_eventfd_handler(ngx_event_t *ev) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
943 { |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
944 int n, events; |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
945 long i; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
946 uint64_t ready; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
947 ngx_err_t err; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
948 ngx_event_t *e; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
949 ngx_event_aio_t *aio; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
950 struct io_event event[64]; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
951 struct timespec ts; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
952 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
953 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
|
954 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
955 n = read(ngx_eventfd, &ready, 8); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
956 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
957 err = ngx_errno; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
958 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
959 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
|
960 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
961 if (n != 8) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
962 if (n == -1) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
963 if (err == NGX_EAGAIN) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
964 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
965 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
966 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
967 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
|
968 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
969 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
970 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
971 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
972 "read(eventfd) returned only %d bytes", n); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
973 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
974 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
975 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
976 ts.tv_sec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
977 ts.tv_nsec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
978 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
979 while (ready) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
980 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
981 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
|
982 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
983 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6480 | 984 "io_getevents: %d", events); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
985 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
986 if (events > 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
987 ready -= events; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
988 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
989 for (i = 0; i < events; i++) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
990 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
991 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6509
7640d6c213e1
Removed redundant "u" format specifier.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
992 "io_event: %XL %XL %L %L", |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
993 event[i].data, event[i].obj, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
994 event[i].res, event[i].res2); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
995 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
996 e = (ngx_event_t *) (uintptr_t) event[i].data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
997 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
998 e->complete = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
999 e->active = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1000 e->ready = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1001 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1002 aio = e->data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1003 aio->res = event[i].res; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1004 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1005 ngx_post_event(e, &ngx_posted_events); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1006 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1007 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1008 continue; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1009 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1010 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1011 if (events == 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1012 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1013 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1014 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
1015 /* events == -1 */ |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
1016 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
|
1017 "io_getevents() failed"); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1018 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1019 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1020 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1021 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1022 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1023 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
1024 |
499 | 1025 static void * |
1026 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
|
1027 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1028 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
|
1029 |
501 | 1030 epcf = ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t)); |
1031 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
|
1032 return NULL; |
501 | 1033 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1034 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1035 epcf->events = NGX_CONF_UNSET; |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
1036 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
|
1037 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1038 return epcf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1039 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1040 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1041 |
499 | 1042 static char * |
1043 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
|
1044 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1045 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
|
1046 |
663 | 1047 ngx_conf_init_uint_value(epcf->events, 512); |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
1048 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
|
1049 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1050 return NGX_CONF_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1051 } |