]> git.kaiwu.me - nginx.git/commitdiff
Win32: detection of connect() errors in select().
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 24 Jan 2019 19:00:44 +0000 (22:00 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 24 Jan 2019 19:00:44 +0000 (22:00 +0300)
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/).

src/event/modules/ngx_win32_select_module.c

index a98a83f281704013028a2d220d7618eccc715cf9..8093a600b0e4a0d053bb6dc404582203b8bd0cc9 100644 (file)
@@ -26,6 +26,7 @@ static fd_set         master_read_fd_set;
 static fd_set         master_write_fd_set;
 static fd_set         work_read_fd_set;
 static fd_set         work_write_fd_set;
+static fd_set         work_except_fd_set;
 
 static ngx_uint_t     max_read;
 static ngx_uint_t     max_write;
@@ -251,9 +252,11 @@ ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
 
     work_read_fd_set = master_read_fd_set;
     work_write_fd_set = master_write_fd_set;
+    work_except_fd_set = master_write_fd_set;
 
     if (max_read || max_write) {
-        ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
+        ready = select(0, &work_read_fd_set, &work_write_fd_set,
+                       &work_except_fd_set, tp);
 
     } else {
 
@@ -306,14 +309,20 @@ ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
 
         if (ev->write) {
             if (FD_ISSET(c->fd, &work_write_fd_set)) {
-                found = 1;
+                found++;
                 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                                "select write %d", c->fd);
             }
 
+            if (FD_ISSET(c->fd, &work_except_fd_set)) {
+                found++;
+                ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+                               "select except %d", c->fd);
+            }
+
         } else {
             if (FD_ISSET(c->fd, &work_read_fd_set)) {
-                found = 1;
+                found++;
                 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                                "select read %d", c->fd);
             }
@@ -327,7 +336,7 @@ ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
 
             ngx_post_event(ev, queue);
 
-            nready++;
+            nready += found;
         }
     }