Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream.h @ 6542:c93e57ba301b
Events: close descriptors on errors in ngx_epoll_test_rdhup().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 18 May 2016 15:57:30 +0300 |
parents | 8f038068f4bc |
children | 6f8254ae61b8 |
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; |
6436 | 69 int type; |
6115 | 70 } ngx_stream_listen_t; |
71 | |
72 | |
73 typedef struct { | |
74 ngx_stream_conf_ctx_t *ctx; | |
75 ngx_str_t addr_text; | |
76 #if (NGX_STREAM_SSL) | |
77 ngx_uint_t ssl; /* unsigned ssl:1; */ | |
78 #endif | |
79 } ngx_stream_addr_conf_t; | |
80 | |
81 typedef struct { | |
82 in_addr_t addr; | |
83 ngx_stream_addr_conf_t conf; | |
84 } ngx_stream_in_addr_t; | |
85 | |
86 | |
87 #if (NGX_HAVE_INET6) | |
88 | |
89 typedef struct { | |
90 struct in6_addr addr6; | |
91 ngx_stream_addr_conf_t conf; | |
92 } ngx_stream_in6_addr_t; | |
93 | |
94 #endif | |
95 | |
96 | |
97 typedef struct { | |
98 /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */ | |
99 void *addrs; | |
100 ngx_uint_t naddrs; | |
101 } ngx_stream_port_t; | |
102 | |
103 | |
104 typedef struct { | |
105 int family; | |
6436 | 106 int type; |
6115 | 107 in_port_t port; |
108 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ | |
109 } ngx_stream_conf_port_t; | |
110 | |
111 | |
112 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
|
113 ngx_stream_listen_t opt; |
6115 | 114 } ngx_stream_conf_addr_t; |
115 | |
116 | |
6175 | 117 typedef ngx_int_t (*ngx_stream_access_pt)(ngx_stream_session_t *s); |
118 | |
119 | |
6115 | 120 typedef struct { |
121 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ | |
122 ngx_array_t listen; /* ngx_stream_listen_t */ | |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
123 ngx_stream_access_pt limit_conn_handler; |
6175 | 124 ngx_stream_access_pt access_handler; |
6115 | 125 } ngx_stream_core_main_conf_t; |
126 | |
127 | |
128 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
129 | |
130 | |
131 typedef struct { | |
132 ngx_stream_handler_pt handler; | |
133 ngx_stream_conf_ctx_t *ctx; | |
134 u_char *file_name; | |
135 ngx_int_t line; | |
136 ngx_log_t *error_log; | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
137 ngx_flag_t tcp_nodelay; |
6115 | 138 } ngx_stream_core_srv_conf_t; |
139 | |
140 | |
141 struct ngx_stream_session_s { | |
142 uint32_t signature; /* "STRM" */ | |
143 | |
144 ngx_connection_t *connection; | |
145 | |
146 off_t received; | |
147 | |
148 ngx_log_handler_pt log_handler; | |
149 | |
150 void **ctx; | |
151 void **main_conf; | |
152 void **srv_conf; | |
153 | |
154 ngx_stream_upstream_t *upstream; | |
155 }; | |
156 | |
157 | |
158 typedef struct { | |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
159 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
|
160 |
6115 | 161 void *(*create_main_conf)(ngx_conf_t *cf); |
162 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
163 | |
164 void *(*create_srv_conf)(ngx_conf_t *cf); | |
165 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
166 void *conf); | |
167 } ngx_stream_module_t; | |
168 | |
169 | |
170 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
171 | |
172 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
173 #define NGX_STREAM_SRV_CONF 0x04000000 | |
174 #define NGX_STREAM_UPS_CONF 0x08000000 | |
175 | |
176 | |
177 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
178 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
179 | |
180 | |
181 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
182 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
183 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
184 | |
185 | |
186 #define ngx_stream_get_module_main_conf(s, module) \ | |
187 (s)->main_conf[module.ctx_index] | |
188 #define ngx_stream_get_module_srv_conf(s, module) \ | |
189 (s)->srv_conf[module.ctx_index] | |
190 | |
191 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
192 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
193 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
194 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
195 | |
196 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
197 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
198 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
199 ->main_conf[module.ctx_index]: \ | |
200 NULL) | |
201 | |
202 | |
203 void ngx_stream_init_connection(ngx_connection_t *c); | |
204 void ngx_stream_close_connection(ngx_connection_t *c); | |
205 | |
206 | |
207 extern ngx_module_t ngx_stream_module; | |
208 extern ngx_uint_t ngx_stream_max_module; | |
209 extern ngx_module_t ngx_stream_core_module; | |
210 | |
211 | |
212 #endif /* _NGX_STREAM_H_INCLUDED_ */ |