diff src/stream/ngx_stream_core_module.c @ 6607:c70b7f4537e1

Stream: variables and script. This is a port of corresponding http code with unrelated features excluded.
author Vladimir Homutov <vl@nginx.com>
date Mon, 04 Jul 2016 16:37:36 +0300
parents 2f41d383c9c7
children 070c31a482e6
line wrap: on
line diff
--- a/src/stream/ngx_stream_core_module.c
+++ b/src/stream/ngx_stream_core_module.c
@@ -10,7 +10,9 @@
 #include <ngx_stream.h>
 
 
+static ngx_int_t ngx_stream_core_preconfiguration(ngx_conf_t *cf);
 static void *ngx_stream_core_create_main_conf(ngx_conf_t *cf);
+static char *ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf);
 static void *ngx_stream_core_create_srv_conf(ngx_conf_t *cf);
 static char *ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent,
     void *child);
@@ -24,6 +26,20 @@ static char *ngx_stream_core_listen(ngx_
 
 static ngx_command_t  ngx_stream_core_commands[] = {
 
+    { ngx_string("variables_hash_max_size"),
+      NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_num_slot,
+      NGX_STREAM_MAIN_CONF_OFFSET,
+      offsetof(ngx_stream_core_main_conf_t, variables_hash_max_size),
+      NULL },
+
+    { ngx_string("variables_hash_bucket_size"),
+      NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_num_slot,
+      NGX_STREAM_MAIN_CONF_OFFSET,
+      offsetof(ngx_stream_core_main_conf_t, variables_hash_bucket_size),
+      NULL },
+
     { ngx_string("server"),
       NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
       ngx_stream_core_server,
@@ -57,11 +73,11 @@ static ngx_command_t  ngx_stream_core_co
 
 
 static ngx_stream_module_t  ngx_stream_core_module_ctx = {
-    NULL,                                  /* preconfiguration */
+    ngx_stream_core_preconfiguration,      /* preconfiguration */
     NULL,                                  /* postconfiguration */
 
     ngx_stream_core_create_main_conf,      /* create main configuration */
-    NULL,                                  /* init main configuration */
+    ngx_stream_core_init_main_conf,        /* init main configuration */
 
     ngx_stream_core_create_srv_conf,       /* create server configuration */
     ngx_stream_core_merge_srv_conf         /* merge server configuration */
@@ -84,6 +100,13 @@ ngx_module_t  ngx_stream_core_module = {
 };
 
 
+static ngx_int_t
+ngx_stream_core_preconfiguration(ngx_conf_t *cf)
+{
+    return ngx_stream_variables_add_core_vars(cf);
+}
+
+
 static void *
 ngx_stream_core_create_main_conf(ngx_conf_t *cf)
 {
@@ -107,10 +130,32 @@ ngx_stream_core_create_main_conf(ngx_con
         return NULL;
     }
 
+    cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
+    cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
+
     return cmcf;
 }
 
 
+static char *
+ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf)
+{
+    ngx_stream_core_main_conf_t *cmcf = conf;
+
+    ngx_conf_init_uint_value(cmcf->variables_hash_max_size, 1024);
+    ngx_conf_init_uint_value(cmcf->variables_hash_bucket_size, 64);
+
+    cmcf->variables_hash_bucket_size =
+               ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
+
+    if (cmcf->ncaptures) {
+        cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
+    }
+
+    return NGX_CONF_OK;
+}
+
+
 static void *
 ngx_stream_core_create_srv_conf(ngx_conf_t *cf)
 {