diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-11-17 00:49:42 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-11-17 00:49:42 +0300 |
commit | f2e676aa1585de170b39cf3e9d71b88db47e4b1b (patch) | |
tree | 3553b3481de51b2321b201ae34024f178af894c1 /src/os/win32 | |
parent | 297c0487518d4b974a548dfd3d5d2f10c250177c (diff) |
nginx-0.0.1-2003-11-17-00:49:42 import
Diffstat (limited to 'src/os/win32')
-rw-r--r-- | src/os/win32/ngx_errno.c | 28 | ||||
-rw-r--r-- | src/os/win32/ngx_errno.h | 5 | ||||
-rw-r--r-- | src/os/win32/ngx_files.c | 70 | ||||
-rw-r--r-- | src/os/win32/ngx_files.h | 88 | ||||
-rw-r--r-- | src/os/win32/ngx_os.h | 1 | ||||
-rw-r--r-- | src/os/win32/ngx_socket.h | 6 | ||||
-rw-r--r-- | src/os/win32/ngx_types.h | 8 | ||||
-rw-r--r-- | src/os/win32/ngx_win32_config.h | 23 | ||||
-rw-r--r-- | src/os/win32/ngx_win32_init.c | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_wsarecv_chain.c | 72 |
10 files changed, 255 insertions, 48 deletions
diff --git a/src/os/win32/ngx_errno.c b/src/os/win32/ngx_errno.c index 3a9487c06..865fbe37b 100644 --- a/src/os/win32/ngx_errno.c +++ b/src/os/win32/ngx_errno.c @@ -9,7 +9,7 @@ #include <ngx_core.h> -ngx_str_t wsa_errors[] = { +static ngx_str_t wsa_errors[] = { ngx_string("Invalid argument"), /* 10022 */ ngx_null_string, /* 10023 */ ngx_null_string, /* 10024 */ @@ -23,7 +23,29 @@ ngx_str_t wsa_errors[] = { ngx_null_string, /* 10032 */ ngx_null_string, /* 10033 */ ngx_null_string, /* 10034 */ - ngx_string("Resource temporarily unavailable") /* 10035 */ + ngx_string("Resource temporarily unavailable"), /* 10035 */ + ngx_null_string, /* 10036 */ + ngx_null_string, /* 10037 */ + ngx_null_string, /* 10038 */ + ngx_null_string, /* 10039 */ + ngx_null_string, /* 10040 */ + ngx_null_string, /* 10041 */ + ngx_null_string, /* 10042 */ + ngx_null_string, /* 10043 */ + ngx_null_string, /* 10044 */ + ngx_null_string, /* 10045 */ + ngx_null_string, /* 10046 */ + ngx_null_string, /* 10047 */ + ngx_null_string, /* 10048 */ + ngx_null_string, /* 10049 */ + ngx_null_string, /* 10050 */ + ngx_null_string, /* 10051 */ + ngx_null_string, /* 10052 */ + ngx_null_string, /* 10053 */ + ngx_null_string, /* 10054 */ + ngx_null_string, /* 10055 */ + ngx_null_string, /* 10056 */ + ngx_string("Socket is not connected") /* 10057 */ }; @@ -45,7 +67,7 @@ int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size) if (format_error == ERROR_MR_MID_NOT_FOUND) { n = err - WSABASEERR - 22; - if (n >= 0 && n < 14) { + if (n >= 0 && n <= 35) { len = wsa_errors[n].len; if (len) { diff --git a/src/os/win32/ngx_errno.h b/src/os/win32/ngx_errno.h index e94dbe066..179cbbce5 100644 --- a/src/os/win32/ngx_errno.h +++ b/src/os/win32/ngx_errno.h @@ -9,6 +9,7 @@ typedef DWORD ngx_err_t; #define ngx_errno GetLastError() +#define ngx_set_errno(err) SetLastError(err) #define ngx_socket_errno WSAGetLastError() #define ngx_set_socket_errno(err) WSASetLastError(err) @@ -21,6 +22,10 @@ typedef DWORD ngx_err_t; #define NGX_EADDRINUSE WSAEADDRINUSE #define NGX_ECONNRESET ECONNRESET #define NGX_ETIMEDOUT WSAETIMEDOUT +#define NGX_ENOMOREFILES ERROR_NO_MORE_FILES + +#define NGX_EALREADY WSAEALREADY +#define NGX_EINVAL WSAEINVAL int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size); diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c index 7e2346288..3906ddc49 100644 --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -163,14 +163,16 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, } -int ngx_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool) +int ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool) { int rc, collision; u_int num; char *name; - ngx_err_t err; - name = ngx_palloc(pool, to->len + 1 + 10 + 1 + sizeof("DELETE")); + if (!(name = ngx_palloc(pool, to->len + 1 + 10 + 1 + sizeof("DELETE")))) { + return NGX_ERROR; + } + ngx_memcpy(name, to->data, to->len); collision = 0; @@ -184,11 +186,6 @@ int ngx_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool) ".%010u.DELETE", num); if (MoveFile(to->data, name) == 0) { - err = ngx_errno; - if (err == NGX_ENOENT || err == NGX_ENOTDIR) { - return NGX_ERROR; - } - collision = 1; ngx_log_error(NGX_LOG_ERR, pool->log, ngx_errno, "MoveFile() failed"); @@ -196,18 +193,21 @@ int ngx_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool) } while (collision); + if (MoveFile(from->data, to->data) == 0) { + rc = NGX_ERROR; + + } else { + rc = NGX_OK; + } + if (ngx_win32_version >= NGX_WIN_NT) { if (DeleteFile(name) == 0) { ngx_log_error(NGX_LOG_ERR, pool->log, ngx_errno, "DeleteFile() failed"); } - } - - if (MoveFile(from->data, to->data) == 0) { - rc = NGX_ERROR; } else { - rc = NGX_OK; + /* TODO: Win9X: update the open files table */ } if (rc == NGX_ERROR) { @@ -220,7 +220,9 @@ int ngx_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool) } -int ngx_file_type(char *file, ngx_file_info_t *sb) +#if 0 + +int ngx_file_info(char *file, ngx_file_info_t *sb) { WIN32_FILE_ATTRIBUTE_DATA fa; @@ -240,13 +242,13 @@ int ngx_file_type(char *file, ngx_file_info_t *sb) return NGX_OK; } +#endif -#if 0 - -/* Win95 */ -int ngx_file_type(char *file, ngx_file_info_t *sb) +int ngx_file_info(char *file, ngx_file_info_t *sb) { + /* Win95 */ + sb->dwFileAttributes = GetFileAttributes(file); if (sb->dwFileAttributes == INVALID_FILE_ATTRIBUTES) { @@ -256,7 +258,37 @@ int ngx_file_type(char *file, ngx_file_info_t *sb) return NGX_OK; } -#endif + +int ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) +{ + ngx_cpystrn(name->data + name->len, NGX_DIR_MASK, NGX_DIR_MASK_LEN + 1); + + dir->dir = FindFirstFile(name->data, &dir->fd); + + if (dir->dir == INVALID_HANDLE_VALUE) { + return NGX_ERROR; + } + + dir->info_valid = 1; + dir->ready = 1; + + return NGX_OK; +} + + +int ngx_read_dir(ngx_dir_t *dir) +{ + if (dir->ready) { + dir->ready = 0; + return NGX_OK; + } + + if (FindNextFile(dir->dir, &dir->fd) == 0) { + return NGX_ERROR; + } + + return NGX_OK; +} int ngx_file_append_mode(ngx_fd_t fd) diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h index d7d7d00b3..1268d47c0 100644 --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -21,6 +21,8 @@ #define NGX_FILE_ERROR 0 +#define STDERR_FILENO (HANDLE) 2 + #define ngx_open_file(name, access, create) \ CreateFile(name, access, \ @@ -58,35 +60,87 @@ int ngx_file_append_mode(ngx_fd_t fd); #define ngx_close_file CloseHandle #define ngx_close_file_n "CloseHandle()" -int ngx_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool); + +#define ngx_delete_file DeleteFile +#define ngx_delete_file_n "DeleteFile()" + + +#define ngx_rename_file MoveFile #define ngx_rename_file_n "MoveFile()" +int ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool); + + +int ngx_file_info(char *filename, ngx_file_info_t *fi); +#define ngx_file_info_n "GetFileAttributesEx()" + -#define ngx_mkdir(name) CreateDirectory(name, NULL) -#define ngx_mkdir_n "CreateDirectory()" +#define ngx_fd_info(fd, fi) GetFileInformationByHandle(fd, fi) +#define ngx_fd_info_n "GetFileInformationByHandle" -int ngx_file_type(char *filename, ngx_file_info_t *fi); -#define ngx_file_type_n "GetFileAttributesEx()" -#define ngx_stat_fd(fd, fi) GetFileInformationByHandle(fd, fi) -#define ngx_stat_fd_n "GetFileInformationByHandle" +#define ngx_is_dir(fi) ((fi)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +#define ngx_is_file(fi) !((fi)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) -#define ngx_is_dir(fi) (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) -#define ngx_is_file(fi) !(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) -#define ngx_file_size(fi) \ - (((off_t) fi.nFileSizeHigh << 32) | fi.nFileSizeLow) +#define ngx_file_size(fi) \ + (((off_t) (fi)->nFileSizeHigh << 32) | (fi)->nFileSizeLow) -#define ngx_file_uniq(fi) (*(ngx_file_uniq_t *) &fi.nFileIndexHigh) +#define ngx_file_uniq(fi) (*(ngx_file_uniq_t *) &(fi)->nFileIndexHigh) /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ -#define ngx_file_mtime(fi) \ - (time_t) (((((unsigned __int64) fi.ftLastWriteTime.dwHighDateTime << 32) \ - | fi.ftLastWriteTime.dwLowDateTime) \ +#define ngx_file_mtime(fi) \ + (time_t) (((((unsigned __int64) (fi)->ftLastWriteTime.dwHighDateTime << 32) \ + | (fi)->ftLastWriteTime.dwLowDateTime) \ - 116444736000000000) / 10000000) +#define NGX_DIR_MASK "/*" +#define NGX_DIR_MASK_LEN 2 + + +int ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir); +#define ngx_open_dir_n "FindFirstFile()" + + +int ngx_read_dir(ngx_dir_t *dir); +#define ngx_read_dir_n "FindNextFile()" + + +#define ngx_close_dir(d) FindClose((d)->dir) +#define ngx_close_dir_n "FindClose()" + + +#define ngx_create_dir(name) CreateDirectory(name, NULL) +#define ngx_create_dir_n "CreateDirectory()" + + +#define ngx_delete_dir RemoveDirectory +#define ngx_delete_dir_n "RemoveDirectory()" + + +#define ngx_de_name(dir) (dir)->fd.cFileName +#define ngx_de_namelen(dir) ngx_strlen((dir)->fd.cFileName) +#define ngx_de_info(name, dir) NGX_OK +#define ngx_de_info_n "dummy()" +#define ngx_de_is_dir(dir) \ + ((dir)->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +#define ngx_de_is_file(dir) \ + !((dir)->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +#define ngx_de_size(dir) \ + (((off_t) (dir)->fd.nFileSizeHigh << 32) | (dir)->fd.nFileSizeLow) + +/* 116444736000000000 is commented in src/os/win32/ngx_time.c */ + +#define ngx_de_mtime(dir) \ + (time_t) (((((unsigned __int64) \ + (dir)->fd.ftLastWriteTime.dwHighDateTime << 32) \ + | (dir)->fd.ftLastWriteTime.dwLowDateTime) \ + - 116444736000000000) / 10000000) + + + ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset); #define ngx_read_file_n "ReadFile()" @@ -96,8 +150,4 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *ce, off_t offset, ngx_pool_t *pool); - -#define STDERR_FILENO (HANDLE) 2 - - #endif /* _NGX_FILES_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h index 52a7c05a8..bf5253b00 100644 --- a/src/os/win32/ngx_os.h +++ b/src/os/win32/ngx_os.h @@ -35,6 +35,7 @@ int ngx_os_init(ngx_log_t *log); ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size); ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, char *buf, size_t size); +ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain); ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in); ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in); diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h index a78c40c6b..86231030f 100644 --- a/src/os/win32/ngx_socket.h +++ b/src/os/win32/ngx_socket.h @@ -13,8 +13,12 @@ typedef SOCKET ngx_socket_t; typedef int socklen_t; +#define ngx_socket(af, type, proto, flags) socket(af, type, proto) + +#if 0 #define ngx_socket(af, type, proto, flags) \ WSASocket(af, type, proto, NULL, 0, flags) +#endif #define ngx_socket_n "WSASocket()" @@ -36,7 +40,7 @@ extern LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs; extern LPFN_TRANSMITFILE transmitfile; -ngx_inline int ngx_tcp_push(s) { +static ngx_inline int ngx_tcp_push(ngx_socket_t s) { return 0; } diff --git a/src/os/win32/ngx_types.h b/src/os/win32/ngx_types.h index fe4af4496..760342968 100644 --- a/src/os/win32/ngx_types.h +++ b/src/os/win32/ngx_types.h @@ -11,11 +11,11 @@ typedef BY_HANDLE_FILE_INFORMATION ngx_file_info_t; typedef uint64_t ngx_file_uniq_t; typedef struct { - HANDLE dir; - WIN32_FIND_DATA de; + HANDLE dir; + WIN32_FIND_DATA fd; + unsigned info_valid; + unsigned ready; } ngx_dir_t; -typedef WIN32_FIND_DATA ngx_dirent_t; - #endif /* _NGX_TYPES_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h index 23164328b..defddab94 100644 --- a/src/os/win32/ngx_win32_config.h +++ b/src/os/win32/ngx_win32_config.h @@ -6,7 +6,18 @@ #define NGX_WIN_NT 200000 +#define STRICT +#define WIN32_LEAN_AND_MEAN +/* + * we need to include windows.h explicity before winsock2.h because + * warning 4201 is enabled in windows.h + */ +#include <windows.h> + +#ifdef _MSC_VER +#pragma warning(disable:4201) +#endif #include <winsock2.h> #include <mswsock.h> @@ -15,6 +26,16 @@ #include <stdlib.h> #include <stdarg.h> +#ifdef _MSC_VER +#pragma warning(default:4201) + +/* unreferenced formal parameter */ +#pragma warning(disable:4100) + +/* STUB */ +#pragma warning(disable:4127) +#endif + #define ngx_inline __inline @@ -30,7 +51,7 @@ typedef u_int uintptr_t; typedef int ssize_t; typedef long time_t; -typedef unsigned __int64 off_t; +typedef __int64 off_t; #define OFF_FMT "%I64d" diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c index 77e4462d0..3c3509c02 100644 --- a/src/os/win32/ngx_win32_init.c +++ b/src/os/win32/ngx_win32_init.c @@ -10,7 +10,7 @@ int ngx_inherited_nonblocking = 1; ngx_os_io_t ngx_os_io = { ngx_wsarecv, - NULL, + ngx_wsarecv_chain, NULL, ngx_wsasend_chain, 0 diff --git a/src/os/win32/ngx_wsarecv_chain.c b/src/os/win32/ngx_wsarecv_chain.c new file mode 100644 index 000000000..edc4421dd --- /dev/null +++ b/src/os/win32/ngx_wsarecv_chain.c @@ -0,0 +1,72 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_event.h> + + +ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain) +{ + int rc; + char *prev; + u_int flags; + size_t bytes, size; + WSABUF *wsabuf; + ngx_err_t err; + ngx_array_t io; + ngx_event_t *rev; + + prev = NULL; + wsabuf = NULL; + flags = 0; + size = 0; + bytes = 0; + + ngx_init_array(io, c->pool, 10, sizeof(WSABUF), NGX_ERROR); + + /* coalesce the neighbouring hunks */ + + while (chain) { + if (prev == chain->hunk->last) { + wsabuf->len += chain->hunk->end - chain->hunk->last; + + } else { + ngx_test_null(wsabuf, ngx_push_array(&io), NGX_ERROR); + wsabuf->buf = chain->hunk->last; + wsabuf->len = chain->hunk->end - chain->hunk->last; + } + + size += chain->hunk->end - chain->hunk->last; + prev = chain->hunk->end; + chain = chain->next; + } + +ngx_log_debug(c->log, "WSARecv: %d:%d" _ io.nelts _ wsabuf->len); + + rc = WSARecv(c->fd, io.elts, io.nelts, &bytes, &flags, NULL, NULL); + + rev = c->read; + + if (rc == -1) { + rev->ready = 0; + err = ngx_socket_errno; + + if (err == WSAEWOULDBLOCK) { + ngx_log_error(NGX_LOG_INFO, c->log, err, "WSARecv() EAGAIN"); + return NGX_AGAIN; + } + + rev->error = 1; + ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSARecv() failed"); + return NGX_ERROR; + } + + if (bytes < size) { + rev->ready = 0; + } + + if (bytes == 0) { + rev->eof = 1; + } + + return bytes; +} |