comparison src/os/win32/ngx_win32_init.c @ 7444:4089b3d2cb59

Win32: added WSAPoll() support. WSAPoll() is only available with Windows Vista and newer (and only available during compilation if _WIN32_WINNT >= 0x0600). To make sure the code works with Windows XP, we do not redefine _WIN32_WINNT, but instead load WSAPoll() dynamically if it is not available during compilation. Also, sockets are not guaranteed to be small integers on Windows. So an index array is used instead of NGX_USE_FD_EVENT to map events to connections.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 24 Jan 2019 21:51:21 +0300
parents 56fc55e32f23
children 4f6e315eef15
comparison
equal deleted inserted replaced
7443:f3ff79ae31d9 7444:4089b3d2cb59
54 static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS; 54 static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
55 static GUID tf_guid = WSAID_TRANSMITFILE; 55 static GUID tf_guid = WSAID_TRANSMITFILE;
56 static GUID tp_guid = WSAID_TRANSMITPACKETS; 56 static GUID tp_guid = WSAID_TRANSMITPACKETS;
57 static GUID cx_guid = WSAID_CONNECTEX; 57 static GUID cx_guid = WSAID_CONNECTEX;
58 static GUID dx_guid = WSAID_DISCONNECTEX; 58 static GUID dx_guid = WSAID_DISCONNECTEX;
59
60
61 #if (NGX_LOAD_WSAPOLL)
62 ngx_wsapoll_pt WSAPoll;
63 ngx_uint_t ngx_have_wsapoll;
64 #endif
59 65
60 66
61 ngx_int_t 67 ngx_int_t
62 ngx_os_init(ngx_log_t *log) 68 ngx_os_init(ngx_log_t *log)
63 { 69 {
221 if (ngx_close_socket(s) == -1) { 227 if (ngx_close_socket(s) == -1) {
222 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, 228 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
223 ngx_close_socket_n " failed"); 229 ngx_close_socket_n " failed");
224 } 230 }
225 231
232 #if (NGX_LOAD_WSAPOLL)
233 {
234 HMODULE hmod;
235
236 hmod = GetModuleHandle("ws2_32.dll");
237 if (hmod == NULL) {
238 ngx_log_error(NGX_LOG_NOTICE, log, ngx_errno,
239 "GetModuleHandle(\"ws2_32.dll\") failed");
240 goto nopoll;
241 }
242
243 WSAPoll = (ngx_wsapoll_pt) GetProcAddress(hmod, "WSAPoll");
244 if (WSAPoll == NULL) {
245 ngx_log_error(NGX_LOG_NOTICE, log, ngx_errno,
246 "GetProcAddress(\"WSAPoll\") failed");
247 goto nopoll;
248 }
249
250 ngx_have_wsapoll = 1;
251
252 }
253
254 nopoll:
255
256 #endif
257
226 if (GetEnvironmentVariable("ngx_unique", ngx_unique, NGX_INT32_LEN + 1) 258 if (GetEnvironmentVariable("ngx_unique", ngx_unique, NGX_INT32_LEN + 1)
227 != 0) 259 != 0)
228 { 260 {
229 ngx_process = NGX_PROCESS_WORKER; 261 ngx_process = NGX_PROCESS_WORKER;
230 262