Mercurial > hg > nginx-quic
annotate src/event/modules/ngx_epoll_module.c @ 6132:859ce1c41f64
Win32: fixed shm.handle loss on reload.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 27 Apr 2015 03:44:30 +0300 |
parents | 953ef81705e1 |
children | d0a84ae2fb48 |
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 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 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
|
109 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
|
110 ngx_uint_t flags); |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
111 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
|
112 ngx_uint_t flags); |
499 | 113 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
|
114 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
|
115 ngx_uint_t flags); |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
116 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
117 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
|
118 #endif |
563 | 119 static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
120 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
|
121 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
122 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
123 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
|
124 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
125 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 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
|
127 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
|
128 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 static int ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 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
|
131 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
|
132 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
133 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
134 static int notify_fd = -1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
135 static ngx_event_t notify_event; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
136 static ngx_connection_t notify_conn; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
137 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
138 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
139 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
140 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
141 int ngx_eventfd = -1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
142 aio_context_t ngx_aio_ctx = 0; |
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 static ngx_event_t ngx_eventfd_event; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
145 static ngx_connection_t ngx_eventfd_conn; |
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 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 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
|
150 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 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
|
152 |
499 | 153 { ngx_string("epoll_events"), |
154 NGX_EVENT_CONF|NGX_CONF_TAKE1, | |
155 ngx_conf_set_num_slot, | |
156 0, | |
157 offsetof(ngx_epoll_conf_t, events), | |
158 NULL }, | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
160 { ngx_string("worker_aio_requests"), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
161 NGX_EVENT_CONF|NGX_CONF_TAKE1, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
162 ngx_conf_set_num_slot, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
163 0, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
164 offsetof(ngx_epoll_conf_t, aio_requests), |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
165 NULL }, |
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
166 |
499 | 167 ngx_null_command |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 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
|
172 &epoll_name, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 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
|
174 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
|
175 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 { |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 ngx_epoll_del_connection, /* delete an connection */ |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
183 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
184 ngx_epoll_notify, /* trigger a notify */ |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
185 #else |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
186 NULL, /* trigger a notify */ |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
187 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 ngx_module_t ngx_epoll_module = { |
509 | 195 NGX_MODULE_V1, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 &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
|
197 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
|
198 NGX_EVENT_MODULE, /* module type */ |
541 | 199 NULL, /* init master */ |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
200 NULL, /* init module */ |
541 | 201 NULL, /* init process */ |
202 NULL, /* init thread */ | |
203 NULL, /* exit thread */ | |
204 NULL, /* exit process */ | |
205 NULL, /* exit master */ | |
206 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
|
207 }; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
210 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
211 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
212 /* |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
213 * 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
|
214 * 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
|
215 * supports eventfd() since 0.3.107 version only. |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
216 */ |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
217 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
218 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
219 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
|
220 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
221 return syscall(SYS_io_setup, nr_reqs, ctx); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
222 } |
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 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
225 static int |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
226 io_destroy(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_destroy, 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 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
232 static int |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
233 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
|
234 struct timespec *tmo) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
235 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
236 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo); |
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 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
239 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
240 static void |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
241 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
|
242 { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
243 int n; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
244 struct epoll_event ee; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
245 |
5707
31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
Ruslan Ermilov <ru@nginx.com>
parents:
5372
diff
changeset
|
246 #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
|
247 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
|
248 #else |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
249 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
|
250 #endif |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
251 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
252 if (ngx_eventfd == -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
253 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
|
254 "eventfd() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
255 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
256 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
257 } |
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 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
|
260 "eventfd: %d", ngx_eventfd); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
261 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
262 n = 1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
263 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
264 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
|
265 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
|
266 "ioctl(eventfd, FIONBIO) failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
267 goto failed; |
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 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
270 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
|
271 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
|
272 "io_setup() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
273 goto failed; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
274 } |
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 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
284 ee.events = EPOLLIN|EPOLLET; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
285 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
|
286 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
287 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
|
288 return; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
289 } |
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 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
|
292 "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
|
293 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
294 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
|
295 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
|
296 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
297 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
298 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
299 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 (close(ngx_eventfd) == -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 "eventfd close() 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 ngx_eventfd = -1; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
307 ngx_aio_ctx = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
308 ngx_file_aio = 0; |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
309 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
310 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
311 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
312 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
313 |
499 | 314 static ngx_int_t |
563 | 315 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
|
316 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
317 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
|
318 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
319 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
|
320 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
321 if (ep == -1) { |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
322 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
|
323 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
324 if (ep == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 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
|
326 "epoll_create() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
327 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
328 } |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
329 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
330 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
331 if (ngx_epoll_notify_init(cycle->log) != NGX_OK) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
332 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
333 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
334 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
335 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
336 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
337 |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
338 ngx_epoll_aio_init(cycle, epcf); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
339 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
340 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
341 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
342 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
343 if (nevents < epcf->events) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
344 if (event_list) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
345 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
346 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
347 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
348 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
|
349 cycle->log); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 if (event_list == NULL) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
351 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
355 nevents = epcf->events; |
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 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
|
358 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
359 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
|
360 |
469 | 361 #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
|
362 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
|
363 #else |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
364 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
|
365 #endif |
455 | 366 |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
|
367 |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
|
368 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
369 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
370 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
371 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
372 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
373 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
374 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
375 static ngx_int_t |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
376 ngx_epoll_notify_init(ngx_log_t *log) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
377 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
378 struct epoll_event ee; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
379 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
380 #if (NGX_HAVE_SYS_EVENTFD_H) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
381 notify_fd = eventfd(0, 0); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
382 #else |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
383 notify_fd = syscall(SYS_eventfd, 0); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
384 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
385 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
386 if (notify_fd == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
387 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
|
388 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
389 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
390 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
391 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
392 "notify eventfd: %d", notify_fd); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
393 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
394 notify_event.handler = ngx_epoll_notify_handler; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
395 notify_event.log = log; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
396 notify_event.active = 1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
397 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
398 notify_conn.fd = notify_fd; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
399 notify_conn.read = ¬ify_event; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
400 notify_conn.log = log; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
401 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
402 ee.events = EPOLLIN|EPOLLET; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
403 ee.data.ptr = ¬ify_conn; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
404 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
405 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
|
406 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
407 "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
408 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
409 if (close(notify_fd) == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
410 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
411 "eventfd close() failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
412 } |
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 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
415 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
416 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
417 return NGX_OK; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
418 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
419 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
420 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
421 static void |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
422 ngx_epoll_notify_handler(ngx_event_t *ev) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
423 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
424 ssize_t n; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
425 uint64_t count; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
426 ngx_err_t err; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
427 ngx_event_handler_pt handler; |
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 if (++ev->index == NGX_MAX_UINT32_VALUE) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
430 ev->index = 0; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
431 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
432 n = read(notify_fd, &count, sizeof(uint64_t)); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
433 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
434 err = ngx_errno; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
435 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
436 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
|
437 "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
|
438 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
439 if ((size_t) n != sizeof(uint64_t)) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
440 ngx_log_error(NGX_LOG_ALERT, ev->log, err, |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
441 "read() eventfd %d failed", notify_fd); |
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 } |
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 handler = ev->data; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
446 handler(ev); |
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 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
449 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
450 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
451 |
499 | 452 static void |
453 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
|
454 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
455 if (close(ep) == -1) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
456 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
|
457 "epoll close() failed"); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
458 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
459 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
460 ep = -1; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
461 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
462 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
463 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
464 if (close(notify_fd) == -1) { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
465 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
|
466 "eventfd close() failed"); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
467 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
468 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
469 notify_fd = -1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
470 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
471 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
472 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
473 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
474 |
4130
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
475 if (ngx_eventfd != -1) { |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
476 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
477 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
|
478 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
|
479 "io_destroy() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
480 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
481 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
482 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
|
483 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
|
484 "eventfd close() failed"); |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
485 } |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
486 |
04751572f900
Fixing Linux AIO initiatialization: AIO operations are disabled if kernel
Igor Sysoev <igor@sysoev.ru>
parents:
4129
diff
changeset
|
487 ngx_eventfd = -1; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
488 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
489 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
490 ngx_aio_ctx = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
491 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
492 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
493 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
494 ngx_free(event_list); |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
495 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
496 event_list = NULL; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
497 nevents = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
498 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
499 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
500 |
499 | 501 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
|
502 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
|
503 { |
483 | 504 int op; |
505 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
|
506 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
|
507 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
|
508 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
|
509 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
510 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
511 |
483 | 512 events = (uint32_t) event; |
513 | |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
514 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
|
515 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
516 prev = EPOLLOUT; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
517 #if (NGX_READ_EVENT != EPOLLIN|EPOLLRDHUP) |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
518 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
|
519 #endif |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
520 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
521 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
522 e = c->read; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
523 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
|
524 #if (NGX_WRITE_EVENT != EPOLLOUT) |
483 | 525 events = EPOLLOUT; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
526 #endif |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
527 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
528 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
529 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
530 op = EPOLL_CTL_MOD; |
483 | 531 events |= prev; |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
532 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
533 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
534 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
|
535 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
536 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
537 ee.events = events | (uint32_t) flags; |
581 | 538 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
|
539 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
540 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 541 "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
|
542 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
|
543 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
544 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
|
545 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
|
546 "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
|
547 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
548 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
549 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
550 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
|
551 #if 0 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
552 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
|
553 #endif |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
554 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
555 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
556 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
557 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
558 |
499 | 559 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
|
560 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
|
561 { |
483 | 562 int op; |
563 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
|
564 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
|
565 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
|
566 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
|
567 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
568 /* |
483 | 569 * 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
|
570 * 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
|
571 * 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
|
572 */ |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
573 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
574 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
|
575 ev->active = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
576 return NGX_OK; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
577 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
578 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
579 c = ev->data; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
580 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
581 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
|
582 e = c->write; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
583 prev = EPOLLOUT; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
584 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
585 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
586 e = c->read; |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
587 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
|
588 } |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
589 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
590 if (e->active) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
591 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
|
592 ee.events = prev | (uint32_t) flags; |
581 | 593 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
|
594 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
595 } else { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
596 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
|
597 ee.events = 0; |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
598 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
|
599 } |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
600 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
601 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
461 | 602 "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
|
603 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
|
604 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
258
diff
changeset
|
605 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
|
606 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
|
607 "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
|
608 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
609 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
610 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
611 ev->active = 0; |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
612 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
613 return NGX_OK; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
614 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
615 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
616 |
499 | 617 static ngx_int_t |
618 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
|
619 { |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
620 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
|
621 |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
622 ee.events = EPOLLIN|EPOLLOUT|EPOLLET|EPOLLRDHUP; |
581 | 623 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
|
624 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
625 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
461 | 626 "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
|
627 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
628 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
|
629 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
|
630 "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
|
631 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
632 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
633 |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
634 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
|
635 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
|
636 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
637 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
638 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
639 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
640 |
499 | 641 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
|
642 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
|
643 { |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
644 int op; |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
645 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
|
646 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
647 /* |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
648 * 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
|
649 * 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
|
650 * 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
|
651 */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
652 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 return NGX_OK; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
657 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
658 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
659 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
|
660 "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
|
661 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
662 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
|
663 ee.events = 0; |
581 | 664 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
|
665 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
666 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
|
667 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
|
668 "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
|
669 return NGX_ERROR; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
670 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
671 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
672 c->read->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
673 c->write->active = 0; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
674 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
675 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
676 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
677 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
678 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
679 #if (NGX_HAVE_EVENTFD) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
680 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
681 static ngx_int_t |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
682 ngx_epoll_notify(ngx_event_handler_pt handler) |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
683 { |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
684 static uint64_t inc = 1; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
685 |
6061
953ef81705e1
Events: fixed possible crash on start or reload.
Valentin Bartenev <vbart@nginx.com>
parents:
6030
diff
changeset
|
686 notify_event.data = handler; |
953ef81705e1
Events: fixed possible crash on start or reload.
Valentin Bartenev <vbart@nginx.com>
parents:
6030
diff
changeset
|
687 |
6019
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
688 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
|
689 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
|
690 "write() to eventfd %d failed", notify_fd); |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
691 return NGX_ERROR; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
692 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
693 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
694 return NGX_OK; |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
695 } |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
696 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
697 #endif |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
698 |
40e244e042a7
Events: implemented epoll notification mechanism.
Valentin Bartenev <vbart@nginx.com>
parents:
6018
diff
changeset
|
699 |
499 | 700 static ngx_int_t |
563 | 701 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
|
702 { |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
703 int events; |
483 | 704 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
|
705 ngx_int_t instance, i; |
563 | 706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 |
316
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
712 /* 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
|
713 |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
259
diff
changeset
|
714 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
557 | 715 "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
|
716 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
663
diff
changeset
|
717 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
|
718 |
3043 | 719 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
|
720 |
3473
0299cf5856fc
do not update time in the timer signal handler,
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
721 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
|
722 ngx_time_update(); |
563 | 723 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
724 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
725 if (err) { |
563 | 726 if (err == NGX_EINTR) { |
727 | |
728 if (ngx_event_timer_alarm) { | |
729 ngx_event_timer_alarm = 0; | |
730 return NGX_OK; | |
731 } | |
577 | 732 |
563 | 733 level = NGX_LOG_INFO; |
577 | 734 |
735 } else { | |
563 | 736 level = NGX_LOG_ALERT; |
737 } | |
738 | |
739 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
|
740 return NGX_ERROR; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
741 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
742 |
563 | 743 if (events == 0) { |
567 | 744 if (timer != NGX_TIMER_INFINITE) { |
745 return NGX_OK; | |
746 } | |
747 | |
748 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
749 "epoll_wait() returned no events without timeout"); | |
750 return NGX_ERROR; | |
563 | 751 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
752 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
753 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
|
754 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
|
755 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
756 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
|
757 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
|
758 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
759 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
|
760 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
761 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
|
762 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
763 /* |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
764 * 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
|
765 * 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
|
766 */ |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
767 |
312
f5431a4bbc7d
nginx-0.0.3-2004-04-13-09:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
768 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 769 "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
|
770 continue; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
771 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
772 |
483 | 773 revents = event_list[i].events; |
774 | |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
775 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 776 "epoll: fd:%d ev:%04XD d:%p", |
577 | 777 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
|
778 |
483 | 779 if (revents & (EPOLLERR|EPOLLHUP)) { |
3902
159b58f9c0bd
fix building by gcc 4.6 without --with-debug
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
780 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 781 "epoll_wait() error on fd:%d ev:%04XD", |
483 | 782 c->fd, revents); |
783 } | |
784 | |
663 | 785 #if 0 |
483 | 786 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
|
787 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
483 | 788 "strange epoll_wait() events fd:%d ev:%04XD", |
789 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
|
790 } |
663 | 791 #endif |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
792 |
483 | 793 if ((revents & (EPOLLERR|EPOLLHUP)) |
794 && (revents & (EPOLLIN|EPOLLOUT)) == 0) | |
795 { | |
796 /* | |
797 * if the error events were returned without EPOLLIN or EPOLLOUT, | |
798 * then add these flags to handle the events at least in one | |
799 * active handler | |
800 */ | |
801 | |
802 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
|
803 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
804 |
563 | 805 if ((revents & EPOLLIN) && rev->active) { |
806 | |
5372
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
807 #if (NGX_HAVE_EPOLLRDHUP) |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
808 if (revents & EPOLLRDHUP) { |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
809 rev->pending_eof = 1; |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
810 } |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
811 #endif |
36b58ddb566d
Events: support for EPOLLRDHUP (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
812 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
813 rev->ready = 1; |
563 | 814 |
815 if (flags & NGX_POST_EVENTS) { | |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
816 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
|
817 : &ngx_posted_events; |
563 | 818 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
819 ngx_post_event(rev, queue); |
563 | 820 |
821 } else { | |
822 rev->handler(rev); | |
823 } | |
824 } | |
825 | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
826 wev = c->write; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
827 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
828 if ((revents & EPOLLOUT) && wev->active) { |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
829 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
830 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
|
831 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
832 /* |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
833 * the stale event from a file descriptor |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
834 * that was just closed in this iteration |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
835 */ |
4305
f68047884e83
Protection from stale write events in epoll.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4134
diff
changeset
|
836 |
4319
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
837 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
|
838 "epoll: stale event %p", c); |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
839 continue; |
f40541f7afb5
Fixed AIO on Linux, broken in r4306.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4305
diff
changeset
|
840 } |
483 | 841 |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
842 wev->ready = 1; |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
843 |
563 | 844 if (flags & NGX_POST_EVENTS) { |
5820
3377f9459e99
Events: removed broken thread support from posted events.
Valentin Bartenev <vbart@nginx.com>
parents:
5707
diff
changeset
|
845 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
|
846 |
563 | 847 } else { |
848 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
|
849 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
850 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
851 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
852 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
853 return NGX_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
854 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
855 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
856 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
857 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
858 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
859 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
860 ngx_epoll_eventfd_handler(ngx_event_t *ev) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
861 { |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
862 int n, events; |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
863 long i; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
864 uint64_t ready; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
865 ngx_err_t err; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
866 ngx_event_t *e; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
867 ngx_event_aio_t *aio; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
868 struct io_event event[64]; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
869 struct timespec ts; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
870 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
871 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
|
872 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
873 n = read(ngx_eventfd, &ready, 8); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
874 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
875 err = ngx_errno; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
876 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
877 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
|
878 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
879 if (n != 8) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
880 if (n == -1) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
881 if (err == NGX_EAGAIN) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
882 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
883 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
884 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
885 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
|
886 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
887 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
888 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
889 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
890 "read(eventfd) returned only %d bytes", n); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
891 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
892 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
893 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
894 ts.tv_sec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
895 ts.tv_nsec = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
896 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
897 while (ready) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
898 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
899 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
|
900 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
901 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
902 "io_getevents: %l", events); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
903 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
904 if (events > 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
905 ready -= events; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
906 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
907 for (i = 0; i < events; i++) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
908 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
909 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
910 "io_event: %uXL %uXL %L %L", |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
911 event[i].data, event[i].obj, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
912 event[i].res, event[i].res2); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
913 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
914 e = (ngx_event_t *) (uintptr_t) event[i].data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
915 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
916 e->complete = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
917 e->active = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
918 e->ready = 1; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
919 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
920 aio = e->data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
921 aio->res = event[i].res; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
922 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
923 ngx_post_event(e, &ngx_posted_events); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
924 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
925 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
926 continue; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
927 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
928 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
929 if (events == 0) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
930 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
931 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
932 |
4129
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
933 /* events == -1 */ |
6903dac6ad19
Fixing Linux AIO syscalls return value handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
934 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
|
935 "io_getevents() failed"); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
936 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
937 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
938 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
939 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
940 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
941 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3044
diff
changeset
|
942 |
499 | 943 static void * |
944 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
|
945 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
946 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
|
947 |
501 | 948 epcf = ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t)); |
949 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
|
950 return NULL; |
501 | 951 } |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
952 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
953 epcf->events = NGX_CONF_UNSET; |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
954 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
|
955 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
956 return epcf; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
957 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
958 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
959 |
499 | 960 static char * |
961 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
|
962 { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
963 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
|
964 |
663 | 965 ngx_conf_init_uint_value(epcf->events, 512); |
4134
a3203c4521c6
The "worker_aio_requests" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
4130
diff
changeset
|
966 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
|
967 |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
968 return NGX_CONF_OK; |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
969 } |