Mercurial > hg > nginx
annotate src/stream/ngx_stream.h @ 6422:768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
If sendfile in threads is used, it is possible that multiple
subrequests will trigger multiple ngx_linux_sendfile_thread() calls,
as operations are only serialized in output chain based on r->aio,
that is, on subrequest level.
This resulted in "task #N already active" alerts, in particular, when
running proxy_store.t with "aio threads; sendfile on;".
Fix is to tolerate duplicate calls, with an additional safety check
that the file is the same as previously used.
The same problem also affects "aio on; sendfile on;" on FreeBSD
(previously known as "aio sendfile;"), where aio->preload_handler()
could be called multiple times due to similar reasons, resulting in
"second aio post" alerts. Fix is the same as well.
It is also believed that similar problems can arise if a filter
calls the next body filter multiple times for some reason. These are
mostly theoretical though.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 03 Mar 2016 21:14:12 +0300 |
parents | 7565e056fad6 |
children | 8f038068f4bc |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #ifndef _NGX_STREAM_H_INCLUDED_ | |
9 #define _NGX_STREAM_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 | |
15 #if (NGX_STREAM_SSL) | |
16 #include <ngx_stream_ssl_module.h> | |
17 #endif | |
18 | |
19 | |
20 typedef struct ngx_stream_session_s ngx_stream_session_t; | |
21 | |
22 | |
23 #include <ngx_stream_upstream.h> | |
24 #include <ngx_stream_upstream_round_robin.h> | |
25 | |
26 | |
27 typedef struct { | |
28 void **main_conf; | |
29 void **srv_conf; | |
30 } ngx_stream_conf_ctx_t; | |
31 | |
32 | |
33 typedef struct { | |
6170
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
34 union { |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
35 struct sockaddr sockaddr; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
36 struct sockaddr_in sockaddr_in; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
37 #if (NGX_HAVE_INET6) |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
38 struct sockaddr_in6 sockaddr_in6; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
39 #endif |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
40 #if (NGX_HAVE_UNIX_DOMAIN) |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
41 struct sockaddr_un sockaddr_un; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
42 #endif |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
43 u_char sockaddr_data[NGX_SOCKADDRLEN]; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
44 } u; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
45 |
6115 | 46 socklen_t socklen; |
47 | |
48 /* server ctx */ | |
49 ngx_stream_conf_ctx_t *ctx; | |
50 | |
51 unsigned bind:1; | |
52 unsigned wildcard:1; | |
53 #if (NGX_STREAM_SSL) | |
54 unsigned ssl:1; | |
55 #endif | |
56 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
57 unsigned ipv6only:1; | |
58 #endif | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
59 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
60 unsigned reuseport:1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
61 #endif |
6115 | 62 unsigned so_keepalive:2; |
63 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
64 int tcp_keepidle; | |
65 int tcp_keepintvl; | |
66 int tcp_keepcnt; | |
67 #endif | |
6172 | 68 int backlog; |
6115 | 69 } ngx_stream_listen_t; |
70 | |
71 | |
72 typedef struct { | |
73 ngx_stream_conf_ctx_t *ctx; | |
74 ngx_str_t addr_text; | |
75 #if (NGX_STREAM_SSL) | |
76 ngx_uint_t ssl; /* unsigned ssl:1; */ | |
77 #endif | |
78 } ngx_stream_addr_conf_t; | |
79 | |
80 typedef struct { | |
81 in_addr_t addr; | |
82 ngx_stream_addr_conf_t conf; | |
83 } ngx_stream_in_addr_t; | |
84 | |
85 | |
86 #if (NGX_HAVE_INET6) | |
87 | |
88 typedef struct { | |
89 struct in6_addr addr6; | |
90 ngx_stream_addr_conf_t conf; | |
91 } ngx_stream_in6_addr_t; | |
92 | |
93 #endif | |
94 | |
95 | |
96 typedef struct { | |
97 /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */ | |
98 void *addrs; | |
99 ngx_uint_t naddrs; | |
100 } ngx_stream_port_t; | |
101 | |
102 | |
103 typedef struct { | |
104 int family; | |
105 in_port_t port; | |
106 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ | |
107 } ngx_stream_conf_port_t; | |
108 | |
109 | |
110 typedef struct { | |
6170
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
111 ngx_stream_listen_t opt; |
6115 | 112 } ngx_stream_conf_addr_t; |
113 | |
114 | |
6175 | 115 typedef ngx_int_t (*ngx_stream_access_pt)(ngx_stream_session_t *s); |
116 | |
117 | |
6115 | 118 typedef struct { |
119 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ | |
120 ngx_array_t listen; /* ngx_stream_listen_t */ | |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
121 ngx_stream_access_pt limit_conn_handler; |
6175 | 122 ngx_stream_access_pt access_handler; |
6115 | 123 } ngx_stream_core_main_conf_t; |
124 | |
125 | |
126 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
127 | |
128 | |
129 typedef struct { | |
130 ngx_stream_handler_pt handler; | |
131 ngx_stream_conf_ctx_t *ctx; | |
132 u_char *file_name; | |
133 ngx_int_t line; | |
134 ngx_log_t *error_log; | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
135 ngx_flag_t tcp_nodelay; |
6115 | 136 } ngx_stream_core_srv_conf_t; |
137 | |
138 | |
139 struct ngx_stream_session_s { | |
140 uint32_t signature; /* "STRM" */ | |
141 | |
142 ngx_connection_t *connection; | |
143 | |
144 off_t received; | |
145 | |
146 ngx_log_handler_pt log_handler; | |
147 | |
148 void **ctx; | |
149 void **main_conf; | |
150 void **srv_conf; | |
151 | |
152 ngx_stream_upstream_t *upstream; | |
153 }; | |
154 | |
155 | |
156 typedef struct { | |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
157 ngx_int_t (*postconfiguration)(ngx_conf_t *cf); |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
158 |
6115 | 159 void *(*create_main_conf)(ngx_conf_t *cf); |
160 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
161 | |
162 void *(*create_srv_conf)(ngx_conf_t *cf); | |
163 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
164 void *conf); | |
165 } ngx_stream_module_t; | |
166 | |
167 | |
168 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
169 | |
170 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
171 #define NGX_STREAM_SRV_CONF 0x04000000 | |
172 #define NGX_STREAM_UPS_CONF 0x08000000 | |
173 | |
174 | |
175 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
176 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
177 | |
178 | |
179 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
180 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
181 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
182 | |
183 | |
184 #define ngx_stream_get_module_main_conf(s, module) \ | |
185 (s)->main_conf[module.ctx_index] | |
186 #define ngx_stream_get_module_srv_conf(s, module) \ | |
187 (s)->srv_conf[module.ctx_index] | |
188 | |
189 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
190 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
191 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
192 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
193 | |
194 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
195 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
196 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
197 ->main_conf[module.ctx_index]: \ | |
198 NULL) | |
199 | |
200 | |
201 void ngx_stream_init_connection(ngx_connection_t *c); | |
202 void ngx_stream_close_connection(ngx_connection_t *c); | |
203 | |
204 | |
205 extern ngx_module_t ngx_stream_module; | |
206 extern ngx_uint_t ngx_stream_max_module; | |
207 extern ngx_module_t ngx_stream_core_module; | |
208 | |
209 | |
210 #endif /* _NGX_STREAM_H_INCLUDED_ */ |