Klaus Demo nginx / 38196b8
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/). Maxim Dounin 3 years ago
1 changed file(s) with 13 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2525 static fd_set master_write_fd_set;
2626 static fd_set work_read_fd_set;
2727 static fd_set work_write_fd_set;
28 static fd_set work_except_fd_set;
2829
2930 static ngx_uint_t max_read;
3031 static ngx_uint_t max_write;
250251
251252 work_read_fd_set = master_read_fd_set;
252253 work_write_fd_set = master_write_fd_set;
254 work_except_fd_set = master_write_fd_set;
253255
254256 if (max_read || max_write) {
255 ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
257 ready = select(0, &work_read_fd_set, &work_write_fd_set,
258 &work_except_fd_set, tp);
256259
257260 } else {
258261
305308
306309 if (ev->write) {
307310 if (FD_ISSET(c->fd, &work_write_fd_set)) {
308 found = 1;
311 found++;
309312 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
310313 "select write %d", c->fd);
311314 }
312315
316 if (FD_ISSET(c->fd, &work_except_fd_set)) {
317 found++;
318 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
319 "select except %d", c->fd);
320 }
321
313322 } else {
314323 if (FD_ISSET(c->fd, &work_read_fd_set)) {
315 found = 1;
324 found++;
316325 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
317326 "select read %d", c->fd);
318327 }
326335
327336 ngx_post_event(ev, queue);
328337
329 nready++;
338 nready += found;
330339 }
331340 }
332341