2003-05-20 00:39:14 +08:00
|
|
|
|
2003-05-20 23:37:55 +08:00
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
|
2003-06-11 23:28:34 +08:00
|
|
|
|
|
|
|
int ngx_win32_version;
|
2003-05-20 23:37:55 +08:00
|
|
|
int ngx_max_sockets;
|
2003-06-11 23:28:34 +08:00
|
|
|
int ngx_inherited_nonblocking = 1;
|
2003-05-20 23:37:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
ngx_os_io_t ngx_os_io = {
|
2003-05-21 21:28:21 +08:00
|
|
|
ngx_wsarecv,
|
2003-11-17 05:49:42 +08:00
|
|
|
ngx_wsarecv_chain,
|
2003-05-20 23:37:55 +08:00
|
|
|
NULL,
|
2003-06-11 23:28:34 +08:00
|
|
|
ngx_wsasend_chain,
|
|
|
|
0
|
2003-05-20 23:37:55 +08:00
|
|
|
};
|
|
|
|
|
2003-05-20 00:39:14 +08:00
|
|
|
|
2003-06-03 23:42:58 +08: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;
|
|
|
|
|
|
|
|
|
2003-05-20 00:39:14 +08:00
|
|
|
int ngx_os_init(ngx_log_t *log)
|
|
|
|
{
|
2003-06-11 23:28:34 +08:00
|
|
|
u_int osviex;
|
2003-06-06 22:59:20 +08:00
|
|
|
DWORD bytes;
|
|
|
|
SOCKET s;
|
|
|
|
WSADATA wsd;
|
|
|
|
OSVERSIONINFOEX osvi;
|
|
|
|
|
|
|
|
/* get Windows version */
|
|
|
|
|
2003-06-11 23:28:34 +08:00
|
|
|
ngx_memzero(&osvi, sizeof(OSVERSIONINFOEX));
|
2003-06-06 22:59:20 +08:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
|
|
|
|
osviex = GetVersionEx((OSVERSIONINFO *) &osvi);
|
|
|
|
|
|
|
|
if (osviex == 0) {
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
2003-06-11 23:28:34 +08:00
|
|
|
if (GetVersionEx((OSVERSIONINFO *) &osvi) == 0) {
|
2003-06-06 22:59:20 +08:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
|
|
"GetVersionEx() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-06-11 23:28:34 +08: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-06-06 22:59:20 +08:00
|
|
|
*/
|
|
|
|
|
2003-06-11 23:28:34 +08:00
|
|
|
ngx_win32_version = osvi.dwPlatformId * 100000
|
|
|
|
+ osvi.dwMajorVersion * 10000
|
|
|
|
+ osvi.dwMinorVersion * 100;
|
2003-06-06 22:59:20 +08:00
|
|
|
|
|
|
|
if (osviex) {
|
2003-06-11 23:28:34 +08:00
|
|
|
ngx_win32_version += osvi.wServicePackMajor * 10
|
|
|
|
+ osvi.wServicePackMinor;
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0,
|
2003-07-01 23:00:03 +08:00
|
|
|
"OS: %u build:%u, \"%s\", suite:%x, type:%u",
|
2003-06-11 23:28:34 +08:00
|
|
|
ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
|
|
|
|
osvi.wReserved[0], osvi.wReserved[1]);
|
2003-06-06 22:59:20 +08:00
|
|
|
|
2003-06-11 23:28:34 +08:00
|
|
|
#if 0
|
2003-06-06 22:59:20 +08:00
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0,
|
2003-07-01 23:00:03 +08:00
|
|
|
"OS: %u build:%u, \"%s\", suite:%x, type:%u",
|
2003-06-06 22:59:20 +08:00
|
|
|
ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
|
2003-06-11 23:28:34 +08:00
|
|
|
osvi.wSuiteMask, osvi.wProductType);
|
|
|
|
#endif
|
2003-06-06 22:59:20 +08:00
|
|
|
|
|
|
|
} else {
|
2003-07-01 23:00:03 +08:00
|
|
|
if (osvi.dwPlatformId == 1) {
|
|
|
|
|
|
|
|
/* Win9x build */
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u.%u.%u, \"%s\"",
|
|
|
|
ngx_win32_version,
|
|
|
|
osvi.dwBuildNumber >> 24,
|
|
|
|
(osvi.dwBuildNumber >> 16) & 0xff,
|
|
|
|
osvi.dwBuildNumber & 0xffff,
|
|
|
|
osvi.szCSDVersion);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u, \"%s\"",
|
|
|
|
ngx_win32_version, osvi.dwBuildNumber,
|
|
|
|
osvi.szCSDVersion);
|
|
|
|
}
|
2003-06-06 22:59:20 +08:00
|
|
|
}
|
|
|
|
|
2003-06-03 23:42:58 +08:00
|
|
|
|
|
|
|
/* init Winsock */
|
|
|
|
|
|
|
|
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
2003-06-06 22:59:20 +08:00
|
|
|
"WSAStartup() failed");
|
2003-06-03 23:42:58 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
|
|
|
|
|
|
|
|
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
|
|
|
|
if (s == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
|
|
|
ngx_socket_n " %s falied");
|
2003-05-20 00:39:14 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-06-03 23:42:58 +08: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-20 00:39:14 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|