Mercurial > hg > nginx
annotate src/stream/ngx_stream.h @ 6169:f654addf0eea
Stream: fixed "reuseport" to actually work.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 05 Jun 2015 23:03:13 +0300 |
parents | 4f6efabcb09b |
children | c13091e6292c |
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 { | |
34 u_char sockaddr[NGX_SOCKADDRLEN]; | |
35 socklen_t socklen; | |
36 | |
37 /* server ctx */ | |
38 ngx_stream_conf_ctx_t *ctx; | |
39 | |
40 unsigned bind:1; | |
41 unsigned wildcard:1; | |
42 #if (NGX_STREAM_SSL) | |
43 unsigned ssl:1; | |
44 #endif | |
45 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
46 unsigned ipv6only:1; | |
47 #endif | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
48 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
49 unsigned reuseport:1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
50 #endif |
6115 | 51 unsigned so_keepalive:2; |
52 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
53 int tcp_keepidle; | |
54 int tcp_keepintvl; | |
55 int tcp_keepcnt; | |
56 #endif | |
57 } ngx_stream_listen_t; | |
58 | |
59 | |
60 typedef struct { | |
61 ngx_stream_conf_ctx_t *ctx; | |
62 ngx_str_t addr_text; | |
63 #if (NGX_STREAM_SSL) | |
64 ngx_uint_t ssl; /* unsigned ssl:1; */ | |
65 #endif | |
66 } ngx_stream_addr_conf_t; | |
67 | |
68 typedef struct { | |
69 in_addr_t addr; | |
70 ngx_stream_addr_conf_t conf; | |
71 } ngx_stream_in_addr_t; | |
72 | |
73 | |
74 #if (NGX_HAVE_INET6) | |
75 | |
76 typedef struct { | |
77 struct in6_addr addr6; | |
78 ngx_stream_addr_conf_t conf; | |
79 } ngx_stream_in6_addr_t; | |
80 | |
81 #endif | |
82 | |
83 | |
84 typedef struct { | |
85 /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */ | |
86 void *addrs; | |
87 ngx_uint_t naddrs; | |
88 } ngx_stream_port_t; | |
89 | |
90 | |
91 typedef struct { | |
92 int family; | |
93 in_port_t port; | |
94 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ | |
95 } ngx_stream_conf_port_t; | |
96 | |
97 | |
98 typedef struct { | |
99 struct sockaddr *sockaddr; | |
100 socklen_t socklen; | |
101 | |
102 ngx_stream_conf_ctx_t *ctx; | |
103 | |
104 unsigned bind:1; | |
105 unsigned wildcard:1; | |
106 #if (NGX_STREAM_SSL) | |
107 unsigned ssl:1; | |
108 #endif | |
109 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
110 unsigned ipv6only:1; | |
111 #endif | |
6169
f654addf0eea
Stream: fixed "reuseport" to actually work.
Ruslan Ermilov <ru@nginx.com>
parents:
6153
diff
changeset
|
112 #if (NGX_HAVE_REUSEPORT) |
f654addf0eea
Stream: fixed "reuseport" to actually work.
Ruslan Ermilov <ru@nginx.com>
parents:
6153
diff
changeset
|
113 unsigned reuseport:1; |
f654addf0eea
Stream: fixed "reuseport" to actually work.
Ruslan Ermilov <ru@nginx.com>
parents:
6153
diff
changeset
|
114 #endif |
6115 | 115 unsigned so_keepalive:2; |
116 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
117 int tcp_keepidle; | |
118 int tcp_keepintvl; | |
119 int tcp_keepcnt; | |
120 #endif | |
121 } ngx_stream_conf_addr_t; | |
122 | |
123 | |
124 typedef struct { | |
125 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ | |
126 ngx_array_t listen; /* ngx_stream_listen_t */ | |
127 } ngx_stream_core_main_conf_t; | |
128 | |
129 | |
130 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
131 | |
132 | |
133 typedef struct { | |
134 ngx_stream_handler_pt handler; | |
135 ngx_stream_conf_ctx_t *ctx; | |
136 u_char *file_name; | |
137 ngx_int_t line; | |
138 ngx_log_t *error_log; | |
139 } ngx_stream_core_srv_conf_t; | |
140 | |
141 | |
142 struct ngx_stream_session_s { | |
143 uint32_t signature; /* "STRM" */ | |
144 | |
145 ngx_connection_t *connection; | |
146 | |
147 off_t received; | |
148 | |
149 ngx_log_handler_pt log_handler; | |
150 | |
151 void **ctx; | |
152 void **main_conf; | |
153 void **srv_conf; | |
154 | |
155 ngx_stream_upstream_t *upstream; | |
156 }; | |
157 | |
158 | |
159 typedef struct { | |
160 void *(*create_main_conf)(ngx_conf_t *cf); | |
161 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
162 | |
163 void *(*create_srv_conf)(ngx_conf_t *cf); | |
164 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
165 void *conf); | |
166 } ngx_stream_module_t; | |
167 | |
168 | |
169 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
170 | |
171 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
172 #define NGX_STREAM_SRV_CONF 0x04000000 | |
173 #define NGX_STREAM_UPS_CONF 0x08000000 | |
174 | |
175 | |
176 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
177 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
178 | |
179 | |
180 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
181 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
182 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
183 | |
184 | |
185 #define ngx_stream_get_module_main_conf(s, module) \ | |
186 (s)->main_conf[module.ctx_index] | |
187 #define ngx_stream_get_module_srv_conf(s, module) \ | |
188 (s)->srv_conf[module.ctx_index] | |
189 | |
190 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
191 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
192 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
193 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
194 | |
195 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
196 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
197 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
198 ->main_conf[module.ctx_index]: \ | |
199 NULL) | |
200 | |
201 | |
202 void ngx_stream_init_connection(ngx_connection_t *c); | |
203 void ngx_stream_close_connection(ngx_connection_t *c); | |
204 | |
205 | |
206 extern ngx_module_t ngx_stream_module; | |
207 extern ngx_uint_t ngx_stream_max_module; | |
208 extern ngx_module_t ngx_stream_core_module; | |
209 | |
210 | |
211 #endif /* _NGX_STREAM_H_INCLUDED_ */ |