summaryrefslogtreecommitdiff
path: root/ext/socket/lib/socket.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/lib/socket.rb')
-rw-r--r--ext/socket/lib/socket.rb31
1 files changed, 6 insertions, 25 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 39fd51b92a..78958c377b 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -617,12 +617,6 @@ class Socket < BasicSocket
IPV6_ADRESS_FORMAT = /\A(?i:(?:(?:[0-9A-F]{1,4}:){7}(?:[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){6}(?:[0-9A-F]{1,4}|:(?:[0-9A-F]{1,4}:){1,5}[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){5}(?:(?::[0-9A-F]{1,4}){1,2}|:(?:[0-9A-F]{1,4}:){1,4}[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){4}(?:(?::[0-9A-F]{1,4}){1,3}|:(?:[0-9A-F]{1,4}:){1,3}[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){3}(?:(?::[0-9A-F]{1,4}){1,4}|:(?:[0-9A-F]{1,4}:){1,2}[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){2}(?:(?::[0-9A-F]{1,4}){1,5}|:(?:[0-9A-F]{1,4}:)[0-9A-F]{1,4}|:)|(?:[0-9A-F]{1,4}:){1}(?:(?::[0-9A-F]{1,4}){1,6}|:(?:[0-9A-F]{1,4}:){0,5}[0-9A-F]{1,4}|:)|(?:::(?:[0-9A-F]{1,4}:){0,7}[0-9A-F]{1,4}|::)))(?:%.+)?\z/
private_constant :IPV6_ADRESS_FORMAT
- @tcp_fast_fallback = true
-
- class << self
- attr_accessor :tcp_fast_fallback
- end
-
# :call-seq:
# Socket.tcp(host, port, local_host=nil, local_port=nil, [opts]) {|socket| ... }
# Socket.tcp(host, port, local_host=nil, local_port=nil, [opts])
@@ -633,8 +627,13 @@ class Socket < BasicSocket
# Happy Eyeballs Version 2 ({RFC 8305}[https://datatracker.ietf.org/doc/html/rfc8305])
# algorithm by default.
#
+ # For details on Happy Eyeballs Version 2,
+ # see {Socket.tcp_fast_fallback=}[rdoc-ref:Socket#tcp_fast_fallback=].
+ #
# To make it behave the same as in Ruby 3.3 and earlier,
- # explicitly specify the option +fast_fallback:false+.
+ # explicitly specify the option fast_fallback:false.
+ # Or, setting Socket.tcp_fast_fallback=false will disable
+ # Happy Eyeballs Version 2 not only for this method but for all Socket globally.
#
# If local_host:local_port is given,
# the socket is bound to it.
@@ -657,24 +656,6 @@ class Socket < BasicSocket
# sock.close_write
# puts sock.read
# }
- #
- # === Happy Eyeballs Version 2
- # Happy Eyeballs Version 2 ({RFC 8305}[https://datatracker.ietf.org/doc/html/rfc8305])
- # is an algorithm designed to improve client socket connectivity.<br>
- # It aims for more reliable and efficient connections by performing hostname resolution
- # and connection attempts in parallel, instead of serially.
- #
- # Starting from Ruby 3.4, this method operates as follows with this algorithm:
- #
- # 1. Start resolving both IPv6 and IPv4 addresses concurrently.
- # 2. Start connecting to the one of the addresses that are obtained first.<br>If IPv4 addresses are obtained first,
- # the method waits 50 ms for IPv6 name resolution to prioritize IPv6 connections.
- # 3. After starting a connection attempt, wait 250 ms for the connection to be established.<br>
- # If no connection is established within this time, a new connection is started every 250 ms<br>
- # until a connection is established or there are no more candidate addresses.<br>
- # (Although RFC 8305 strictly specifies sorting addresses,<br>
- # this method only alternates between IPv6 / IPv4 addresses due to the performance concerns)
- # 4. Once a connection is established, all remaining connection attempts are canceled.
def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, fast_fallback: tcp_fast_fallback, &) # :yield: socket
sock = if fast_fallback && !(host && ip_address?(host))
tcp_with_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:)