changeset 1652:cc7a7d0b89e8

http resolver and resolver_timeout
author Igor Sysoev <igor@sysoev.ru>
date Tue, 27 Nov 2007 11:33:52 +0000
parents 555ee689cecc
children ea681a6a0c61
files src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -69,6 +69,8 @@ static char *ngx_http_core_keepalive(ngx
     void *conf);
 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
+static char * ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
+    void *conf);
 
 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
@@ -492,6 +494,20 @@ static ngx_command_t  ngx_http_core_comm
       offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
       NULL },
 
+    { ngx_string("resolver"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_http_core_resolver,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      0,
+      NULL },
+
+    { ngx_string("resolver_timeout"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_msec_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
+      NULL },
+
       ngx_null_command
 };
 
@@ -2391,6 +2407,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t
     lcf->keepalive_header = NGX_CONF_UNSET;
     lcf->lingering_time = NGX_CONF_UNSET_MSEC;
     lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
+    lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
     lcf->reset_timedout_connection = NGX_CONF_UNSET;
     lcf->port_in_redirect = NGX_CONF_UNSET;
     lcf->msie_padding = NGX_CONF_UNSET;
@@ -2572,6 +2589,12 @@ ngx_http_core_merge_loc_conf(ngx_conf_t 
                               prev->lingering_time, 30000);
     ngx_conf_merge_msec_value(conf->lingering_timeout,
                               prev->lingering_timeout, 5000);
+    ngx_conf_merge_msec_value(conf->resolver_timeout,
+                              prev->resolver_timeout, 30000);
+
+    if (conf->resolver == NULL) {
+        conf->resolver = prev->resolver;
+    }
 
     ngx_conf_merge_path_value(conf->client_body_temp_path,
                               prev->client_body_temp_path,
@@ -3361,6 +3384,33 @@ ngx_http_core_internal(ngx_conf_t *cf, n
 
 
 static char *
+ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_http_core_loc_conf_t  *clcf = conf;
+
+    ngx_url_t   u;
+    ngx_str_t  *value;
+
+    value = cf->args->elts;
+
+    u.host = value[1];
+    u.port = 53;
+
+    if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
+        return NGX_CONF_ERROR;
+    }
+
+    clcf->resolver = ngx_resolver_create(&u.addrs[0], cf->cycle->new_log);
+    if (clcf->resolver == NULL) {
+        return NGX_OK;
+    }
+
+    return NGX_CONF_OK;
+}
+
+
+static char *
 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
 {
 #if (NGX_FREEBSD)
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -270,6 +270,9 @@ struct ngx_http_core_loc_conf_s {
     ngx_msec_t    keepalive_timeout;       /* keepalive_timeout */
     ngx_msec_t    lingering_time;          /* lingering_time */
     ngx_msec_t    lingering_timeout;       /* lingering_timeout */
+    ngx_msec_t    resolver_timeout;        /* resolver_timeout */
+
+    ngx_resolver_t  *resolver;             /* resolver */
 
     time_t        keepalive_header;        /* keepalive_timeout */