comparison src/stream/ngx_stream_core_module.c @ 6618:070c31a482e6

Stream: resolver.
author Vladimir Homutov <vl@nginx.com>
date Thu, 07 Jul 2016 13:15:31 +0300
parents c70b7f4537e1
children 3d5202c71f94
comparison
equal deleted inserted replaced
6617:8bf484eef9ab 6618:070c31a482e6
20 void *conf); 20 void *conf);
21 static char *ngx_stream_core_server(ngx_conf_t *cf, ngx_command_t *cmd, 21 static char *ngx_stream_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
22 void *conf); 22 void *conf);
23 static char *ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, 23 static char *ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
24 void *conf); 24 void *conf);
25 static char *ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
26 void *conf);
25 27
26 28
27 static ngx_command_t ngx_stream_core_commands[] = { 29 static ngx_command_t ngx_stream_core_commands[] = {
28 30
29 { ngx_string("variables_hash_max_size"), 31 { ngx_string("variables_hash_max_size"),
57 { ngx_string("error_log"), 59 { ngx_string("error_log"),
58 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, 60 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
59 ngx_stream_core_error_log, 61 ngx_stream_core_error_log,
60 NGX_STREAM_SRV_CONF_OFFSET, 62 NGX_STREAM_SRV_CONF_OFFSET,
61 0, 63 0,
64 NULL },
65
66 { ngx_string("resolver"),
67 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
68 ngx_stream_core_resolver,
69 NGX_STREAM_SRV_CONF_OFFSET,
70 0,
71 NULL },
72
73 { ngx_string("resolver_timeout"),
74 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
75 ngx_conf_set_msec_slot,
76 NGX_STREAM_SRV_CONF_OFFSET,
77 offsetof(ngx_stream_core_srv_conf_t, resolver_timeout),
62 NULL }, 78 NULL },
63 79
64 { ngx_string("tcp_nodelay"), 80 { ngx_string("tcp_nodelay"),
65 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, 81 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
66 ngx_conf_set_flag_slot, 82 ngx_conf_set_flag_slot,
173 * cscf->error_log = NULL; 189 * cscf->error_log = NULL;
174 */ 190 */
175 191
176 cscf->file_name = cf->conf_file->file.name.data; 192 cscf->file_name = cf->conf_file->file.name.data;
177 cscf->line = cf->conf_file->line; 193 cscf->line = cf->conf_file->line;
194 cscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
178 cscf->tcp_nodelay = NGX_CONF_UNSET; 195 cscf->tcp_nodelay = NGX_CONF_UNSET;
179 196
180 return cscf; 197 return cscf;
181 } 198 }
182 199
184 static char * 201 static char *
185 ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) 202 ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
186 { 203 {
187 ngx_stream_core_srv_conf_t *prev = parent; 204 ngx_stream_core_srv_conf_t *prev = parent;
188 ngx_stream_core_srv_conf_t *conf = child; 205 ngx_stream_core_srv_conf_t *conf = child;
206
207 ngx_conf_merge_msec_value(conf->resolver_timeout,
208 prev->resolver_timeout, 30000);
209
210 if (conf->resolver == NULL) {
211
212 if (prev->resolver == NULL) {
213
214 /*
215 * create dummy resolver in stream {} context
216 * to inherit it in all servers
217 */
218
219 prev->resolver = ngx_resolver_create(cf, NULL, 0);
220 if (prev->resolver == NULL) {
221 return NGX_CONF_ERROR;
222 }
223 }
224
225 conf->resolver = prev->resolver;
226 }
189 227
190 if (conf->handler == NULL) { 228 if (conf->handler == NULL) {
191 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 229 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
192 "no handler for server in %s:%ui", 230 "no handler for server in %s:%ui",
193 conf->file_name, conf->line); 231 conf->file_name, conf->line);
563 return NGX_CONF_ERROR; 601 return NGX_CONF_ERROR;
564 } 602 }
565 603
566 return NGX_CONF_OK; 604 return NGX_CONF_OK;
567 } 605 }
606
607
608 static char *
609 ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
610 {
611 ngx_stream_core_srv_conf_t *cscf = conf;
612
613 ngx_str_t *value;
614
615 if (cscf->resolver) {
616 return "is duplicate";
617 }
618
619 value = cf->args->elts;
620
621 cscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
622 if (cscf->resolver == NULL) {
623 return NGX_CONF_ERROR;
624 }
625
626 return NGX_CONF_OK;
627 }