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