diff options
Diffstat (limited to 'src/os/win32')
-rw-r--r-- | src/os/win32/ngx_shared.h | 18 | ||||
-rw-r--r-- | src/os/win32/ngx_shmem.c | 58 | ||||
-rw-r--r-- | src/os/win32/ngx_shmem.h | 27 |
3 files changed, 85 insertions, 18 deletions
diff --git a/src/os/win32/ngx_shared.h b/src/os/win32/ngx_shared.h deleted file mode 100644 index 29e4a33d5..000000000 --- a/src/os/win32/ngx_shared.h +++ /dev/null @@ -1,18 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - */ - - -#ifndef _NGX_SHARED_H_INCLUDED_ -#define _NGX_SHARED_H_INCLUDED_ - - -#include <ngx_config.h> -#include <ngx_core.h> - - -void *ngx_create_shared_memory(size_t size, ngx_log_t *log); - - -#endif /* _NGX_SHARED_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_shmem.c b/src/os/win32/ngx_shmem.c new file mode 100644 index 000000000..5c8fb6223 --- /dev/null +++ b/src/os/win32/ngx_shmem.c @@ -0,0 +1,58 @@ + +/* + * Copyright (C) Igor Sysoev + */ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +/* + * TODO: + * maping name or inheritable handle + */ + +ngx_int_t +ngx_shm_alloc(ngx_shm_t *shm) +{ + shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, + 0, shm->size, NULL); + + if (shm->handle == NULL) { + ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, + "CreateFileMapping(%uz) failed", shm->size); + return NGX_ERROR; + } + + shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0); + + if (shm->addr == NULL) { + ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, + "MapViewOfFile(%uz) failed", shm->size); + + if (CloseHandle(shm->handle) == 0) { + ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, + "CloseHandle() failed"); + } + + return NGX_ERROR; + } + + return NGX_OK; +} + + +void +ngx_shm_free(ngx_shm_t *shm) +{ + if (UnmapViewOfFile(shm->addr) == 0) { + ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, + "UnmapViewOfFile(%p) failed", shm->addr); + } + + if (CloseHandle(shm->handle) == 0) { + ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, + "CloseHandle() failed"); + } +} diff --git a/src/os/win32/ngx_shmem.h b/src/os/win32/ngx_shmem.h new file mode 100644 index 000000000..fe3e71df6 --- /dev/null +++ b/src/os/win32/ngx_shmem.h @@ -0,0 +1,27 @@ + +/* + * Copyright (C) Igor Sysoev + */ + + +#ifndef _NGX_SHARED_H_INCLUDED_ +#define _NGX_SHARED_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +typedef struct { + u_char *addr; + size_t size; + HANDLE handle; + ngx_log_t *log; +} ngx_shm_t; + + +ngx_int_t ngx_shm_alloc(ngx_shm_t *shm); +void ngx_shm_free(ngx_shm_t *shm); + + +#endif /* _NGX_SHARED_H_INCLUDED_ */ |