comparison 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
comparison
equal deleted inserted replaced
6606:2f41d383c9c7 6607:c70b7f4537e1
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_stream.h> 10 #include <ngx_stream.h>
11 11
12 12
13 static ngx_int_t ngx_stream_core_preconfiguration(ngx_conf_t *cf);
13 static void *ngx_stream_core_create_main_conf(ngx_conf_t *cf); 14 static void *ngx_stream_core_create_main_conf(ngx_conf_t *cf);
15 static char *ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf);
14 static void *ngx_stream_core_create_srv_conf(ngx_conf_t *cf); 16 static void *ngx_stream_core_create_srv_conf(ngx_conf_t *cf);
15 static char *ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, 17 static char *ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent,
16 void *child); 18 void *child);
17 static char *ngx_stream_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, 19 static char *ngx_stream_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
18 void *conf); 20 void *conf);
22 void *conf); 24 void *conf);
23 25
24 26
25 static ngx_command_t ngx_stream_core_commands[] = { 27 static ngx_command_t ngx_stream_core_commands[] = {
26 28
29 { ngx_string("variables_hash_max_size"),
30 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1,
31 ngx_conf_set_num_slot,
32 NGX_STREAM_MAIN_CONF_OFFSET,
33 offsetof(ngx_stream_core_main_conf_t, variables_hash_max_size),
34 NULL },
35
36 { ngx_string("variables_hash_bucket_size"),
37 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1,
38 ngx_conf_set_num_slot,
39 NGX_STREAM_MAIN_CONF_OFFSET,
40 offsetof(ngx_stream_core_main_conf_t, variables_hash_bucket_size),
41 NULL },
42
27 { ngx_string("server"), 43 { ngx_string("server"),
28 NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, 44 NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
29 ngx_stream_core_server, 45 ngx_stream_core_server,
30 0, 46 0,
31 0, 47 0,
55 ngx_null_command 71 ngx_null_command
56 }; 72 };
57 73
58 74
59 static ngx_stream_module_t ngx_stream_core_module_ctx = { 75 static ngx_stream_module_t ngx_stream_core_module_ctx = {
60 NULL, /* preconfiguration */ 76 ngx_stream_core_preconfiguration, /* preconfiguration */
61 NULL, /* postconfiguration */ 77 NULL, /* postconfiguration */
62 78
63 ngx_stream_core_create_main_conf, /* create main configuration */ 79 ngx_stream_core_create_main_conf, /* create main configuration */
64 NULL, /* init main configuration */ 80 ngx_stream_core_init_main_conf, /* init main configuration */
65 81
66 ngx_stream_core_create_srv_conf, /* create server configuration */ 82 ngx_stream_core_create_srv_conf, /* create server configuration */
67 ngx_stream_core_merge_srv_conf /* merge server configuration */ 83 ngx_stream_core_merge_srv_conf /* merge server configuration */
68 }; 84 };
69 85
82 NULL, /* exit master */ 98 NULL, /* exit master */
83 NGX_MODULE_V1_PADDING 99 NGX_MODULE_V1_PADDING
84 }; 100 };
85 101
86 102
103 static ngx_int_t
104 ngx_stream_core_preconfiguration(ngx_conf_t *cf)
105 {
106 return ngx_stream_variables_add_core_vars(cf);
107 }
108
109
87 static void * 110 static void *
88 ngx_stream_core_create_main_conf(ngx_conf_t *cf) 111 ngx_stream_core_create_main_conf(ngx_conf_t *cf)
89 { 112 {
90 ngx_stream_core_main_conf_t *cmcf; 113 ngx_stream_core_main_conf_t *cmcf;
91 114
105 != NGX_OK) 128 != NGX_OK)
106 { 129 {
107 return NULL; 130 return NULL;
108 } 131 }
109 132
133 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
134 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
135
110 return cmcf; 136 return cmcf;
137 }
138
139
140 static char *
141 ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf)
142 {
143 ngx_stream_core_main_conf_t *cmcf = conf;
144
145 ngx_conf_init_uint_value(cmcf->variables_hash_max_size, 1024);
146 ngx_conf_init_uint_value(cmcf->variables_hash_bucket_size, 64);
147
148 cmcf->variables_hash_bucket_size =
149 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
150
151 if (cmcf->ncaptures) {
152 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
153 }
154
155 return NGX_CONF_OK;
111 } 156 }
112 157
113 158
114 static void * 159 static void *
115 ngx_stream_core_create_srv_conf(ngx_conf_t *cf) 160 ngx_stream_core_create_srv_conf(ngx_conf_t *cf)