Mercurial > hg > nginx
annotate src/http/modules/ngx_http_limit_conn_module.c @ 4280:91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 14 Nov 2011 14:04:42 +0000 |
parents | src/http/modules/ngx_http_limit_zone_module.c@260d591cb6a3 |
children | 7697412a0921 |
rev | line source |
---|---|
980 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 typedef struct { | |
981 | 13 u_char color; |
14 u_char len; | |
980 | 15 u_short conn; |
16 u_char data[1]; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
17 } ngx_http_limit_conn_node_t; |
980 | 18 |
19 | |
20 typedef struct { | |
21 ngx_shm_zone_t *shm_zone; | |
22 ngx_rbtree_node_t *node; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
23 } ngx_http_limit_conn_cleanup_t; |
980 | 24 |
25 | |
26 typedef struct { | |
987 | 27 ngx_rbtree_t *rbtree; |
28 ngx_int_t index; | |
29 ngx_str_t var; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
30 } ngx_http_limit_conn_ctx_t; |
987 | 31 |
32 | |
33 typedef struct { | |
980 | 34 ngx_shm_zone_t *shm_zone; |
35 ngx_uint_t conn; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
36 } ngx_http_limit_conn_limit_t; |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
37 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
38 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
39 typedef struct { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
40 ngx_array_t limits; |
3186 | 41 ngx_uint_t log_level; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
42 } ngx_http_limit_conn_conf_t; |
980 | 43 |
44 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
45 static ngx_rbtree_node_t *ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
46 ngx_http_variable_value_t *vv, uint32_t hash); |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
47 static void ngx_http_limit_conn_cleanup(void *data); |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
48 static ngx_inline void ngx_http_limit_conn_cleanup_all(ngx_pool_t *pool); |
980 | 49 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
50 static void *ngx_http_limit_conn_create_conf(ngx_conf_t *cf); |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
51 static char *ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, |
980 | 52 void *child); |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
53 static char *ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
54 void *conf); |
980 | 55 static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, |
56 void *conf); | |
57 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, | |
58 void *conf); | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
59 static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf); |
980 | 60 |
61 | |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
62 static ngx_conf_deprecated_t ngx_conf_deprecated_limit_zone = { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
63 ngx_conf_deprecated, "limit_zone", "limit_conn_zone" |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
64 }; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
65 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
66 |
3186 | 67 static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = { |
68 { ngx_string("info"), NGX_LOG_INFO }, | |
69 { ngx_string("notice"), NGX_LOG_NOTICE }, | |
70 { ngx_string("warn"), NGX_LOG_WARN }, | |
71 { ngx_string("error"), NGX_LOG_ERR }, | |
72 { ngx_null_string, 0 } | |
73 }; | |
74 | |
75 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
76 static ngx_command_t ngx_http_limit_conn_commands[] = { |
980 | 77 |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
78 { ngx_string("limit_conn_zone"), |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
79 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
80 ngx_http_limit_conn_zone, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
81 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
82 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
83 NULL }, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
84 |
980 | 85 { ngx_string("limit_zone"), |
987 | 86 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3, |
980 | 87 ngx_http_limit_zone, |
88 0, | |
89 0, | |
90 NULL }, | |
91 | |
92 { ngx_string("limit_conn"), | |
987 | 93 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
980 | 94 ngx_http_limit_conn, |
95 NGX_HTTP_LOC_CONF_OFFSET, | |
96 0, | |
97 NULL }, | |
98 | |
3186 | 99 { ngx_string("limit_conn_log_level"), |
100 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
101 ngx_conf_set_enum_slot, | |
102 NGX_HTTP_LOC_CONF_OFFSET, | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
103 offsetof(ngx_http_limit_conn_conf_t, log_level), |
3186 | 104 &ngx_http_limit_conn_log_levels }, |
105 | |
980 | 106 ngx_null_command |
107 }; | |
108 | |
109 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
110 static ngx_http_module_t ngx_http_limit_conn_module_ctx = { |
980 | 111 NULL, /* preconfiguration */ |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
112 ngx_http_limit_conn_init, /* postconfiguration */ |
980 | 113 |
114 NULL, /* create main configuration */ | |
115 NULL, /* init main configuration */ | |
116 | |
117 NULL, /* create server configuration */ | |
118 NULL, /* merge server configuration */ | |
119 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
120 ngx_http_limit_conn_create_conf, /* create location configration */ |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
121 ngx_http_limit_conn_merge_conf /* merge location configration */ |
980 | 122 }; |
123 | |
124 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
125 ngx_module_t ngx_http_limit_conn_module = { |
980 | 126 NGX_MODULE_V1, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
127 &ngx_http_limit_conn_module_ctx, /* module context */ |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
128 ngx_http_limit_conn_commands, /* module directives */ |
980 | 129 NGX_HTTP_MODULE, /* module type */ |
130 NULL, /* init master */ | |
131 NULL, /* init module */ | |
132 NULL, /* init process */ | |
133 NULL, /* init thread */ | |
134 NULL, /* exit thread */ | |
135 NULL, /* exit process */ | |
136 NULL, /* exit master */ | |
137 NGX_MODULE_V1_PADDING | |
138 }; | |
139 | |
140 | |
141 static ngx_int_t | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
142 ngx_http_limit_conn_handler(ngx_http_request_t *r) |
980 | 143 { |
144 size_t len, n; | |
145 uint32_t hash; | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
146 ngx_uint_t i; |
980 | 147 ngx_slab_pool_t *shpool; |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
148 ngx_rbtree_node_t *node; |
980 | 149 ngx_pool_cleanup_t *cln; |
150 ngx_http_variable_value_t *vv; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
151 ngx_http_limit_conn_ctx_t *ctx; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
152 ngx_http_limit_conn_node_t *lc; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
153 ngx_http_limit_conn_conf_t *lccf; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
154 ngx_http_limit_conn_limit_t *limits; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
155 ngx_http_limit_conn_cleanup_t *lccln; |
980 | 156 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
157 if (r->main->limit_conn_set) { |
984
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
158 return NGX_DECLINED; |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
159 } |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
160 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
161 r->main->limit_conn_set = 1; |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
162 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
163 lccf = ngx_http_get_module_loc_conf(r, ngx_http_limit_conn_module); |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
164 limits = lccf->limits.elts; |
980 | 165 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
166 for (i = 0; i < lccf->limits.nelts; i++) { |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
167 ctx = limits[i].shm_zone->data; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
168 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
169 vv = ngx_http_get_indexed_variable(r, ctx->index); |
980 | 170 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
171 if (vv == NULL || vv->not_found) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
172 continue; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
173 } |
980 | 174 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
175 len = vv->len; |
980 | 176 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
177 if (len == 0) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
178 continue; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
179 } |
980 | 180 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
181 if (len > 255) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
182 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
183 "the value of the \"%V\" variable " |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
184 "is more than 255 bytes: \"%v\"", |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
185 &ctx->var, vv); |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
186 continue; |
980 | 187 } |
188 | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
189 hash = ngx_crc32_short(vv->data, len); |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
190 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
191 shpool = (ngx_slab_pool_t *) limits[i].shm_zone->shm.addr; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
192 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
193 ngx_shmtx_lock(&shpool->mutex); |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
194 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
195 node = ngx_http_limit_conn_lookup(ctx->rbtree, vv, hash); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
196 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
197 if (node == NULL) { |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
198 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
199 n = offsetof(ngx_rbtree_node_t, color) |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
200 + offsetof(ngx_http_limit_conn_node_t, data) |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
201 + len; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
202 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
203 node = ngx_slab_alloc_locked(shpool, n); |
980 | 204 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
205 if (node == NULL) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
206 ngx_shmtx_unlock(&shpool->mutex); |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
207 ngx_http_limit_conn_cleanup_all(r->pool); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
208 return NGX_HTTP_SERVICE_UNAVAILABLE; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
209 } |
2373 | 210 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
211 lc = (ngx_http_limit_conn_node_t *) &node->color; |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
212 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
213 node->key = hash; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
214 lc->len = (u_char) len; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
215 lc->conn = 1; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
216 ngx_memcpy(lc->data, vv->data, len); |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
217 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
218 ngx_rbtree_insert(ctx->rbtree, node); |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
219 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
220 } else { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
221 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
222 lc = (ngx_http_limit_conn_node_t *) &node->color; |
980 | 223 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
224 if ((ngx_uint_t) lc->conn >= limits[i].conn) { |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
225 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
226 ngx_shmtx_unlock(&shpool->mutex); |
980 | 227 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
228 ngx_log_error(lccf->log_level, r->connection->log, 0, |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
229 "limiting connections by zone \"%V\"", |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
230 &limits[i].shm_zone->shm.name); |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
231 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
232 ngx_http_limit_conn_cleanup_all(r->pool); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
233 return NGX_HTTP_SERVICE_UNAVAILABLE; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
234 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
235 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
236 lc->conn++; |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
237 } |
980 | 238 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
239 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
240 "limit zone: %08XD %d", node->key, lc->conn); |
980 | 241 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
242 ngx_shmtx_unlock(&shpool->mutex); |
980 | 243 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
244 cln = ngx_pool_cleanup_add(r->pool, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
245 sizeof(ngx_http_limit_conn_cleanup_t)); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
246 if (cln == NULL) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
247 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
248 } |
980 | 249 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
250 cln->handler = ngx_http_limit_conn_cleanup; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
251 lccln = cln->data; |
980 | 252 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
253 lccln->shm_zone = limits[i].shm_zone; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
254 lccln->node = node; |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
255 } |
980 | 256 |
257 return NGX_DECLINED; | |
258 } | |
259 | |
260 | |
261 static void | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
262 ngx_http_limit_conn_rbtree_insert_value(ngx_rbtree_node_t *temp, |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
263 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
264 { |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
265 ngx_rbtree_node_t **p; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
266 ngx_http_limit_conn_node_t *lcn, *lcnt; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
267 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
268 for ( ;; ) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
269 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
270 if (node->key < temp->key) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
271 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
272 p = &temp->left; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
273 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
274 } else if (node->key > temp->key) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
275 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
276 p = &temp->right; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
277 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
278 } else { /* node->key == temp->key */ |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
279 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
280 lcn = (ngx_http_limit_conn_node_t *) &node->color; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
281 lcnt = (ngx_http_limit_conn_node_t *) &temp->color; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
282 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
283 p = (ngx_memn2cmp(lcn->data, lcnt->data, lcn->len, lcnt->len) < 0) |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
284 ? &temp->left : &temp->right; |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
285 } |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
286 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
287 if (*p == sentinel) { |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
288 break; |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
289 } |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
290 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
291 temp = *p; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
292 } |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
293 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
294 *p = node; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
295 node->parent = temp; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
296 node->left = sentinel; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
297 node->right = sentinel; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
298 ngx_rbt_red(node); |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
299 } |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
300 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
301 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
302 static ngx_rbtree_node_t * |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
303 ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_http_variable_value_t *vv, |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
304 uint32_t hash) |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
305 { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
306 ngx_int_t rc; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
307 ngx_rbtree_node_t *node, *sentinel; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
308 ngx_http_limit_conn_node_t *lcn; |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
309 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
310 node = rbtree->root; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
311 sentinel = rbtree->sentinel; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
312 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
313 while (node != sentinel) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
314 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
315 if (hash < node->key) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
316 node = node->left; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
317 continue; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
318 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
319 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
320 if (hash > node->key) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
321 node = node->right; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
322 continue; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
323 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
324 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
325 /* hash == node->key */ |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
326 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
327 do { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
328 lcn = (ngx_http_limit_conn_node_t *) &node->color; |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
329 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
330 rc = ngx_memn2cmp(vv->data, lcn->data, |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
331 (size_t) vv->len, (size_t) lcn->len); |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
332 if (rc == 0) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
333 return node; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
334 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
335 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
336 node = (rc < 0) ? node->left : node->right; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
337 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
338 } while (node != sentinel && hash == node->key); |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
339 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
340 break; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
341 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
342 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
343 return NULL; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
344 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
345 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
346 |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
347 static void |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
348 ngx_http_limit_conn_cleanup(void *data) |
980 | 349 { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
350 ngx_http_limit_conn_cleanup_t *lccln = data; |
980 | 351 |
352 ngx_slab_pool_t *shpool; | |
353 ngx_rbtree_node_t *node; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
354 ngx_http_limit_conn_ctx_t *ctx; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
355 ngx_http_limit_conn_node_t *lc; |
980 | 356 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
357 ctx = lccln->shm_zone->data; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
358 shpool = (ngx_slab_pool_t *) lccln->shm_zone->shm.addr; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
359 node = lccln->node; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
360 lc = (ngx_http_limit_conn_node_t *) &node->color; |
980 | 361 |
362 ngx_shmtx_lock(&shpool->mutex); | |
363 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
364 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lccln->shm_zone->shm.log, 0, |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
365 "limit zone cleanup: %08XD %d", node->key, lc->conn); |
980 | 366 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
367 lc->conn--; |
980 | 368 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
369 if (lc->conn == 0) { |
987 | 370 ngx_rbtree_delete(ctx->rbtree, node); |
980 | 371 ngx_slab_free_locked(shpool, node); |
372 } | |
373 | |
374 ngx_shmtx_unlock(&shpool->mutex); | |
375 } | |
376 | |
377 | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
378 static ngx_inline void |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
379 ngx_http_limit_conn_cleanup_all(ngx_pool_t *pool) |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
380 { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
381 ngx_pool_cleanup_t *cln; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
382 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
383 cln = pool->cleanup; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
384 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
385 while (cln && cln->handler == ngx_http_limit_conn_cleanup) { |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
386 ngx_http_limit_conn_cleanup(cln->data); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
387 cln = cln->next; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
388 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
389 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
390 pool->cleanup = cln; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
391 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
392 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
393 |
980 | 394 static ngx_int_t |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
395 ngx_http_limit_conn_init_zone(ngx_shm_zone_t *shm_zone, void *data) |
980 | 396 { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
397 ngx_http_limit_conn_ctx_t *octx = data; |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
398 |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
399 size_t len; |
987 | 400 ngx_slab_pool_t *shpool; |
401 ngx_rbtree_node_t *sentinel; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
402 ngx_http_limit_conn_ctx_t *ctx; |
980 | 403 |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
404 ctx = shm_zone->data; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
405 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
406 if (octx) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
407 if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
408 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
409 "limit_conn_zone \"%V\" uses the \"%V\" variable " |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
410 "while previously it used the \"%V\" variable", |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2612
diff
changeset
|
411 &shm_zone->shm.name, &ctx->var, &octx->var); |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
412 return NGX_ERROR; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
413 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
414 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
415 ctx->rbtree = octx->rbtree; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
416 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
417 return NGX_OK; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
418 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
419 |
980 | 420 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; |
421 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
422 if (shm_zone->shm.exists) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
423 ctx->rbtree = shpool->data; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
424 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
425 return NGX_OK; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
426 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
427 |
987 | 428 ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t)); |
429 if (ctx->rbtree == NULL) { | |
980 | 430 return NGX_ERROR; |
431 } | |
432 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
433 shpool->data = ctx->rbtree; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
434 |
980 | 435 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t)); |
436 if (sentinel == NULL) { | |
437 return NGX_ERROR; | |
438 } | |
439 | |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
440 ngx_rbtree_init(ctx->rbtree, sentinel, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
441 ngx_http_limit_conn_rbtree_insert_value); |
980 | 442 |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
443 len = sizeof(" in limit_conn_zone \"\"") + shm_zone->shm.name.len; |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
444 |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
445 shpool->log_ctx = ngx_slab_alloc(shpool, len); |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
446 if (shpool->log_ctx == NULL) { |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
447 return NGX_ERROR; |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
448 } |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
449 |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
450 ngx_sprintf(shpool->log_ctx, " in limit_conn_zone \"%V\"%Z", |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2612
diff
changeset
|
451 &shm_zone->shm.name); |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
452 |
980 | 453 return NGX_OK; |
454 } | |
455 | |
456 | |
457 static void * | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
458 ngx_http_limit_conn_create_conf(ngx_conf_t *cf) |
980 | 459 { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
460 ngx_http_limit_conn_conf_t *conf; |
980 | 461 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
462 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_conf_t)); |
980 | 463 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2720
diff
changeset
|
464 return NULL; |
980 | 465 } |
466 | |
467 /* | |
468 * set by ngx_pcalloc(): | |
469 * | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
470 * conf->limits.elts = NULL; |
980 | 471 */ |
472 | |
3186 | 473 conf->log_level = NGX_CONF_UNSET_UINT; |
474 | |
980 | 475 return conf; |
476 } | |
477 | |
478 | |
479 static char * | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
480 ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
980 | 481 { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
482 ngx_http_limit_conn_conf_t *prev = parent; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
483 ngx_http_limit_conn_conf_t *conf = child; |
980 | 484 |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
485 if (conf->limits.elts == NULL) { |
980 | 486 *conf = *prev; |
487 } | |
488 | |
3186 | 489 ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR); |
490 | |
980 | 491 return NGX_CONF_OK; |
492 } | |
493 | |
494 | |
495 static char * | |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
496 ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
497 { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
498 u_char *p; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
499 ssize_t size; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
500 ngx_str_t *value, name, s; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
501 ngx_uint_t i; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
502 ngx_shm_zone_t *shm_zone; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
503 ngx_http_limit_conn_ctx_t *ctx; |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
504 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
505 value = cf->args->elts; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
506 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
507 ctx = NULL; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
508 size = 0; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
509 name.len = 0; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
510 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
511 for (i = 1; i < cf->args->nelts; i++) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
512 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
513 if (ngx_strncmp(value[i].data, "zone=", 5) == 0) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
514 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
515 name.data = value[i].data + 5; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
516 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
517 p = (u_char *) ngx_strchr(name.data, ':'); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
518 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
519 if (p == NULL) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
520 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
521 "invalid zone size \"%V\"", &value[i]); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
522 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
523 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
524 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
525 name.len = p - name.data; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
526 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
527 s.data = p + 1; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
528 s.len = value[i].data + value[i].len - s.data; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
529 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
530 size = ngx_parse_size(&s); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
531 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
532 if (size == NGX_ERROR) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
533 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
534 "invalid zone size \"%V\"", &value[i]); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
535 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
536 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
537 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
538 if (size < (ssize_t) (8 * ngx_pagesize)) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
539 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
540 "zone \"%V\" is too small", &value[i]); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
541 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
542 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
543 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
544 continue; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
545 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
546 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
547 if (value[i].data[0] == '$') { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
548 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
549 value[i].len--; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
550 value[i].data++; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
551 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
552 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t)); |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
553 if (ctx == NULL) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
554 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
555 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
556 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
557 ctx->index = ngx_http_get_variable_index(cf, &value[i]); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
558 if (ctx->index == NGX_ERROR) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
559 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
560 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
561 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
562 ctx->var = value[i]; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
563 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
564 continue; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
565 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
566 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
567 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
568 "invalid parameter \"%V\"", &value[i]); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
569 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
570 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
571 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
572 if (name.len == 0) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
573 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
574 "\"%V\" must have \"zone\" parameter", |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
575 &cmd->name); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
576 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
577 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
578 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
579 if (ctx == NULL) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
580 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
581 "no variable is defined for %V \"%V\"", |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
582 &cmd->name, &name); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
583 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
584 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
585 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
586 shm_zone = ngx_shared_memory_add(cf, &name, size, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
587 &ngx_http_limit_conn_module); |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
588 if (shm_zone == NULL) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
589 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
590 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
591 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
592 if (shm_zone->data) { |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
593 ctx = shm_zone->data; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
594 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
595 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
596 "%V \"%V\" is already bound to variable \"%V\"", |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
597 &cmd->name, &name, &ctx->var); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
598 return NGX_CONF_ERROR; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
599 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
600 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
601 shm_zone->init = ngx_http_limit_conn_init_zone; |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
602 shm_zone->data = ctx; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
603 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
604 return NGX_CONF_OK; |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
605 } |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
606 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
607 |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
608 static char * |
980 | 609 ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
610 { | |
987 | 611 ssize_t n; |
612 ngx_str_t *value; | |
613 ngx_shm_zone_t *shm_zone; | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
614 ngx_http_limit_conn_ctx_t *ctx; |
980 | 615 |
4272
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
616 ngx_conf_deprecated(cf, &ngx_conf_deprecated_limit_zone, NULL); |
260d591cb6a3
Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4271
diff
changeset
|
617 |
980 | 618 value = cf->args->elts; |
619 | |
987 | 620 if (value[2].data[0] != '$') { |
621 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
622 "invalid variable name \"%V\"", &value[2]); | |
623 return NGX_CONF_ERROR; | |
624 } | |
625 | |
626 value[2].len--; | |
627 value[2].data++; | |
628 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
629 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t)); |
987 | 630 if (ctx == NULL) { |
631 return NGX_CONF_ERROR; | |
632 } | |
633 | |
634 ctx->index = ngx_http_get_variable_index(cf, &value[2]); | |
635 if (ctx->index == NGX_ERROR) { | |
636 return NGX_CONF_ERROR; | |
637 } | |
638 | |
639 ctx->var = value[2]; | |
640 | |
641 n = ngx_parse_size(&value[3]); | |
980 | 642 |
643 if (n == NGX_ERROR) { | |
644 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
987 | 645 "invalid size of limit_zone \"%V\"", &value[3]); |
980 | 646 return NGX_CONF_ERROR; |
647 } | |
648 | |
649 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
650 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
651 "limit_zone \"%V\" is too small", &value[1]); | |
652 return NGX_CONF_ERROR; | |
653 } | |
654 | |
655 | |
656 shm_zone = ngx_shared_memory_add(cf, &value[1], n, | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
657 &ngx_http_limit_conn_module); |
980 | 658 if (shm_zone == NULL) { |
659 return NGX_CONF_ERROR; | |
660 } | |
661 | |
987 | 662 if (shm_zone->data) { |
663 ctx = shm_zone->data; | |
664 | |
665 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
666 "limit_zone \"%V\" is already bound to variable \"%V\"", | |
667 &value[1], &ctx->var); | |
668 return NGX_CONF_ERROR; | |
669 } | |
670 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
671 shm_zone->init = ngx_http_limit_conn_init_zone; |
987 | 672 shm_zone->data = ctx; |
980 | 673 |
674 return NGX_CONF_OK; | |
675 } | |
676 | |
677 | |
678 static char * | |
679 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
680 { | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
681 ngx_shm_zone_t *shm_zone; |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
682 ngx_http_limit_conn_conf_t *lccf = conf; |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
683 ngx_http_limit_conn_limit_t *limit, *limits; |
980 | 684 |
685 ngx_str_t *value; | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
686 ngx_int_t n; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
687 ngx_uint_t i; |
2372 | 688 |
980 | 689 value = cf->args->elts; |
690 | |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
691 shm_zone = ngx_shared_memory_add(cf, &value[1], 0, |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
692 &ngx_http_limit_conn_module); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
693 if (shm_zone == NULL) { |
980 | 694 return NGX_CONF_ERROR; |
695 } | |
696 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
697 limits = lccf->limits.elts; |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
698 |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
699 if (limits == NULL) { |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
700 if (ngx_array_init(&lccf->limits, cf->pool, 1, |
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
701 sizeof(ngx_http_limit_conn_limit_t)) |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
702 != NGX_OK) |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
703 { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
704 return NGX_CONF_ERROR; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
705 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
706 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
707 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
708 for (i = 0; i < lccf->limits.nelts; i++) { |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
709 if (shm_zone == limits[i].shm_zone) { |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
710 return "is duplicate"; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
711 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
712 } |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
713 |
987 | 714 n = ngx_atoi(value[2].data, value[2].len); |
715 if (n <= 0) { | |
980 | 716 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
987 | 717 "invalid number of connections \"%V\"", &value[2]); |
980 | 718 return NGX_CONF_ERROR; |
719 } | |
720 | |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
721 if (n > 65535) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
722 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
723 "connection limit must be less 65536"); |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
724 return NGX_CONF_ERROR; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
725 } |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
726 |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
727 limit = ngx_array_push(&lccf->limits); |
4271
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
728 limit->conn = n; |
b86cceba426a
Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents:
4270
diff
changeset
|
729 limit->shm_zone = shm_zone; |
980 | 730 |
731 return NGX_CONF_OK; | |
732 } | |
733 | |
734 | |
735 static ngx_int_t | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
736 ngx_http_limit_conn_init(ngx_conf_t *cf) |
980 | 737 { |
738 ngx_http_handler_pt *h; | |
739 ngx_http_core_main_conf_t *cmcf; | |
740 | |
741 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
742 | |
743 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers); | |
744 if (h == NULL) { | |
745 return NGX_ERROR; | |
746 } | |
747 | |
4280
91874133fb27
Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents:
4272
diff
changeset
|
748 *h = ngx_http_limit_conn_handler; |
980 | 749 |
750 return NGX_OK; | |
751 } |