Mercurial > hg > nginx-quic
comparison src/stream/ngx_stream_proxy_module.c @ 6215:8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Both download and upload buffers now have the same size. The old directives
proxy_downstream_buffer and proxy_upstream_buffer are removed.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 29 Jul 2015 13:46:26 -0700 |
parents | 7a14a0d754ad |
children | 543f10fe34d2 |
comparison
equal
deleted
inserted
replaced
6214:341e4303d25b | 6215:8ee6a08ea3eb |
---|---|
15 | 15 |
16 typedef struct { | 16 typedef struct { |
17 ngx_msec_t connect_timeout; | 17 ngx_msec_t connect_timeout; |
18 ngx_msec_t timeout; | 18 ngx_msec_t timeout; |
19 ngx_msec_t next_upstream_timeout; | 19 ngx_msec_t next_upstream_timeout; |
20 size_t downstream_buf_size; | 20 size_t buffer_size; |
21 size_t upload_rate; | 21 size_t upload_rate; |
22 size_t upstream_buf_size; | |
23 size_t download_rate; | 22 size_t download_rate; |
24 ngx_uint_t next_upstream_tries; | 23 ngx_uint_t next_upstream_tries; |
25 ngx_flag_t next_upstream; | 24 ngx_flag_t next_upstream; |
26 ngx_flag_t proxy_protocol; | 25 ngx_flag_t proxy_protocol; |
27 ngx_addr_t *local; | 26 ngx_addr_t *local; |
125 ngx_conf_set_msec_slot, | 124 ngx_conf_set_msec_slot, |
126 NGX_STREAM_SRV_CONF_OFFSET, | 125 NGX_STREAM_SRV_CONF_OFFSET, |
127 offsetof(ngx_stream_proxy_srv_conf_t, timeout), | 126 offsetof(ngx_stream_proxy_srv_conf_t, timeout), |
128 NULL }, | 127 NULL }, |
129 | 128 |
130 { ngx_string("proxy_downstream_buffer"), | 129 { ngx_string("proxy_buffer_size"), |
131 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | 130 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
132 ngx_conf_set_size_slot, | 131 ngx_conf_set_size_slot, |
133 NGX_STREAM_SRV_CONF_OFFSET, | 132 NGX_STREAM_SRV_CONF_OFFSET, |
134 offsetof(ngx_stream_proxy_srv_conf_t, downstream_buf_size), | 133 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), |
135 NULL }, | 134 NULL }, |
136 | 135 |
137 { ngx_string("proxy_upload_rate"), | 136 { ngx_string("proxy_upload_rate"), |
138 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | 137 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
139 ngx_conf_set_size_slot, | 138 ngx_conf_set_size_slot, |
140 NGX_STREAM_SRV_CONF_OFFSET, | 139 NGX_STREAM_SRV_CONF_OFFSET, |
141 offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), | 140 offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), |
142 NULL }, | |
143 | |
144 { ngx_string("proxy_upstream_buffer"), | |
145 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
146 ngx_conf_set_size_slot, | |
147 NGX_STREAM_SRV_CONF_OFFSET, | |
148 offsetof(ngx_stream_proxy_srv_conf_t, upstream_buf_size), | |
149 NULL }, | 141 NULL }, |
150 | 142 |
151 { ngx_string("proxy_download_rate"), | 143 { ngx_string("proxy_download_rate"), |
152 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | 144 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
153 ngx_conf_set_size_slot, | 145 ngx_conf_set_size_slot, |
356 } | 348 } |
357 | 349 |
358 u->proxy_protocol = pscf->proxy_protocol; | 350 u->proxy_protocol = pscf->proxy_protocol; |
359 u->start_sec = ngx_time(); | 351 u->start_sec = ngx_time(); |
360 | 352 |
361 p = ngx_pnalloc(c->pool, pscf->downstream_buf_size); | 353 p = ngx_pnalloc(c->pool, pscf->buffer_size); |
362 if (p == NULL) { | 354 if (p == NULL) { |
363 ngx_stream_proxy_finalize(s, NGX_ERROR); | 355 ngx_stream_proxy_finalize(s, NGX_ERROR); |
364 return; | 356 return; |
365 } | 357 } |
366 | 358 |
367 u->downstream_buf.start = p; | 359 u->downstream_buf.start = p; |
368 u->downstream_buf.end = p + pscf->downstream_buf_size; | 360 u->downstream_buf.end = p + pscf->buffer_size; |
369 u->downstream_buf.pos = p; | 361 u->downstream_buf.pos = p; |
370 u->downstream_buf.last = p; | 362 u->downstream_buf.last = p; |
371 | 363 |
372 c->write->handler = ngx_stream_proxy_downstream_handler; | 364 c->write->handler = ngx_stream_proxy_downstream_handler; |
373 c->read->handler = ngx_stream_proxy_downstream_handler; | 365 c->read->handler = ngx_stream_proxy_downstream_handler; |
374 | 366 |
375 if (u->proxy_protocol | 367 if (u->proxy_protocol |
376 #if (NGX_STREAM_SSL) | 368 #if (NGX_STREAM_SSL) |
377 && pscf->ssl == NULL | 369 && pscf->ssl == NULL |
378 #endif | 370 #endif |
379 && pscf->downstream_buf_size >= NGX_PROXY_PROTOCOL_MAX_HEADER | 371 && pscf->buffer_size >= NGX_PROXY_PROTOCOL_MAX_HEADER |
380 ) | 372 ) |
381 { | 373 { |
382 /* optimization for a typical case */ | 374 /* optimization for a typical case */ |
383 | 375 |
384 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, | 376 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
511 } | 503 } |
512 } | 504 } |
513 | 505 |
514 c->log->action = "proxying connection"; | 506 c->log->action = "proxying connection"; |
515 | 507 |
516 p = ngx_pnalloc(c->pool, pscf->upstream_buf_size); | 508 p = ngx_pnalloc(c->pool, pscf->buffer_size); |
517 if (p == NULL) { | 509 if (p == NULL) { |
518 ngx_stream_proxy_finalize(s, NGX_ERROR); | 510 ngx_stream_proxy_finalize(s, NGX_ERROR); |
519 return; | 511 return; |
520 } | 512 } |
521 | 513 |
522 u->upstream_buf.start = p; | 514 u->upstream_buf.start = p; |
523 u->upstream_buf.end = p + pscf->upstream_buf_size; | 515 u->upstream_buf.end = p + pscf->buffer_size; |
524 u->upstream_buf.pos = p; | 516 u->upstream_buf.pos = p; |
525 u->upstream_buf.last = p; | 517 u->upstream_buf.last = p; |
526 | 518 |
527 u->connected = 1; | 519 u->connected = 1; |
528 | 520 |
1293 */ | 1285 */ |
1294 | 1286 |
1295 conf->connect_timeout = NGX_CONF_UNSET_MSEC; | 1287 conf->connect_timeout = NGX_CONF_UNSET_MSEC; |
1296 conf->timeout = NGX_CONF_UNSET_MSEC; | 1288 conf->timeout = NGX_CONF_UNSET_MSEC; |
1297 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; | 1289 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; |
1298 conf->downstream_buf_size = NGX_CONF_UNSET_SIZE; | 1290 conf->buffer_size = NGX_CONF_UNSET_SIZE; |
1299 conf->upload_rate = NGX_CONF_UNSET_SIZE; | 1291 conf->upload_rate = NGX_CONF_UNSET_SIZE; |
1300 conf->upstream_buf_size = NGX_CONF_UNSET_SIZE; | |
1301 conf->download_rate = NGX_CONF_UNSET_SIZE; | 1292 conf->download_rate = NGX_CONF_UNSET_SIZE; |
1302 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; | 1293 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; |
1303 conf->next_upstream = NGX_CONF_UNSET; | 1294 conf->next_upstream = NGX_CONF_UNSET; |
1304 conf->proxy_protocol = NGX_CONF_UNSET; | 1295 conf->proxy_protocol = NGX_CONF_UNSET; |
1305 conf->local = NGX_CONF_UNSET_PTR; | 1296 conf->local = NGX_CONF_UNSET_PTR; |
1330 prev->timeout, 10 * 60000); | 1321 prev->timeout, 10 * 60000); |
1331 | 1322 |
1332 ngx_conf_merge_msec_value(conf->next_upstream_timeout, | 1323 ngx_conf_merge_msec_value(conf->next_upstream_timeout, |
1333 prev->next_upstream_timeout, 0); | 1324 prev->next_upstream_timeout, 0); |
1334 | 1325 |
1335 ngx_conf_merge_size_value(conf->downstream_buf_size, | 1326 ngx_conf_merge_size_value(conf->buffer_size, |
1336 prev->downstream_buf_size, 16384); | 1327 prev->buffer_size, 16384); |
1337 | 1328 |
1338 ngx_conf_merge_size_value(conf->upload_rate, | 1329 ngx_conf_merge_size_value(conf->upload_rate, |
1339 prev->upload_rate, 0); | 1330 prev->upload_rate, 0); |
1340 | |
1341 ngx_conf_merge_size_value(conf->upstream_buf_size, | |
1342 prev->upstream_buf_size, 16384); | |
1343 | 1331 |
1344 ngx_conf_merge_size_value(conf->download_rate, | 1332 ngx_conf_merge_size_value(conf->download_rate, |
1345 prev->download_rate, 0); | 1333 prev->download_rate, 0); |
1346 | 1334 |
1347 ngx_conf_merge_uint_value(conf->next_upstream_tries, | 1335 ngx_conf_merge_uint_value(conf->next_upstream_tries, |