Mercurial > hg > nginx
annotate src/os/win32/ngx_shmem.c @ 5115:a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
And corresponding variable $connections_waiting was added.
Previously, waiting connections were counted as the difference between
active connections and the sum of reading and writing connections.
That made it impossible to count more than one request in one connection
as reading or writing (as is the case for SPDY).
Also, we no longer count connections in handshake state as waiting.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Fri, 15 Mar 2013 20:00:49 +0000 |
parents | b3d4e9c66e24 |
children | af7eba90645d |
rev | line source |
---|---|
605 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
605 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 ngx_int_t | |
13 ngx_shm_alloc(ngx_shm_t *shm) | |
14 { | |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
15 u_char *name; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
16 uint64_t size; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
17 |
4570
b3d4e9c66e24
Win32: fixed memory allocation for shmem name (ticket #134).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
18 name = ngx_alloc(shm->name.len + 2 + NGX_INT32_LEN, shm->log); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
19 if (name == NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
20 return NGX_ERROR; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
21 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
22 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
23 (void) ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
24 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
25 ngx_set_errno(0); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
26 |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
27 size = shm->size; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
28 |
605 | 29 shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
30 (u_long) (size >> 32), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
31 (u_long) (size & 0xffffffff), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
32 (char *) name); |
605 | 33 |
34 if (shm->handle == NULL) { | |
35 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
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:
605
diff
changeset
|
36 "CreateFileMapping(%uz, %s) failed", |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
37 shm->size, name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
38 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
39 |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
40 return NGX_ERROR; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
41 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
42 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
43 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
44 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
45 if (ngx_errno == ERROR_ALREADY_EXISTS) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
46 shm->exists = 1; |
605 | 47 } |
48 | |
49 shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
50 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
51 if (shm->addr != NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
52 return NGX_OK; |
605 | 53 } |
54 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
55 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
56 "MapViewOfFile(%uz) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
57 shm->size, &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
58 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
59 if (CloseHandle(shm->handle) == 0) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
60 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
61 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
62 &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
63 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
64 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
65 return NGX_ERROR; |
605 | 66 } |
67 | |
68 | |
69 void | |
70 ngx_shm_free(ngx_shm_t *shm) | |
71 { | |
72 if (UnmapViewOfFile(shm->addr) == 0) { | |
73 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
74 "UnmapViewOfFile(%p) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
75 shm->addr, &shm->name); |
605 | 76 } |
77 | |
78 if (CloseHandle(shm->handle) == 0) { | |
79 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
80 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
81 &shm->name); |
605 | 82 } |
83 } |