2003-05-19 12:39:14 -04:00
|
|
|
|
2004-09-28 04:34:51 -04:00
|
|
|
/*
|
2004-09-29 12:00:49 -04:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 04:34:51 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-05-20 11:37:55 -04:00
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
2005-09-08 10:36:09 -04:00
|
|
|
#include <nginx.h>
|
2003-05-20 11:37:55 -04:00
|
|
|
|
2003-06-11 11:28:34 -04:00
|
|
|
|
2004-10-03 16:02:06 -04:00
|
|
|
ngx_uint_t ngx_win32_version;
|
|
|
|
ngx_uint_t ngx_ncpu;
|
2004-11-11 11:07:14 -03:00
|
|
|
ngx_uint_t ngx_max_wsabufs;
|
2004-10-03 16:02:06 -04:00
|
|
|
ngx_int_t ngx_max_sockets;
|
|
|
|
ngx_uint_t ngx_inherited_nonblocking = 1;
|
2004-12-02 15:40:46 -03:00
|
|
|
ngx_uint_t ngx_tcp_nodelay_and_tcp_nopush;
|
|
|
|
|
2004-10-03 16:02:06 -04:00
|
|
|
ngx_fd_t ngx_stderr_fileno;
|
2003-05-20 11:37:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
ngx_os_io_t ngx_os_io = {
|
2003-05-21 09:28:21 -04:00
|
|
|
ngx_wsarecv,
|
2003-11-16 18:49:42 -03:00
|
|
|
ngx_wsarecv_chain,
|
2003-05-20 11:37:55 -04:00
|
|
|
NULL,
|
2003-06-11 11:28:34 -04:00
|
|
|
ngx_wsasend_chain,
|
|
|
|
0
|
2003-05-20 11:37:55 -04:00
|
|
|
};
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
|
2004-03-09 16:47:07 -03:00
|
|
|
typedef struct {
|
|
|
|
WORD wServicePackMinor;
|
|
|
|
WORD wSuiteMask;
|
|
|
|
BYTE wProductType;
|
|
|
|
} ngx_osviex_stub_t;
|
|
|
|
|
|
|
|
|
2004-11-11 11:07:14 -03:00
|
|
|
static u_int osviex;
|
|
|
|
static OSVERSIONINFOEX osvi;
|
|
|
|
|
2003-06-03 11:42:58 -04:00
|
|
|
/* Should these pointers be per protocol ? */
|
|
|
|
LPFN_ACCEPTEX acceptex;
|
|
|
|
LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
|
|
|
|
LPFN_TRANSMITFILE transmitfile;
|
|
|
|
|
|
|
|
static GUID ae_guid = WSAID_ACCEPTEX;
|
|
|
|
static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
|
|
|
|
static GUID tf_guid = WSAID_TRANSMITFILE;
|
|
|
|
|
|
|
|
|
2004-10-03 16:02:06 -04:00
|
|
|
ngx_int_t ngx_os_init(ngx_log_t *log)
|
2003-05-19 12:39:14 -04:00
|
|
|
{
|
2004-11-11 11:07:14 -03:00
|
|
|
DWORD bytes;
|
|
|
|
SOCKET s;
|
|
|
|
WSADATA wsd;
|
|
|
|
SYSTEM_INFO si;
|
2003-06-06 10:59:20 -04:00
|
|
|
|
|
|
|
/* get Windows version */
|
|
|
|
|
2003-06-11 11:28:34 -04:00
|
|
|
ngx_memzero(&osvi, sizeof(OSVERSIONINFOEX));
|
2003-06-06 10:59:20 -04:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
|
|
|
|
osviex = GetVersionEx((OSVERSIONINFO *) &osvi);
|
|
|
|
|
|
|
|
if (osviex == 0) {
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
2003-06-11 11:28:34 -04:00
|
|
|
if (GetVersionEx((OSVERSIONINFO *) &osvi) == 0) {
|
2003-06-06 10:59:20 -04:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
|
|
"GetVersionEx() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-12-14 17:10:27 -03:00
|
|
|
* Windows 3.1 Win32s 0xxxxx
|
|
|
|
*
|
2003-06-11 11:28:34 -04:00
|
|
|
* Windows 95 140000
|
|
|
|
* Windows 98 141000
|
|
|
|
* Windows ME 149000
|
|
|
|
* Windows NT 3.51 235100
|
|
|
|
* Windows NT 4.0 240000
|
|
|
|
* Windows NT 4.0 SP5 240050
|
|
|
|
* Windows 2000 250000
|
|
|
|
* Windows XP 250100
|
|
|
|
* Windows 2003 250200
|
2003-12-14 17:10:27 -03:00
|
|
|
*
|
|
|
|
* Windows CE x.x 3xxxxx
|
2003-06-06 10:59:20 -04:00
|
|
|
*/
|
|
|
|
|
2003-06-11 11:28:34 -04:00
|
|
|
ngx_win32_version = osvi.dwPlatformId * 100000
|
|
|
|
+ osvi.dwMajorVersion * 10000
|
|
|
|
+ osvi.dwMinorVersion * 100;
|
2003-06-06 10:59:20 -04:00
|
|
|
|
|
|
|
if (osviex) {
|
2003-06-11 11:28:34 -04:00
|
|
|
ngx_win32_version += osvi.wServicePackMajor * 10
|
|
|
|
+ osvi.wServicePackMinor;
|
2003-06-06 10:59:20 -04:00
|
|
|
}
|
|
|
|
|
2004-06-06 15:49:18 -04:00
|
|
|
GetSystemInfo(&si);
|
|
|
|
ngx_pagesize = si.dwPageSize;
|
2004-06-30 11:30:41 -04:00
|
|
|
ngx_ncpu = si.dwNumberOfProcessors;
|
2005-12-16 12:07:08 -03:00
|
|
|
ngx_cacheline_size = NGX_CPU_CACHE_LINE;
|
2004-06-06 15:49:18 -04:00
|
|
|
|
2003-06-03 11:42:58 -04:00
|
|
|
|
|
|
|
/* init Winsock */
|
|
|
|
|
|
|
|
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
2003-06-06 10:59:20 -04:00
|
|
|
"WSAStartup() failed");
|
2003-06-03 11:42:58 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-03-09 16:47:07 -03:00
|
|
|
if (ngx_win32_version < NGX_WIN_NT) {
|
2004-11-11 11:07:14 -03:00
|
|
|
ngx_max_wsabufs = 16;
|
2004-03-09 16:47:07 -03:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2004-11-11 11:07:14 -03:00
|
|
|
/* STUB: ngx_uint_t max */
|
|
|
|
ngx_max_wsabufs = 1024 * 1024;
|
|
|
|
|
2003-06-03 11:42:58 -04:00
|
|
|
/* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
|
|
|
|
|
2004-11-11 11:07:14 -03:00
|
|
|
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
2003-06-03 11:42:58 -04:00
|
|
|
if (s == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
2004-11-11 11:07:14 -03:00
|
|
|
ngx_socket_n " falied");
|
2003-05-19 12:39:14 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-06-03 11:42:58 -04:00
|
|
|
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
|
|
|
|
&acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
|
|
|
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
|
|
|
"WSAID_ACCEPTEX) failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
|
|
|
|
&getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
|
|
|
|
&bytes, NULL, NULL) == -1) {
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
|
|
|
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
|
|
|
"WSAID_ACCEPTEX) failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
|
|
|
|
&transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
|
|
|
|
NULL, NULL) == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
|
|
|
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
|
|
|
"WSAID_TRANSMITFILE) failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_close_socket(s) == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
|
|
|
|
ngx_close_socket_n " failed");
|
|
|
|
}
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
2004-10-03 16:02:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
void ngx_os_status(ngx_log_t *log)
|
|
|
|
{
|
2004-11-11 11:07:14 -03:00
|
|
|
ngx_osviex_stub_t *osviex_stub;
|
|
|
|
|
2005-09-08 10:36:09 -04:00
|
|
|
ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER);
|
|
|
|
|
2004-11-11 11:07:14 -03:00
|
|
|
if (osviex) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the MSVC 6.0 SP2 defines wSuiteMask and wProductType
|
|
|
|
* as WORD wReserved[2]
|
|
|
|
*/
|
|
|
|
osviex_stub = (ngx_osviex_stub_t *) &osvi.wServicePackMinor;
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0,
|
|
|
|
"OS: %ud build:%ud, \"%s\", suite:%Xd, type:%ud",
|
|
|
|
ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
|
|
|
|
osviex_stub->wSuiteMask, osviex_stub->wProductType);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
|
|
|
|
|
|
|
|
/* Win9x build */
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0,
|
|
|
|
"OS: %u build:%ud.%ud.%ud, \"%s\"",
|
|
|
|
ngx_win32_version,
|
|
|
|
osvi.dwBuildNumber >> 24,
|
|
|
|
(osvi.dwBuildNumber >> 16) & 0xff,
|
|
|
|
osvi.dwBuildNumber & 0xffff,
|
|
|
|
osvi.szCSDVersion);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VER_PLATFORM_WIN32_NT
|
|
|
|
*
|
|
|
|
* we do not currently support VER_PLATFORM_WIN32_CE
|
|
|
|
* and we do not support VER_PLATFORM_WIN32s at all
|
|
|
|
*/
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %ud build:%ud, \"%s\"",
|
|
|
|
ngx_win32_version, osvi.dwBuildNumber,
|
|
|
|
osvi.szCSDVersion);
|
|
|
|
}
|
|
|
|
}
|
2004-10-03 16:02:06 -04:00
|
|
|
}
|