Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_upstream_zone_module.c @ 8456:c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Previously, if there were some pipelined SMTP data in the buffer when
a proxied connection with the backend was established, nginx called
ngx_mail_proxy_handler() to send these data, and not tried to send the
response to the last command. In most cases, this response was later sent
along with the response to the pipelined command, but if for some reason
client decides to wait for the response before finishing the next command
this might result in a connection hang.
Fix is to always call ngx_mail_proxy_handler() to send the response, and
additionally post an event to send the pipelined data if needed.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 May 2021 03:13:12 +0300 |
parents | 3b1b81e248bc |
children |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Ruslan Ermilov | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_stream.h> | |
11 | |
12 | |
13 static char *ngx_stream_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd, | |
14 void *conf); | |
15 static ngx_int_t ngx_stream_upstream_init_zone(ngx_shm_zone_t *shm_zone, | |
16 void *data); | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
17 static ngx_stream_upstream_rr_peers_t *ngx_stream_upstream_zone_copy_peers( |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
18 ngx_slab_pool_t *shpool, ngx_stream_upstream_srv_conf_t *uscf); |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
19 static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_zone_copy_peer( |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
20 ngx_stream_upstream_rr_peers_t *peers, ngx_stream_upstream_rr_peer_t *src); |
6115 | 21 |
22 | |
23 static ngx_command_t ngx_stream_upstream_zone_commands[] = { | |
24 | |
25 { ngx_string("zone"), | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
26 NGX_STREAM_UPS_CONF|NGX_CONF_TAKE12, |
6115 | 27 ngx_stream_upstream_zone, |
28 0, | |
29 0, | |
30 NULL }, | |
31 | |
32 ngx_null_command | |
33 }; | |
34 | |
35 | |
36 static ngx_stream_module_t ngx_stream_upstream_zone_module_ctx = { | |
6606
2f41d383c9c7
Stream: added preconfiguration step.
Vladimir Homutov <vl@nginx.com>
parents:
6214
diff
changeset
|
37 NULL, /* preconfiguration */ |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6123
diff
changeset
|
38 NULL, /* postconfiguration */ |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6123
diff
changeset
|
39 |
6115 | 40 NULL, /* create main configuration */ |
41 NULL, /* init main configuration */ | |
42 | |
43 NULL, /* create server configuration */ | |
6629 | 44 NULL /* merge server configuration */ |
6115 | 45 }; |
46 | |
47 | |
48 ngx_module_t ngx_stream_upstream_zone_module = { | |
49 NGX_MODULE_V1, | |
50 &ngx_stream_upstream_zone_module_ctx, /* module context */ | |
51 ngx_stream_upstream_zone_commands, /* module directives */ | |
52 NGX_STREAM_MODULE, /* module type */ | |
53 NULL, /* init master */ | |
54 NULL, /* init module */ | |
55 NULL, /* init process */ | |
56 NULL, /* init thread */ | |
57 NULL, /* exit thread */ | |
58 NULL, /* exit process */ | |
59 NULL, /* exit master */ | |
60 NGX_MODULE_V1_PADDING | |
61 }; | |
62 | |
63 | |
64 static char * | |
65 ngx_stream_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
66 { | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
67 ssize_t size; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
68 ngx_str_t *value; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
69 ngx_stream_upstream_srv_conf_t *uscf; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
70 ngx_stream_upstream_main_conf_t *umcf; |
6115 | 71 |
72 uscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_upstream_module); | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
73 umcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_upstream_module); |
6115 | 74 |
75 value = cf->args->elts; | |
76 | |
77 if (!value[1].len) { | |
78 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
79 "invalid zone name \"%V\"", &value[1]); | |
80 return NGX_CONF_ERROR; | |
81 } | |
82 | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
83 if (cf->args->nelts == 3) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
84 size = ngx_parse_size(&value[2]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
85 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
86 if (size == NGX_ERROR) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
87 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
88 "invalid zone size \"%V\"", &value[2]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
89 return NGX_CONF_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
90 } |
6115 | 91 |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
92 if (size < (ssize_t) (8 * ngx_pagesize)) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
93 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
94 "zone \"%V\" is too small", &value[1]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
95 return NGX_CONF_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
96 } |
6115 | 97 |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
98 } else { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
99 size = 0; |
6115 | 100 } |
101 | |
102 uscf->shm_zone = ngx_shared_memory_add(cf, &value[1], size, | |
103 &ngx_stream_upstream_module); | |
104 if (uscf->shm_zone == NULL) { | |
105 return NGX_CONF_ERROR; | |
106 } | |
107 | |
108 uscf->shm_zone->init = ngx_stream_upstream_init_zone; | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
109 uscf->shm_zone->data = umcf; |
6115 | 110 |
111 uscf->shm_zone->noreuse = 1; | |
112 | |
113 return NGX_CONF_OK; | |
114 } | |
115 | |
116 | |
117 static ngx_int_t | |
118 ngx_stream_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data) | |
119 { | |
120 size_t len; | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
121 ngx_uint_t i; |
6115 | 122 ngx_slab_pool_t *shpool; |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
123 ngx_stream_upstream_rr_peers_t *peers, **peersp; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
124 ngx_stream_upstream_srv_conf_t *uscf, **uscfp; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
125 ngx_stream_upstream_main_conf_t *umcf; |
6115 | 126 |
127 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
128 umcf = shm_zone->data; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
129 uscfp = umcf->upstreams.elts; |
6115 | 130 |
131 if (shm_zone->shm.exists) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
132 peers = shpool->data; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
133 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
134 for (i = 0; i < umcf->upstreams.nelts; i++) { |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
135 uscf = uscfp[i]; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
136 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
137 if (uscf->shm_zone != shm_zone) { |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
138 continue; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
139 } |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
140 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
141 uscf->peer.data = peers; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
142 peers = peers->zone_next; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
143 } |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
144 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
145 return NGX_OK; |
6115 | 146 } |
147 | |
148 len = sizeof(" in upstream zone \"\"") + shm_zone->shm.name.len; | |
149 | |
150 shpool->log_ctx = ngx_slab_alloc(shpool, len); | |
151 if (shpool->log_ctx == NULL) { | |
152 return NGX_ERROR; | |
153 } | |
154 | |
155 ngx_sprintf(shpool->log_ctx, " in upstream zone \"%V\"%Z", | |
156 &shm_zone->shm.name); | |
157 | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
158 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
159 /* copy peers to shared memory */ |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
160 |
6214
341e4303d25b
Fixed strict aliasing warnings with old GCC versions.
Ruslan Ermilov <ru@nginx.com>
parents:
6198
diff
changeset
|
161 peersp = (ngx_stream_upstream_rr_peers_t **) (void *) &shpool->data; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
162 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
163 for (i = 0; i < umcf->upstreams.nelts; i++) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
164 uscf = uscfp[i]; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
165 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
166 if (uscf->shm_zone != shm_zone) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
167 continue; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
168 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
169 |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
170 peers = ngx_stream_upstream_zone_copy_peers(shpool, uscf); |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
171 if (peers == NULL) { |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
172 return NGX_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
173 } |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
174 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
175 *peersp = peers; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
176 peersp = &peers->zone_next; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
177 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
178 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
179 return NGX_OK; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
180 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
181 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
182 |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
183 static ngx_stream_upstream_rr_peers_t * |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
184 ngx_stream_upstream_zone_copy_peers(ngx_slab_pool_t *shpool, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
185 ngx_stream_upstream_srv_conf_t *uscf) |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
186 { |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
187 ngx_str_t *name; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
188 ngx_stream_upstream_rr_peer_t *peer, **peerp; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
189 ngx_stream_upstream_rr_peers_t *peers, *backup; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
190 |
6115 | 191 peers = ngx_slab_alloc(shpool, sizeof(ngx_stream_upstream_rr_peers_t)); |
192 if (peers == NULL) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
193 return NULL; |
6115 | 194 } |
195 | |
196 ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_stream_upstream_rr_peers_t)); | |
197 | |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
198 name = ngx_slab_alloc(shpool, sizeof(ngx_str_t)); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
199 if (name == NULL) { |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
200 return NULL; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
201 } |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
202 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
203 name->data = ngx_slab_alloc(shpool, peers->name->len); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
204 if (name->data == NULL) { |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
205 return NULL; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
206 } |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
207 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
208 ngx_memcpy(name->data, peers->name->data, peers->name->len); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
209 name->len = peers->name->len; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
210 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
211 peers->name = name; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
212 |
6115 | 213 peers->shpool = shpool; |
214 | |
215 for (peerp = &peers->peer; *peerp; peerp = &peer->next) { | |
216 /* pool is unlocked */ | |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
217 peer = ngx_stream_upstream_zone_copy_peer(peers, *peerp); |
6115 | 218 if (peer == NULL) { |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
219 return NULL; |
6115 | 220 } |
221 | |
222 *peerp = peer; | |
223 } | |
224 | |
225 if (peers->next == NULL) { | |
226 goto done; | |
227 } | |
228 | |
229 backup = ngx_slab_alloc(shpool, sizeof(ngx_stream_upstream_rr_peers_t)); | |
230 if (backup == NULL) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
231 return NULL; |
6115 | 232 } |
233 | |
234 ngx_memcpy(backup, peers->next, sizeof(ngx_stream_upstream_rr_peers_t)); | |
235 | |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
236 backup->name = name; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6629
diff
changeset
|
237 |
6115 | 238 backup->shpool = shpool; |
239 | |
240 for (peerp = &backup->peer; *peerp; peerp = &peer->next) { | |
241 /* pool is unlocked */ | |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
242 peer = ngx_stream_upstream_zone_copy_peer(backup, *peerp); |
6115 | 243 if (peer == NULL) { |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
244 return NULL; |
6115 | 245 } |
246 | |
247 *peerp = peer; | |
248 } | |
249 | |
250 peers->next = backup; | |
251 | |
252 done: | |
253 | |
254 uscf->peer.data = peers; | |
255 | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6174
diff
changeset
|
256 return peers; |
6115 | 257 } |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
258 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
259 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
260 static ngx_stream_upstream_rr_peer_t * |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
261 ngx_stream_upstream_zone_copy_peer(ngx_stream_upstream_rr_peers_t *peers, |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
262 ngx_stream_upstream_rr_peer_t *src) |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
263 { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
264 ngx_slab_pool_t *pool; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
265 ngx_stream_upstream_rr_peer_t *dst; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
266 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
267 pool = peers->shpool; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
268 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
269 dst = ngx_slab_calloc_locked(pool, sizeof(ngx_stream_upstream_rr_peer_t)); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
270 if (dst == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
271 return NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
272 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
273 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
274 if (src) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
275 ngx_memcpy(dst, src, sizeof(ngx_stream_upstream_rr_peer_t)); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
276 dst->sockaddr = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
277 dst->name.data = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
278 dst->server.data = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
279 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
280 |
7110
3b1b81e248bc
Do not use the obsolete NGX_SOCKADDRLEN macro.
Ruslan Ermilov <ru@nginx.com>
parents:
7080
diff
changeset
|
281 dst->sockaddr = ngx_slab_calloc_locked(pool, sizeof(ngx_sockaddr_t)); |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
282 if (dst->sockaddr == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
283 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
284 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
285 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
286 dst->name.data = ngx_slab_calloc_locked(pool, NGX_SOCKADDR_STRLEN); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
287 if (dst->name.data == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
288 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
289 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
290 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
291 if (src) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
292 ngx_memcpy(dst->sockaddr, src->sockaddr, src->socklen); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
293 ngx_memcpy(dst->name.data, src->name.data, src->name.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
294 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
295 dst->server.data = ngx_slab_alloc_locked(pool, src->server.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
296 if (dst->server.data == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
297 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
298 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
299 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
300 ngx_memcpy(dst->server.data, src->server.data, src->server.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
301 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
302 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
303 return dst; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
304 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
305 failed: |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
306 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
307 if (dst->server.data) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
308 ngx_slab_free_locked(pool, dst->server.data); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
309 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
310 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
311 if (dst->name.data) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
312 ngx_slab_free_locked(pool, dst->name.data); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
313 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
314 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
315 if (dst->sockaddr) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
316 ngx_slab_free_locked(pool, dst->sockaddr); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
317 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
318 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
319 ngx_slab_free_locked(pool, dst); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
320 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
321 return NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
322 } |