comparison src/http/modules/ngx_http_limit_zone_module.c @ 981:6fe76f377a62

fix key length and alignment
author Igor Sysoev <igor@sysoev.ru>
date Sun, 07 Jan 2007 09:18:26 +0000
parents 7cb910b4a58a
children dd128232e6ba
comparison
equal deleted inserted replaced
980:7cb910b4a58a 981:6fe76f377a62
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11 11
12 typedef struct { 12 typedef struct {
13 u_short len; 13 u_char color;
14 u_char len;
14 u_short conn; 15 u_short conn;
15 u_char data[1]; 16 u_char data[1];
16 } ngx_http_limit_zone_node_t; 17 } ngx_http_limit_zone_node_t;
17 18
18 19
146 node = node->right; 147 node = node->right;
147 continue; 148 continue;
148 } 149 }
149 150
150 if (hash == node->key ){ 151 if (hash == node->key ){
151 lz = (ngx_http_limit_zone_node_t *) &node->data; 152 lz = (ngx_http_limit_zone_node_t *) &node->color;
152 153
153 if (len == (size_t) lz->len 154 if (len == (size_t) lz->len
154 && ngx_strncmp(lz->data, vv->data, len) == 0) 155 && ngx_strncmp(lz->data, vv->data, len) == 0)
155 { 156 {
156 if (lz->conn < (u_short) lzcf->conn) { 157 if ((ngx_uint_t) lz->conn < lzcf->conn) {
157 lz->conn++; 158 lz->conn++;
158 goto done; 159 goto done;
159 } 160 }
160 161
161 ngx_shmtx_unlock(&shpool->mutex); 162 ngx_shmtx_unlock(&shpool->mutex);
163 return NGX_HTTP_SERVICE_UNAVAILABLE; 164 return NGX_HTTP_SERVICE_UNAVAILABLE;
164 } 165 }
165 } 166 }
166 } 167 }
167 168
168 n = offsetof(ngx_rbtree_node_t, data) 169 n = offsetof(ngx_rbtree_node_t, color)
169 + offsetof(ngx_http_limit_zone_node_t, data) 170 + offsetof(ngx_http_limit_zone_node_t, data)
170 + len; 171 + len;
171 172
172 node = ngx_slab_alloc_locked(shpool, n); 173 node = ngx_slab_alloc_locked(shpool, n);
173 if (node == NULL) { 174 if (node == NULL) {
174 ngx_shmtx_unlock(&shpool->mutex); 175 ngx_shmtx_unlock(&shpool->mutex);
175 return NGX_HTTP_SERVICE_UNAVAILABLE; 176 return NGX_HTTP_SERVICE_UNAVAILABLE;
176 } 177 }
177 178
178 lz = (ngx_http_limit_zone_node_t *) &node->data; 179 lz = (ngx_http_limit_zone_node_t *) &node->color;
179 180
180 node->key = hash; 181 node->key = hash;
181 lz->len = (u_short) len; 182 lz->len = (u_char) len;
182 lz->conn = 1; 183 lz->conn = 1;
183 ngx_memcpy(lz->data, vv->data, len); 184 ngx_memcpy(lz->data, vv->data, len);
184 185
185 ngx_rbtree_insert(rbtree, node); 186 ngx_rbtree_insert(rbtree, node);
186 187
212 ngx_http_limit_zone_node_t *lz; 213 ngx_http_limit_zone_node_t *lz;
213 214
214 rbtree = lzcln->shm_zone->data; 215 rbtree = lzcln->shm_zone->data;
215 shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr; 216 shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr;
216 node = lzcln->node; 217 node = lzcln->node;
217 lz = (ngx_http_limit_zone_node_t *) &node->data; 218 lz = (ngx_http_limit_zone_node_t *) &node->color;
218 219
219 ngx_shmtx_lock(&shpool->mutex); 220 ngx_shmtx_lock(&shpool->mutex);
220 221
221 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0, 222 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0,
222 "limit zone cleanup: %08XD %d", node->key, lz->conn); 223 "limit zone cleanup: %08XD %d", node->key, lz->conn);