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

ruby-changes:57681

From: Masaki <ko1@a...>
Date: Mon, 9 Sep 2019 20:35:17 +0900 (JST)
Subject: [ruby-changes:57681] c4efbf663e (master): Revert "Support timeout for Addrinfo"

https://git.ruby-lang.org/ruby.git/commit/?id=c4efbf663e

From c4efbf663ea1849986383ca97bfc8c2609142c68 Mon Sep 17 00:00:00 2001
From: Masaki Matsushita <glass.saga@g...>
Date: Mon, 9 Sep 2019 20:30:45 +0900
Subject: Revert "Support timeout for Addrinfo"

This reverts commit 6382f5cc91ac9e36776bc854632d9a1237250da7.
test failed on Solaris.

diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 42cfb06..0cc8a88 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -444,7 +444,6 @@ else https://github.com/ruby/ruby/blob/trunk/ext/socket/extconf.rb#L444
   test_func = "socket(0,0,0)"
   have_library("nsl", 't_open("", 0, (struct t_info *)NULL)', headers) # SunOS
   have_library("socket", "socket(0,0,0)", headers) # SunOS
-  have_library("anl", 'getaddrinfo_a', headers)
 end
 
 if have_func(test_func, headers)
@@ -506,7 +505,6 @@ EOF https://github.com/ruby/ruby/blob/trunk/ext/socket/extconf.rb#L505
   unless have_func("gethostname((char *)0, 0)", headers)
     have_func("uname((struct utsname *)NULL)", headers)
   end
-  have_func("getaddrinfo_a", headers)
 
   ipv6 = false
   default_ipv6 = /haiku/ !~ RUBY_PLATFORM
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index d756a32..4ed2df2 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -223,8 +223,8 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L223
   #   #   #<Addrinfo: [::1]:80 TCP (:80)>
   #   #   #<Addrinfo: [::1]:80 UDP (:80)>
   #
-  def self.foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=nil, timeout: nil, &block)
-    Addrinfo.getaddrinfo(nodename, service, family, socktype, protocol, flags, timeout: timeout).each(&block)
+  def self.foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=nil, &block)
+    Addrinfo.getaddrinfo(nodename, service, family, socktype, protocol, flags).each(&block)
   end
 end
 
@@ -606,7 +606,6 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L606
   # _opts_ may have following options:
   #
   # [:connect_timeout] specify the timeout in seconds.
-  # [:resolv_timeout] specify the name resolution timeout in seconds.
   #
   # If a block is given, the block is called with the socket.
   # The value of the block is returned.
@@ -620,7 +619,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L619
   #     puts sock.read
   #   }
   #
-  def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil) # :yield: socket
+  def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil) # :yield: socket
     last_error = nil
     ret = nil
 
@@ -629,7 +628,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L628
       local_addr_list = Addrinfo.getaddrinfo(local_host, local_port, nil, :STREAM, nil)
     end
 
-    Addrinfo.foreach(host, port, nil, :STREAM, timeout: resolv_timeout) {|ai|
+    Addrinfo.foreach(host, port, nil, :STREAM) {|ai|
       if local_addr_list
         local_addr = local_addr_list.find {|local_ai| local_ai.afamily == ai.afamily }
         next unless local_addr
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 0499b84..dad11ad 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -199,27 +199,6 @@ nogvl_getaddrinfo(void *arg) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L199
 }
 #endif
 
-#ifdef HAVE_GETADDRINFO_A
-struct gai_suspend_arg
-{
-    struct gaicb *req;
-    struct timespec *timeout;
-};
-
-static void *
-nogvl_gai_suspend(void *arg)
-{
-    int ret;
-    struct gai_suspend_arg *ptr = arg;
-    struct gaicb const *wait_reqs[1];
-
-    wait_reqs[0] = ptr->req;
-    ret = gai_suspend(wait_reqs, 1, ptr->timeout);
-
-    return (void *)(VALUE)ret;
-}
-#endif
-
 static int
 numeric_getaddrinfo(const char *node, const char *service,
         const struct addrinfo *hints,
@@ -339,59 +318,6 @@ rb_getaddrinfo(const char *node, const char *service, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L318
     return ret;
 }
 
-#ifdef HAVE_GETADDRINFO_A
-int
-rb_getaddrinfo_a(const char *node, const char *service,
-               const struct addrinfo *hints,
-               struct rb_addrinfo **res, struct timespec *timeout)
-{
-    struct addrinfo *ai;
-    int ret;
-    int allocated_by_malloc = 0;
-
-    ret = numeric_getaddrinfo(node, service, hints, &ai);
-    if (ret == 0)
-        allocated_by_malloc = 1;
-    else {
-	struct gai_suspend_arg arg;
-	struct gaicb *reqs[1];
-	struct gaicb req;
-
-	req.ar_name = node;
-	req.ar_service = service;
-	req.ar_request = hints;
-
-	reqs[0] = &req;
-	ret = getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL);
-	if (ret) return ret;
-
-	arg.req = &req;
-	arg.timeout = timeout;
-
-	ret = (int)(VALUE)rb_thread_call_without_gvl(nogvl_gai_suspend, &arg, RUBY_UBF_IO, 0);
-
-	if (ret) {
-	    /* on Ubuntu 18.04 (or other systems), gai_suspend(3) returns EAI_SYSTEM/ENOENT on timeout */
-	    if (ret == EAI_SYSTEM && errno == ENOENT) {
-		return EAI_AGAIN;
-	    } else {
-		return ret;
-	    }
-	}
-
-	ret = gai_error(reqs[0]);
-	ai = reqs[0]->ar_result;
-    }
-
-    if (ret == 0) {
-        *res = (struct rb_addrinfo *)xmalloc(sizeof(struct rb_addrinfo));
-        (*res)->allocated_by_malloc = allocated_by_malloc;
-        (*res)->ai = ai;
-    }
-    return ret;
-}
-#endif
-
 void
 rb_freeaddrinfo(struct rb_addrinfo *ai)
 {
@@ -604,42 +530,6 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L530
     return res;
 }
 
-#ifdef HAVE_GETADDRINFO_A
-static struct rb_addrinfo*
-rsock_getaddrinfo_a(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack, VALUE timeout)
-{
-    struct rb_addrinfo* res = NULL;
-    char *hostp, *portp;
-    int error;
-    char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
-    int additional_flags = 0;
-
-    hostp = host_str(host, hbuf, sizeof(hbuf), &additional_flags);
-    portp = port_str(port, pbuf, sizeof(pbuf), &additional_flags);
-
-    if (socktype_hack && hints->ai_socktype == 0 && str_is_number(portp)) {
-       hints->ai_socktype = SOCK_DGRAM;
-    }
-    hints->ai_flags |= additional_flags;
-
-    if (NIL_P(timeout)) {
-	error = rb_getaddrinfo(hostp, portp, hints, &res);
-    } else {
-	struct timespec _timeout = rb_time_timespec_interval(timeout);
-	error = rb_getaddrinfo_a(hostp, portp, hints, &res, &_timeout);
-    }
-
-    if (error) {
-        if (hostp && hostp[strlen(hostp)-1] == '\n') {
-            rb_raise(rb_eSocket, "newline at the end of hostname");
-        }
-        rsock_raise_socket_error("getaddrinfo_a", error);
-    }
-
-    return res;
-}
-#endif
-
 int
 rsock_fd_family(int fd)
 {
@@ -927,7 +817,7 @@ rsock_addrinfo_new(struct sockaddr *addr, socklen_t len, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L817
 static struct rb_addrinfo *
 call_getaddrinfo(VALUE node, VALUE service,
                  VALUE family, VALUE socktype, VALUE protocol, VALUE flags,
-                 int socktype_hack, VALUE timeout)
+                 int socktype_hack)
 {
     struct addrinfo hints;
     struct rb_addrinfo *res;
@@ -944,16 +834,7 @@ call_getaddrinfo(VALUE node, VALUE service, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L834
     if (!NIL_P(flags)) {
 	hints.ai_flags = NUM2INT(flags);
     }
-
-#ifdef HAVE_GETADDRINFO_A
-    if (NIL_P(timeout)) {
-	res = rsock_getaddrinfo(node, service, &hints, socktype_hack);
-    } else {
-	res = rsock_getaddrinfo_a(node, service, &hints, socktype_hack, timeout);
-    }
-#else
     res = rsock_getaddrinfo(node, service, &hints, socktype_hack);
-#endif
 
     if (res == NULL)
 	rb_raise(rb_eSocket, "host not found");
@@ -967,7 +848,7 @@ init_addrinfo_getaddrinfo(rb_addrinfo_t *rai, VALUE node, VALUE service, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L848
                           VALUE family, VALUE socktype, VALUE protocol, VALUE flags,
                           VALUE inspectnode, VALUE inspectservice)
 {
-    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 1, Qnil);
+    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 1);
     VALUE canonname;
     VALUE inspectname = rb_str_equal(node, inspectnode) ? Qnil : make_inspectname(inspectnode, inspectservice, res->ai);
 
@@ -1037,7 +918,7 @@ addrinfo_firstonly_new(VALUE node, VALUE service, VALUE family, VALUE socktype, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L918
     VALUE canonname;
     VALUE inspectname;
 
-    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0, Qnil);
+    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0);
 
     inspectname = make_inspectname(node, service, res->ai);
 
@@ -1057,13 +938,13 @@ addrinfo_firstonly_new(VALUE node, VALUE service, VALUE family, VALUE socktype, https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L938
 }
 
 static VALUE
-addrinfo_list_new(VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags, VALUE timeout)
+addrinfo_list_new(VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags)
 {
     VALUE ret;
     struct addrinfo *r;
     VALUE inspectname;
 
-    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0, timeout);
+    struct rb_addrinfo *res = call_getaddrinfo(node, service, family, socktype, protocol, flags, 0);
 
     inspectname = make_inspectname(node, service, res->ai);
 
@@ -1815,7 +1696,7 @@ addrinfo_mload(VALUE self, VALUE ary) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1696
 #endif
         res = call_getaddrinfo(rb_ary_entry(pair, 0), rb_ary_entry(pair, 1),
               (... truncated)

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

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