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