Klaus Demo nginx / c7f876b
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory Igor Sysoev 13 years ago
12 changed file(s) with 58 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
411411 if (shm_zone[i].shm.size == 0) {
412412 ngx_log_error(NGX_LOG_EMERG, log, 0,
413413 "zero size shared memory zone \"%V\"",
414 &shm_zone[i].name);
414 &shm_zone[i].shm.name);
415415 goto failed;
416416 }
417417
436436 n = 0;
437437 }
438438
439 if (shm_zone[i].name.len != oshm_zone[n].name.len) {
439 if (shm_zone[i].shm.name.len != oshm_zone[n].shm.name.len) {
440440 continue;
441441 }
442442
443 if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data,
444 shm_zone[i].name.len)
443 if (ngx_strncmp(shm_zone[i].shm.name.data,
444 oshm_zone[n].shm.name.data,
445 shm_zone[i].shm.name.len)
445446 != 0)
446447 {
447448 continue;
671672 n = 0;
672673 }
673674
674 if (oshm_zone[i].name.len == shm_zone[n].name.len
675 && ngx_strncmp(oshm_zone[i].name.data,
676 shm_zone[n].name.data,
677 oshm_zone[i].name.len)
675 if (oshm_zone[i].shm.name.len == shm_zone[n].shm.name.len
676 && ngx_strncmp(oshm_zone[i].shm.name.data,
677 shm_zone[n].shm.name.data,
678 oshm_zone[i].shm.name.len)
678679 == 0)
679680 {
680681 goto live_shm_zone;
11741175 i = 0;
11751176 }
11761177
1177 if (name->len != shm_zone[i].name.len) {
1178 continue;
1179 }
1180
1181 if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) {
1178 if (name->len != shm_zone[i].shm.name.len) {
1179 continue;
1180 }
1181
1182 if (ngx_strncmp(name->data, shm_zone[i].shm.name.data, name->len)
1183 != 0)
1184 {
11821185 continue;
11831186 }
11841187
11851188 if (size && size != shm_zone[i].shm.size) {
11861189 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1187 "the size %uz of shared memory zone \"%V\" "
1188 "conflicts with already declared size %uz",
1189 size, &shm_zone[i].name, shm_zone[i].shm.size);
1190 "the size %uz of shared memory zone \"%V\" "
1191 "conflicts with already declared size %uz",
1192 size, &shm_zone[i].shm.name, shm_zone[i].shm.size);
11901193 return NULL;
11911194 }
11921195
11931196 if (tag != shm_zone[i].tag) {
11941197 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1195 "the shared memory zone \"%V\" is "
1196 "already declared for a different use",
1197 &shm_zone[i].name);
1198 "the shared memory zone \"%V\" is "
1199 "already declared for a different use",
1200 &shm_zone[i].shm.name);
11981201 return NULL;
11991202 }
12001203
12101213 shm_zone->data = NULL;
12111214 shm_zone->shm.log = cf->cycle->log;
12121215 shm_zone->shm.size = size;
1216 shm_zone->shm.name = *name;
12131217 shm_zone->init = NULL;
1214 shm_zone->name = *name;
12151218 shm_zone->tag = tag;
12161219
12171220 return shm_zone;
2828 void *data;
2929 ngx_shm_t shm;
3030 ngx_shm_zone_init_pt init;
31 ngx_str_t name;
3231 void *tag;
3332 };
3433
14321432
14331433 ngx_queue_init(&cache->expire_queue);
14341434
1435 len = sizeof(" in SSL session shared cache \"\"") + shm_zone->name.len;
1435 len = sizeof(" in SSL session shared cache \"\"") + shm_zone->shm.name.len;
14361436
14371437 shpool->log_ctx = ngx_slab_alloc(shpool, len);
14381438 if (shpool->log_ctx == NULL) {
14401440 }
14411441
14421442 ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
1443 &shm_zone->name);
1443 &shm_zone->shm.name);
14441444
14451445 shm_zone->data = cache;
14461446
20422042
20432043 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
20442044 "\"fastcgi_cache\" zone \"%V\" is unknown",
2045 &shm_zone->name);
2045 &shm_zone->shm.name);
20462046
20472047 return NGX_CONF_ERROR;
20482048 }
178178
179179 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
180180 "limiting requests, excess: %ui.%03ui by zone \"%V\"",
181 excess / 1000, excess % 1000, &lrcf->shm_zone->name);
181 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
182182
183183 return NGX_HTTP_SERVICE_UNAVAILABLE;
184184 }
192192
193193 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
194194 "delaying request, excess: %ui.%03ui, by zone \"%V\"",
195 excess / 1000, excess % 1000, &lrcf->shm_zone->name);
195 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
196196
197197 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
198198 return NGX_HTTP_INTERNAL_SERVER_ERROR;
462462 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
463463 "limit_req \"%V\" uses the \"%V\" variable "
464464 "while previously it used the \"%V\" variable",
465 &shm_zone->name, &ctx->var, &octx->var);
465 &shm_zone->shm.name, &ctx->var, &octx->var);
466466 return NGX_ERROR;
467467 }
468468
495495
496496 ngx_queue_init(ctx->queue);
497497
498 len = sizeof(" in limit_req zone \"\"") + shm_zone->name.len;
498 len = sizeof(" in limit_req zone \"\"") + shm_zone->shm.name.len;
499499
500500 ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
501501 if (ctx->shpool->log_ctx == NULL) {
503503 }
504504
505505 ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
506 &shm_zone->name);
506 &shm_zone->shm.name);
507507
508508 return NGX_OK;
509509 }
573573 p = (u_char *) ngx_strchr(name.data, ':');
574574
575575 if (p) {
576 *p = '\0';
577
576578 name.len = p - name.data;
577579
578580 p++;
743745 if (lrcf->shm_zone->data == NULL) {
744746 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
745747 "unknown limit_req_zone \"%V\"",
746 &lrcf->shm_zone->name);
748 &lrcf->shm_zone->shm.name);
747749 return NGX_CONF_ERROR;
748750 }
749751
190190
191191 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
192192 "limiting connections by zone \"%V\"",
193 &lzcf->shm_zone->name);
193 &lzcf->shm_zone->shm.name);
194194
195195 return NGX_HTTP_SERVICE_UNAVAILABLE;
196196 }
327327 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
328328 "limit_zone \"%V\" uses the \"%V\" variable "
329329 "while previously it used the \"%V\" variable",
330 &shm_zone->name, &ctx->var, &octx->var);
330 &shm_zone->shm.name, &ctx->var, &octx->var);
331331 return NGX_ERROR;
332332 }
333333
351351 ngx_rbtree_init(ctx->rbtree, sentinel,
352352 ngx_http_limit_zone_rbtree_insert_value);
353353
354 len = sizeof(" in limit_zone \"\"") + shm_zone->name.len;
354 len = sizeof(" in limit_zone \"\"") + shm_zone->shm.name.len;
355355
356356 shpool->log_ctx = ngx_slab_alloc(shpool, len);
357357 if (shpool->log_ctx == NULL) {
358358 return NGX_ERROR;
359359 }
360360
361 ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", &shm_zone->name);
361 ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z",
362 &shm_zone->shm.name);
362363
363364 return NGX_OK;
364365 }
21032103
21042104 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
21052105 "\"proxy_cache\" zone \"%V\" is unknown",
2106 &shm_zone->name);
2106 &shm_zone->shm.name);
21072107
21082108 return NGX_CONF_ERROR;
21092109 }
563563
564564 for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
565565 if (value[i].data[j] == ':') {
566 value[i].data[j] = '\0';
566567 break;
567568 }
568569
5353 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
5454 "cache \"%V\" uses the \"%V\" cache path "
5555 "while previously it used the \"%V\" cache path",
56 &shm_zone->name, &cache->path->name,
56 &shm_zone->shm.name, &cache->path->name,
5757 &ocache->path->name);
5858
5959 return NGX_ERROR;
111111
112112 cache->max_size /= cache->bsize;
113113
114 len = sizeof(" in cache keys zone \"\"") + shm_zone->name.len;
114 len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len;
115115
116116 cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
117117 if (cache->shpool->log_ctx == NULL) {
119119 }
120120
121121 ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
122 &shm_zone->name);
122 &shm_zone->shm.name);
123123
124124 return NGX_OK;
125125 }
13981398 p = (u_char *) ngx_strchr(name.data, ':');
13991399
14001400 if (p) {
1401 *p = '\0';
1402
14011403 name.len = p - name.data;
14021404
14031405 p++;
1212
1313
1414 typedef struct {
15 u_char *addr;
16 size_t size;
17 ngx_log_t *log;
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 ngx_log_t *log;
1819 } ngx_shm_t;
1920
2021
77 #include <ngx_core.h>
88
99
10 /*
11 * TODO:
12 * maping name or inheritable handle
13 */
14
1510 ngx_int_t
1611 ngx_shm_alloc(ngx_shm_t *shm)
1712 {
1813 shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
19 0, shm->size, NULL);
14 0, shm->size, (char *) shm->name.data);
2015
2116 if (shm->handle == NULL) {
2217 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
23 "CreateFileMapping(%uz) failed", shm->size);
18 "CreateFileMapping(%uz, %s) failed",
19 shm->size, shm->name.data);
2420 return NGX_ERROR;
2521 }
2622
1212
1313
1414 typedef struct {
15 u_char *addr;
16 size_t size;
17 HANDLE handle;
18 ngx_log_t *log;
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 HANDLE handle;
19 ngx_log_t *log;
1920 } ngx_shm_t;
2021
2122