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