[nginx] Stream: resolver.

Vladimir Homutov vl at nginx.com
Thu Jul 7 11:32:03 UTC 2016


details:   http://hg.nginx.org/nginx/rev/070c31a482e6
branches:  
changeset: 6618:070c31a482e6
user:      Vladimir Homutov <vl at nginx.com>
date:      Thu Jul 07 13:15:31 2016 +0300
description:
Stream: resolver.

diffstat:

 src/stream/ngx_stream.h             |   3 +
 src/stream/ngx_stream_core_module.c |  60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diffs (108 lines):

diff -r 8bf484eef9ab -r 070c31a482e6 src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h	Wed Jul 06 13:22:29 2016 +0300
+++ b/src/stream/ngx_stream.h	Thu Jul 07 13:15:31 2016 +0300
@@ -141,6 +141,9 @@ typedef struct {
     ngx_flag_t                     tcp_nodelay;
 
     ngx_log_t                     *error_log;
+
+    ngx_msec_t                     resolver_timeout;
+    ngx_resolver_t                *resolver;
 } ngx_stream_core_srv_conf_t;
 
 
diff -r 8bf484eef9ab -r 070c31a482e6 src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Wed Jul 06 13:22:29 2016 +0300
+++ b/src/stream/ngx_stream_core_module.c	Thu Jul 07 13:15:31 2016 +0300
@@ -22,6 +22,8 @@ static char *ngx_stream_core_server(ngx_
     void *conf);
 static char *ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
+static char *ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
+    void *conf);
 
 
 static ngx_command_t  ngx_stream_core_commands[] = {
@@ -61,6 +63,20 @@ static ngx_command_t  ngx_stream_core_co
       0,
       NULL },
 
+    { ngx_string("resolver"),
+      NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
+      ngx_stream_core_resolver,
+      NGX_STREAM_SRV_CONF_OFFSET,
+      0,
+      NULL },
+
+    { ngx_string("resolver_timeout"),
+      NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_msec_slot,
+      NGX_STREAM_SRV_CONF_OFFSET,
+      offsetof(ngx_stream_core_srv_conf_t, resolver_timeout),
+      NULL },
+
     { ngx_string("tcp_nodelay"),
       NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -175,6 +191,7 @@ ngx_stream_core_create_srv_conf(ngx_conf
 
     cscf->file_name = cf->conf_file->file.name.data;
     cscf->line = cf->conf_file->line;
+    cscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
     cscf->tcp_nodelay = NGX_CONF_UNSET;
 
     return cscf;
@@ -187,6 +204,27 @@ ngx_stream_core_merge_srv_conf(ngx_conf_
     ngx_stream_core_srv_conf_t *prev = parent;
     ngx_stream_core_srv_conf_t *conf = child;
 
+    ngx_conf_merge_msec_value(conf->resolver_timeout,
+                              prev->resolver_timeout, 30000);
+
+    if (conf->resolver == NULL) {
+
+        if (prev->resolver == NULL) {
+
+            /*
+             * create dummy resolver in stream {} context
+             * to inherit it in all servers
+             */
+
+            prev->resolver = ngx_resolver_create(cf, NULL, 0);
+            if (prev->resolver == NULL) {
+                return NGX_CONF_ERROR;
+            }
+        }
+
+        conf->resolver = prev->resolver;
+    }
+
     if (conf->handler == NULL) {
         ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                       "no handler for server in %s:%ui",
@@ -565,3 +603,25 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
 
     return NGX_CONF_OK;
 }
+
+
+static char *
+ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_stream_core_srv_conf_t  *cscf = conf;
+
+    ngx_str_t  *value;
+
+    if (cscf->resolver) {
+        return "is duplicate";
+    }
+
+    value = cf->args->elts;
+
+    cscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
+    if (cscf->resolver == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    return NGX_CONF_OK;
+}



More information about the nginx-devel mailing list