comparison src/event/modules/ngx_win32_select_module.c @ 7446:9234e8d61aa0

Win32: detection of connect() errors in select(). On Windows, connect() errors are only reported via exceptfds descriptor set from select(). Previously exceptfds was set to NULL, and connect() errors were not detected at all, so connects to closed ports were waiting till a timeout occurred. Since ongoing connect() means that there will be a write event active, except descriptor set is copied from the write one. While it is possible to construct except descriptor set as a concatenation of both read and write descriptor sets, this looks unneeded. With this change, connect() errors are properly detected now when using select(). Note well that it is not possible to detect connect() errors with WSAPoll() (see https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/).
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 24 Jan 2019 22:00:44 +0300
parents a72886067bbb
children efd71d49bde0
comparison
equal deleted inserted replaced
7445:c9235164bbf1 7446:9234e8d61aa0
24 24
25 static fd_set master_read_fd_set; 25 static fd_set master_read_fd_set;
26 static fd_set master_write_fd_set; 26 static fd_set master_write_fd_set;
27 static fd_set work_read_fd_set; 27 static fd_set work_read_fd_set;
28 static fd_set work_write_fd_set; 28 static fd_set work_write_fd_set;
29 static fd_set work_except_fd_set;
29 30
30 static ngx_uint_t max_read; 31 static ngx_uint_t max_read;
31 static ngx_uint_t max_write; 32 static ngx_uint_t max_write;
32 static ngx_uint_t nevents; 33 static ngx_uint_t nevents;
33 34
249 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 250 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
250 "select timer: %M", timer); 251 "select timer: %M", timer);
251 252
252 work_read_fd_set = master_read_fd_set; 253 work_read_fd_set = master_read_fd_set;
253 work_write_fd_set = master_write_fd_set; 254 work_write_fd_set = master_write_fd_set;
255 work_except_fd_set = master_write_fd_set;
254 256
255 if (max_read || max_write) { 257 if (max_read || max_write) {
256 ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp); 258 ready = select(0, &work_read_fd_set, &work_write_fd_set,
259 &work_except_fd_set, tp);
257 260
258 } else { 261 } else {
259 262
260 /* 263 /*
261 * Winsock select() requires that at least one descriptor set must be 264 * Winsock select() requires that at least one descriptor set must be
304 c = ev->data; 307 c = ev->data;
305 found = 0; 308 found = 0;
306 309
307 if (ev->write) { 310 if (ev->write) {
308 if (FD_ISSET(c->fd, &work_write_fd_set)) { 311 if (FD_ISSET(c->fd, &work_write_fd_set)) {
309 found = 1; 312 found++;
310 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 313 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
311 "select write %d", c->fd); 314 "select write %d", c->fd);
312 } 315 }
313 316
317 if (FD_ISSET(c->fd, &work_except_fd_set)) {
318 found++;
319 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
320 "select except %d", c->fd);
321 }
322
314 } else { 323 } else {
315 if (FD_ISSET(c->fd, &work_read_fd_set)) { 324 if (FD_ISSET(c->fd, &work_read_fd_set)) {
316 found = 1; 325 found++;
317 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 326 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
318 "select read %d", c->fd); 327 "select read %d", c->fd);
319 } 328 }
320 } 329 }
321 330
325 queue = ev->accept ? &ngx_posted_accept_events 334 queue = ev->accept ? &ngx_posted_accept_events
326 : &ngx_posted_events; 335 : &ngx_posted_events;
327 336
328 ngx_post_event(ev, queue); 337 ngx_post_event(ev, queue);
329 338
330 nready++; 339 nready += found;
331 } 340 }
332 } 341 }
333 342
334 if (ready != nready) { 343 if (ready != nready) {
335 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 344 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,