[前][次][番号順一覧][スレッド一覧]

ruby-changes:53403

From: normal <ko1@a...>
Date: Thu, 8 Nov 2018 12:27:22 +0900 (JST)
Subject: [ruby-changes:53403] normal:r65619 (trunk): ext/socket/init.c (wait_connectable): bail out early on some errors

normal	2018-11-08 12:27:16 +0900 (Thu, 08 Nov 2018)

  New Revision: 65619

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65619

  Log:
    ext/socket/init.c (wait_connectable): bail out early on some errors
    
    This becomes necesary if sockets become non-blocking by
    default <https://bugs.ruby-lang.org/issues/14968>; but it's
    always been possible to make sockets non-blocking anyways.

  Modified files:
    trunk/ext/socket/init.c
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 65618)
+++ ext/socket/init.c	(revision 65619)
@@ -508,11 +508,30 @@ wait_connectable(int fd) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L508
     int sockerr, revents;
     socklen_t sockerrlen;
 
-    /* only to clear pending error */
     sockerrlen = (socklen_t)sizeof(sockerr);
     if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen) < 0)
         return -1;
 
+    /* necessary for non-blocking sockets (at least ECONNREFUSED) */
+    switch (sockerr) {
+      case 0:
+        break;
+#ifdef EALREADY
+      case EALREADY:
+#endif
+#ifdef EISCONN
+      case EISCONN:
+#endif
+#ifdef ECONNREFUSED
+      case ECONNREFUSED:
+#endif
+#ifdef EHOSTUNREACH
+      case EHOSTUNREACH:
+#endif
+        errno = sockerr;
+        return -1;
+    }
+
     /*
      * Stevens book says, successful finish turn on RB_WAITFD_OUT and
      * failure finish turn on both RB_WAITFD_IN and RB_WAITFD_OUT.

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]