comparison src/os/win32/ngx_win32_init.c @ 103:6dfda4cf5200

nginx-0.0.1-2003-06-11-19:28:34 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Jun 2003 15:28:34 +0000
parents src/os/win32/ngx_init.c@7e86d028d8f0
children b5be4b0448d3
comparison
equal deleted inserted replaced
102:7e86d028d8f0 103:6dfda4cf5200
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4
5 /* STUB */
6 ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size);
7 ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in);
8 /* */
9
10
11 int ngx_win32_version;
12 int ngx_max_sockets;
13 int ngx_inherited_nonblocking = 1;
14
15
16 ngx_os_io_t ngx_os_io = {
17 ngx_wsarecv,
18 NULL,
19 NULL,
20 ngx_wsasend_chain,
21 0
22 };
23
24
25 /* Should these pointers be per protocol ? */
26 LPFN_ACCEPTEX acceptex;
27 LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
28 LPFN_TRANSMITFILE transmitfile;
29
30 static GUID ae_guid = WSAID_ACCEPTEX;
31 static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
32 static GUID tf_guid = WSAID_TRANSMITFILE;
33
34
35 int ngx_os_init(ngx_log_t *log)
36 {
37 u_int osviex;
38 DWORD bytes;
39 SOCKET s;
40 WSADATA wsd;
41 OSVERSIONINFOEX osvi;
42
43 /* get Windows version */
44
45 ngx_memzero(&osvi, sizeof(OSVERSIONINFOEX));
46 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
47
48 osviex = GetVersionEx((OSVERSIONINFO *) &osvi);
49
50 if (osviex == 0) {
51 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
52 if (GetVersionEx((OSVERSIONINFO *) &osvi) == 0) {
53 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
54 "GetVersionEx() failed");
55 return NGX_ERROR;
56 }
57 }
58
59 /*
60 * Windows 95 140000
61 * Windows 98 141000
62 * Windows ME 149000
63 * Windows NT 3.51 235100
64 * Windows NT 4.0 240000
65 * Windows NT 4.0 SP5 240050
66 * Windows 2000 250000
67 * Windows XP 250100
68 * Windows 2003 250200
69 */
70
71 ngx_win32_version = osvi.dwPlatformId * 100000
72 + osvi.dwMajorVersion * 10000
73 + osvi.dwMinorVersion * 100;
74
75 if (osviex) {
76 ngx_win32_version += osvi.wServicePackMajor * 10
77 + osvi.wServicePackMinor;
78
79 ngx_log_error(NGX_LOG_INFO, log, 0,
80 "OS: %u build:%u, %s, suite:%x, type:%u",
81 ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
82 osvi.wReserved[0], osvi.wReserved[1]);
83
84 #if 0
85 ngx_log_error(NGX_LOG_INFO, log, 0,
86 "OS: %u build:%u, %s, suite:%x, type:%u",
87 ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
88 osvi.wSuiteMask, osvi.wProductType);
89 #endif
90
91 } else {
92 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u, %s",
93 ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion);
94 }
95
96
97 /* init Winsock */
98
99 if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
100 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
101 "WSAStartup() failed");
102 return NGX_ERROR;
103 }
104
105 /* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
106
107 s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
108 if (s == -1) {
109 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
110 ngx_socket_n " %s falied");
111 return NGX_ERROR;
112 }
113
114 if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
115 &acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
116
117 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
118 "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
119 "WSAID_ACCEPTEX) failed");
120 return NGX_ERROR;
121 }
122
123 if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
124 &getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
125 &bytes, NULL, NULL) == -1) {
126
127 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
128 "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
129 "WSAID_ACCEPTEX) failed");
130 return NGX_ERROR;
131 }
132
133 if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
134 &transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
135 NULL, NULL) == -1) {
136 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
137 "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
138 "WSAID_TRANSMITFILE) failed");
139 return NGX_ERROR;
140 }
141
142 if (ngx_close_socket(s) == -1) {
143 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
144 ngx_close_socket_n " failed");
145 }
146
147 return NGX_OK;
148 }