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

ruby-changes:66439

From: nagachika <ko1@a...>
Date: Thu, 10 Jun 2021 16:33:29 +0900 (JST)
Subject: [ruby-changes:66439] ced669aed0 (ruby_3_0): merge revision(s) a86c6cb34df0c44973efe6578ba1cd9150af22cf:

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

From ced669aed0de19090d1ba85eb9881becb693a735 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Thu, 10 Jun 2021 16:01:53 +0900
Subject: merge revision(s) a86c6cb34df0c44973efe6578ba1cd9150af22cf:

	[ruby/net-ftp] Replace Timeout.timeout with socket timeout

	Timeout.timeout is inefficient since it spins up a new thread for
	each invocation, use Socket.tcp's connect_timeout option instead
	when we aren't using SOCKS (we can't replace Timeout.timeout
	for SOCKS yet since SOCKSSocket doesn't have a connect_timeout
	option).

	https://github.com/ruby/net-ftp/commit/d65910132f
	---
	 lib/net/ftp.rb | 17 +++++++++++------
	 1 file changed, 11 insertions(+), 6 deletions(-)
---
 lib/net/ftp.rb | 17 +++++++++++------
 version.h      |  2 +-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 5e3e181..9e57cb3 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -330,14 +330,19 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L330
     # SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
     # returned.
     def open_socket(host, port) # :nodoc:
-      return Timeout.timeout(@open_timeout, OpenTimeout) {
-        if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
-          @passive = true
+      if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
+        @passive = true
+        Timeout.timeout(@open_timeout, OpenTimeout) do
           SOCKSSocket.open(host, port)
-        else
-          Socket.tcp(host, port)
         end
-      }
+      else
+        begin
+          Socket.tcp host, port, nil, nil, connect_timeout: @open_timeout
+        rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
+          raise Net::OpenTimeout, "Timeout to open TCP connection to "\
+          "#{host}:#{port} (exceeds #{@open_timeout} seconds)"
+        end
+      end
     end
     private :open_socket
 
diff --git a/version.h b/version.h
index ce64675..99224ae 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 2
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 96
+#define RUBY_PATCHLEVEL 97
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 6
-- 
cgit v1.1


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

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