rbs 3.7.0 → 3.8.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +7 -7
  4. data/CHANGELOG.md +52 -0
  5. data/core/array.rbs +1743 -1580
  6. data/core/basic_object.rbs +38 -35
  7. data/core/comparable.rbs +1 -1
  8. data/core/complex.rbs +165 -93
  9. data/core/data.rbs +1 -1
  10. data/core/dir.rbs +1 -17
  11. data/core/encoding.rbs +12 -6
  12. data/core/enumerable.rbs +270 -266
  13. data/core/enumerator.rbs +0 -2
  14. data/core/env.rbs +1 -1
  15. data/core/errno.rbs +33 -16
  16. data/core/errors.rbs +2 -2
  17. data/core/exception.rbs +236 -170
  18. data/core/fiber.rbs +3 -2
  19. data/core/file.rbs +32 -74
  20. data/core/float.rbs +125 -72
  21. data/core/gc.rbs +138 -40
  22. data/core/hash.rbs +120 -141
  23. data/core/integer.rbs +79 -50
  24. data/core/io/buffer.rbs +49 -43
  25. data/core/io.rbs +97 -144
  26. data/core/kernel.rbs +290 -200
  27. data/core/match_data.rbs +76 -2
  28. data/core/math.rbs +0 -36
  29. data/core/module.rbs +28 -23
  30. data/core/nil_class.rbs +0 -3
  31. data/core/numeric.rbs +100 -103
  32. data/core/object.rbs +0 -4
  33. data/core/object_space/weak_key_map.rbs +3 -4
  34. data/core/object_space.rbs +3 -3
  35. data/core/proc.rbs +0 -2
  36. data/core/process.rbs +109 -57
  37. data/core/ractor.rbs +37 -4
  38. data/core/range.rbs +114 -87
  39. data/core/rational.rbs +0 -2
  40. data/core/rbs/unnamed/argf.rbs +234 -33
  41. data/core/rbs/unnamed/env_class.rbs +35 -53
  42. data/core/rbs/unnamed/random.rbs +1 -2
  43. data/core/regexp.rbs +4 -52
  44. data/core/ruby_vm.rbs +88 -9
  45. data/core/rubygems/config_file.rbs +3 -0
  46. data/core/rubygems/errors.rbs +0 -5
  47. data/core/rubygems/platform.rbs +0 -9
  48. data/core/rubygems/rubygems.rbs +0 -5
  49. data/core/rubygems/version.rbs +6 -6
  50. data/core/set.rbs +3 -15
  51. data/core/string.rbs +130 -136
  52. data/core/struct.rbs +6 -18
  53. data/core/symbol.rbs +14 -21
  54. data/core/thread.rbs +32 -35
  55. data/core/time.rbs +127 -50
  56. data/core/trace_point.rbs +16 -0
  57. data/core/true_class.rbs +0 -1
  58. data/core/warning.rbs +9 -2
  59. data/docs/architecture.md +1 -1
  60. data/docs/syntax.md +1 -1
  61. data/ext/rbs_extension/location.c +29 -19
  62. data/ext/rbs_extension/parser.c +267 -292
  63. data/ext/rbs_extension/parserstate.c +56 -22
  64. data/lib/rbs/annotate/annotations.rb +3 -3
  65. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  66. data/lib/rbs/cli/diff.rb +3 -3
  67. data/lib/rbs/cli/validate.rb +1 -1
  68. data/lib/rbs/cli.rb +13 -13
  69. data/lib/rbs/collection/config.rb +3 -1
  70. data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
  71. data/lib/rbs/environment_loader.rb +1 -1
  72. data/lib/rbs/namespace.rb +1 -0
  73. data/lib/rbs/parser_aux.rb +2 -2
  74. data/lib/rbs/prototype/rb.rb +11 -8
  75. data/lib/rbs/prototype/rbi.rb +9 -5
  76. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  77. data/lib/rbs/prototype/runtime.rb +4 -5
  78. data/lib/rbs/type_name.rb +14 -9
  79. data/lib/rbs/unit_test/type_assertions.rb +2 -2
  80. data/lib/rbs/validator.rb +3 -1
  81. data/lib/rbs/version.rb +1 -1
  82. data/lib/rdoc_plugin/parser.rb +2 -2
  83. data/rbs.gemspec +4 -0
  84. data/sig/ancestor_graph.rbs +4 -4
  85. data/sig/namespace.rbs +2 -3
  86. data/sig/resolver/constant_resolver.rbs +2 -2
  87. data/sig/resolver/context.rbs +1 -1
  88. data/sig/type_alias_regularity.rbs +5 -5
  89. data/sig/typename.rbs +8 -5
  90. data/sig/use_map.rbs +1 -1
  91. data/sig/validator.rbs +2 -2
  92. data/stdlib/base64/0/base64.rbs +0 -9
  93. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  94. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  95. data/stdlib/cgi/0/core.rbs +47 -0
  96. data/stdlib/coverage/0/coverage.rbs +0 -3
  97. data/stdlib/csv/0/csv.rbs +18 -58
  98. data/stdlib/date/0/date.rbs +4 -19
  99. data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
  100. data/stdlib/digest/0/digest.rbs +25 -2
  101. data/stdlib/erb/0/erb.rbs +0 -1
  102. data/stdlib/etc/0/etc.rbs +51 -34
  103. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  104. data/stdlib/io-console/0/io-console.rbs +69 -15
  105. data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
  106. data/stdlib/json/0/json.rbs +56 -71
  107. data/stdlib/logger/0/log_device.rbs +1 -1
  108. data/stdlib/logger/0/logger.rbs +3 -18
  109. data/stdlib/net-http/0/net-http.rbs +19 -77
  110. data/stdlib/nkf/0/nkf.rbs +30 -0
  111. data/stdlib/objspace/0/objspace.rbs +1 -2
  112. data/stdlib/observable/0/observable.rbs +1 -1
  113. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  114. data/stdlib/open3/0/open3.rbs +0 -8
  115. data/stdlib/openssl/0/openssl.rbs +136 -69
  116. data/stdlib/optparse/0/optparse.rbs +58 -18
  117. data/stdlib/pathname/0/pathname.rbs +2 -8
  118. data/stdlib/pp/0/pp.rbs +3 -1
  119. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  120. data/stdlib/pstore/0/pstore.rbs +0 -6
  121. data/stdlib/psych/0/psych.rbs +15 -4
  122. data/stdlib/pty/0/pty.rbs +46 -4
  123. data/stdlib/rdoc/0/code_object.rbs +0 -4
  124. data/stdlib/rdoc/0/markup.rbs +10 -12
  125. data/stdlib/rdoc/0/rdoc.rbs +1 -2
  126. data/stdlib/resolv/0/resolv.rbs +8 -3
  127. data/stdlib/ripper/0/ripper.rbs +0 -2
  128. data/stdlib/securerandom/0/securerandom.rbs +0 -2
  129. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  130. data/stdlib/singleton/0/singleton.rbs +0 -1
  131. data/stdlib/socket/0/addrinfo.rbs +0 -1
  132. data/stdlib/socket/0/basic_socket.rbs +0 -5
  133. data/stdlib/socket/0/socket.rbs +49 -25
  134. data/stdlib/socket/0/tcp_server.rbs +0 -3
  135. data/stdlib/socket/0/tcp_socket.rbs +58 -3
  136. data/stdlib/socket/0/udp_socket.rbs +0 -1
  137. data/stdlib/socket/0/unix_server.rbs +0 -3
  138. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  139. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  140. data/stdlib/time/0/time.rbs +48 -35
  141. data/stdlib/timeout/0/timeout.rbs +11 -8
  142. data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
  143. data/stdlib/tsort/0/tsort.rbs +0 -4
  144. data/stdlib/uri/0/common.rbs +11 -30
  145. data/stdlib/uri/0/ftp.rbs +1 -1
  146. data/stdlib/uri/0/generic.rbs +22 -18
  147. data/stdlib/uri/0/http.rbs +2 -2
  148. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  149. data/stdlib/zlib/0/buf_error.rbs +1 -70
  150. data/stdlib/zlib/0/data_error.rbs +1 -70
  151. data/stdlib/zlib/0/deflate.rbs +8 -72
  152. data/stdlib/zlib/0/error.rbs +1 -70
  153. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  154. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  155. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  156. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  157. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  158. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  159. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  160. data/stdlib/zlib/0/inflate.rbs +4 -71
  161. data/stdlib/zlib/0/mem_error.rbs +1 -70
  162. data/stdlib/zlib/0/need_dict.rbs +1 -70
  163. data/stdlib/zlib/0/stream_end.rbs +1 -70
  164. data/stdlib/zlib/0/stream_error.rbs +1 -70
  165. data/stdlib/zlib/0/version_error.rbs +1 -70
  166. data/stdlib/zlib/0/zlib.rbs +0 -2
  167. data/stdlib/zlib/0/zstream.rbs +4 -72
  168. metadata +4 -6
@@ -292,7 +292,6 @@ class Resolv::DNS
292
292
  # * Resolv::DNS::Resource::IN::TXT
293
293
  # * Resolv::DNS::Resource::IN::WKS
294
294
  #
295
- #
296
295
  # Returned resource is represented as a Resolv::DNS::Resource instance, i.e.
297
296
  # Resolv::DNS::Resource::IN::A.
298
297
  #
@@ -341,8 +340,10 @@ class Resolv::DNS
341
340
  #
342
341
  # nil
343
342
  # : Uses /etc/resolv.conf.
343
+ #
344
344
  # String
345
345
  # : Path to a file using /etc/resolv.conf's format.
346
+ #
346
347
  # Hash
347
348
  # : Must contain :nameserver, :search and :ndots keys.
348
349
  #
@@ -355,12 +356,10 @@ class Resolv::DNS
355
356
  # * :nameserver => '8.8.8.8'
356
357
  # * :nameserver => ['8.8.8.8', '8.8.4.4']
357
358
  #
358
- #
359
359
  # The value of :nameserver_port should be an array of pair of nameserver address
360
360
  # and port number.
361
361
  # * :nameserver_port => [['8.8.8.8', 53], ['8.8.4.4', 53]]
362
362
  #
363
- #
364
363
  # Example:
365
364
  #
366
365
  # Resolv::DNS.new(:nameserver => ['210.251.121.21'],
@@ -594,6 +593,7 @@ class Resolv::DNS::Name
594
593
  #
595
594
  # Name
596
595
  # : returns `arg`.
596
+ #
597
597
  # String
598
598
  # : Creates a new Name.
599
599
  #
@@ -1534,6 +1534,7 @@ class Resolv::IPv6
1534
1534
  #
1535
1535
  # IPv6
1536
1536
  # : returns `arg`.
1537
+ #
1537
1538
  # String
1538
1539
  # : `arg` must match one of the IPv6::Regex* constants
1539
1540
  #
@@ -1617,6 +1618,7 @@ class Resolv::LOC::Alt
1617
1618
  #
1618
1619
  # LOC::Alt
1619
1620
  # : returns `arg`.
1621
+ #
1620
1622
  # String
1621
1623
  # : `arg` must match the LOC::Alt::Regex constant
1622
1624
  #
@@ -1663,6 +1665,7 @@ class Resolv::LOC::Coord
1663
1665
  #
1664
1666
  # LOC::Coord
1665
1667
  # : returns `arg`.
1668
+ #
1666
1669
  # String
1667
1670
  # : `arg` must match the LOC::Coord::Regex constant
1668
1671
  #
@@ -1712,6 +1715,7 @@ class Resolv::LOC::Size
1712
1715
  #
1713
1716
  # LOC::Size
1714
1717
  # : returns `arg`.
1718
+ #
1715
1719
  # String
1716
1720
  # : `arg` must match the LOC::Size::Regex constant
1717
1721
  #
@@ -1782,6 +1786,7 @@ class Resolv::MDNS < Resolv::DNS
1782
1786
  # nil
1783
1787
  # : Uses the default mDNS addresses
1784
1788
  #
1789
+ #
1785
1790
  # Hash
1786
1791
  # : Must contain :nameserver or :nameserver_port like Resolv::DNS#initialize.
1787
1792
  #
@@ -55,13 +55,11 @@
55
55
  # Inside](http://www.rubyinside.com/using-ripper-to-see-how-ruby-is-parsing-
56
56
  # your-code-5270.html)
57
57
  #
58
- #
59
58
  # ## Requirements
60
59
  #
61
60
  # * ruby 1.9 (support CVS HEAD only)
62
61
  # * bison 1.28 or later (Other yaccs do not work)
63
62
  #
64
- #
65
63
  # ## License
66
64
  #
67
65
  # Ruby License.
@@ -14,7 +14,6 @@
14
14
  # * /dev/urandom
15
15
  # * Win32
16
16
  #
17
- #
18
17
  # SecureRandom is extended by the Random::Formatter module which defines the
19
18
  # following methods:
20
19
  #
@@ -29,7 +28,6 @@
29
28
  # * urlsafe_base64
30
29
  # * uuid
31
30
  #
32
- #
33
31
  # These methods are usable as class methods of SecureRandom such as
34
32
  # `SecureRandom.hex`.
35
33
  #
@@ -4,9 +4,11 @@
4
4
  # This module manipulates strings according to the word parsing rules of the
5
5
  # UNIX Bourne shell.
6
6
  #
7
- # The shellwords() function was originally a port of shellwords.pl, but modified
8
- # to conform to the Shell & Utilities volume of the IEEE Std 1003.1-2008, 2016
9
- # Edition [1].
7
+ # The `shellwords()` function was originally a port of shellwords.pl, but
8
+ # modified to conform to [the Shell & Utilities volume of the IEEE Std
9
+ # 1003.1-2008, 2016
10
+ # Edition](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.ht
11
+ # ml)
10
12
  #
11
13
  # ### Usage
12
14
  #
@@ -58,17 +60,9 @@
58
60
  # * Wakou Aoyama
59
61
  # * Akinori MUSHA <knu@iDaemons.org>
60
62
  #
61
- #
62
63
  # ### Contact
63
64
  # * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
64
65
  #
65
- #
66
- # ### Resources
67
- #
68
- # 1: [IEEE Std 1003.1-2008, 2016 Edition, the Shell & Utilities
69
- # volume](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.htm
70
- # l)
71
- #
72
66
  module Shellwords
73
67
  # <!--
74
68
  # rdoc-file=lib/shellwords.rb
@@ -77,6 +71,8 @@ module Shellwords
77
71
  # Escapes a string so that it can be safely used in a Bourne shell command line.
78
72
  # `str` can be a non-string object that responds to `to_s`.
79
73
  #
74
+ # `str` must not contain NUL characters because of nature of `exec` system call.
75
+ #
80
76
  # Note that a resulted string should be used unquoted and is not intended for
81
77
  # use in double quotes nor in single quotes.
82
78
  #
@@ -114,7 +110,7 @@ module Shellwords
114
110
  #
115
111
  # All elements are joined into a single string with fields separated by a space,
116
112
  # where each element is escaped for the Bourne shell and stringified using
117
- # `to_s`.
113
+ # `to_s`. See also Shellwords.shellescape.
118
114
  #
119
115
  # ary = ["There's", "a", "time", "and", "place", "for", "everything"]
120
116
  # argv = Shellwords.join(ary)
@@ -142,6 +138,9 @@ module Shellwords
142
138
  # argv = Shellwords.split('here are "two words"')
143
139
  # argv #=> ["here", "are", "two words"]
144
140
  #
141
+ # `line` must not contain NUL characters because of nature of `exec` system
142
+ # call.
143
+ #
145
144
  # Note, however, that this is not a command line parser. Shell metacharacters
146
145
  # except for the single and double quotes and backslash are not treated as such.
147
146
  #
@@ -53,7 +53,6 @@
53
53
  # * Overriding Klass#clone and Klass#dup to raise TypeErrors to prevent
54
54
  # cloning or duping.
55
55
  #
56
- #
57
56
  # ## Singleton and Marshal
58
57
  #
59
58
  # By default Singleton's #_dump(depth) returns the empty string. Marshalling by
@@ -642,7 +642,6 @@ class Addrinfo
642
642
  # * `Socket.sockaddr_in(80, "www.ruby-lang.org")`
643
643
  # * `Socket.sockaddr_un("/tmp/sock")`
644
644
  #
645
- #
646
645
  # In an AF_INET/AF_INET6 sockaddr array, the 4th element, numeric IP address, is
647
646
  # used to construct socket address in the Addrinfo instance. If the 3rd element,
648
647
  # textual host name, is non-nil, it is also recorded but used only for
@@ -82,7 +82,6 @@ class BasicSocket < IO
82
82
  # (127.0.0.1).
83
83
  # * IPv6 unspecified address (::) is replaced by IPv6 loopback address (::1).
84
84
  #
85
- #
86
85
  # If the local address is not suitable for connect, SocketError is raised. IPv4
87
86
  # and IPv6 address which port is 0 is not suitable for connect. Unix domain
88
87
  # socket which has no path is not suitable for connect.
@@ -202,7 +201,6 @@ class BasicSocket < IO
202
201
  # Socket::SO_REUSEADDR. A string or symbol of the name, possibly without
203
202
  # prefix, is also accepted.
204
203
  #
205
- #
206
204
  # ### Examples
207
205
  #
208
206
  # Some socket options are integers with boolean values, in this case #getsockopt
@@ -302,7 +300,6 @@ class BasicSocket < IO
302
300
  # * `buf` - destination String buffer
303
301
  # * `options` - keyword hash, supporting `exception: false`
304
302
  #
305
- #
306
303
  # ### Example
307
304
  # serv = TCPServer.new("127.0.0.1", 0)
308
305
  # af, port, host, addr = serv.addr
@@ -518,10 +515,8 @@ class BasicSocket < IO
518
515
  # int is passed as for an Integer. Note that `false` must be passed, not
519
516
  # `nil`.
520
517
  # * String: the string's data and length is passed to the socket.
521
- #
522
518
  # * `socketoption` is an instance of Socket::Option
523
519
  #
524
- #
525
520
  # ### Examples
526
521
  #
527
522
  # Some socket options are integers with boolean values, in this case #setsockopt
@@ -22,12 +22,10 @@
22
22
  # * Socket::PF_UNIX
23
23
  # * etc.
24
24
  #
25
- #
26
25
  # **type:** The type of communications between the two endpoints, typically
27
26
  # * Socket::SOCK_STREAM
28
27
  # * Socket::SOCK_DGRAM.
29
28
  #
30
- #
31
29
  # **protocol:** Typically *zero*. This may be used to identify a variant of a
32
30
  # protocol.
33
31
  #
@@ -37,7 +35,6 @@
37
35
  # * a zero-length string which specifies INADDR_ANY
38
36
  # * an integer (interpreted as binary address in host byte order).
39
37
  #
40
- #
41
38
  # ### Quick start
42
39
  #
43
40
  # Many of the classes, such as TCPSocket, UDPSocket or UNIXSocket, ease the use
@@ -94,10 +91,13 @@
94
91
  #
95
92
  # TCP client socket
96
93
  # : Socket.tcp, TCPSocket.open
94
+ #
97
95
  # TCP server socket
98
96
  # : Socket.tcp_server_loop, TCPServer.open
97
+ #
99
98
  # UNIX client socket
100
99
  # : Socket.unix, UNIXSocket.open
100
+ #
101
101
  # UNIX server socket
102
102
  # : Socket.unix_server_loop, UNIXServer.open
103
103
  #
@@ -108,7 +108,6 @@
108
108
  # * Sam Roberts
109
109
  # * *Programming Ruby* from The Pragmatic Bookshelf.
110
110
  #
111
- #
112
111
  # Much material in this documentation is taken with permission from *Programming
113
112
  # Ruby* from The Pragmatic Bookshelf.
114
113
  #
@@ -180,7 +179,6 @@ class Socket < BasicSocket
180
179
  # cannot be released since gethostbyname() is not thread safe.)
181
180
  # * This method uses gethostbyname() function already removed from POSIX.
182
181
  #
183
- #
184
182
  # This method obtains the host information for *address*.
185
183
  #
186
184
  # p Socket.gethostbyaddr([221,186,184,68].pack("CCCC"))
@@ -209,7 +207,6 @@ class Socket < BasicSocket
209
207
  # cannot be released since gethostbyname() is not thread safe.)
210
208
  # * This method uses gethostbyname() function already removed from POSIX.
211
209
  #
212
- #
213
210
  # This method obtains the host information for *hostname*.
214
211
  #
215
212
  # p Socket.gethostbyname("hal") #=> ["localhost", ["hal"], 2, "\x7F\x00\x00\x01"]
@@ -281,7 +278,6 @@ class Socket < BasicSocket
281
278
  # * 3-elements array such as ["AF_INET", 80, "127.0.0.1"]
282
279
  # * 4-elements array such as ["AF_INET", 80, ignored, "127.0.0.1"]
283
280
  #
284
- #
285
281
  # *flags* should be bitwise OR of Socket::NI_* constants.
286
282
  #
287
283
  # Note: The last form is compatible with IPSocket#addr and IPSocket#peeraddr.
@@ -462,13 +458,33 @@ class Socket < BasicSocket
462
458
  # -->
463
459
  # creates a new socket object connected to host:port using TCP/IP.
464
460
  #
461
+ # Starting from Ruby 3.4, this method operates according to the Happy Eyeballs
462
+ # Version 2 ([RFC 8305](https://datatracker.ietf.org/doc/html/rfc8305))
463
+ # algorithm by default.
464
+ #
465
+ # To make it behave the same as in Ruby 3.3 and earlier, explicitly specify the
466
+ # option `fast_fallback:false`.
467
+ #
465
468
  # If local_host:local_port is given, the socket is bound to it.
466
469
  #
467
470
  # The optional last argument *opts* is options represented by a hash. *opts* may
468
471
  # have following options:
469
472
  #
473
+ # :resolv_timeout
474
+ # : Specifies the timeout in seconds from when the hostname resolution starts.
475
+ #
470
476
  # :connect_timeout
471
- # : specify the timeout in seconds.
477
+ # : This method sequentially attempts connecting to all candidate destination
478
+ # addresses.
479
+ # The `connect_timeout` specifies the timeout in seconds from the start of
480
+ # the connection attempt to the last candidate.
481
+ # By default, all connection attempts continue until the timeout occurs.
482
+ # When `fast_fallback:false` is explicitly specified,
483
+ # a timeout is set for each connection attempt and any connection attempt
484
+ # that exceeds its timeout will be canceled.
485
+ #
486
+ # :fast_fallback
487
+ # : Enables the Happy Eyeballs Version 2 algorithm (enabled by default).
472
488
  #
473
489
  #
474
490
  # If a block is given, the block is called with the socket. The value of the
@@ -482,6 +498,31 @@ class Socket < BasicSocket
482
498
  # puts sock.read
483
499
  # }
484
500
  #
501
+ # ### Happy Eyeballs Version 2
502
+ # Happy Eyeballs Version 2 ([RFC
503
+ # 8305](https://datatracker.ietf.org/doc/html/rfc8305)) is an algorithm designed
504
+ # to improve client socket connectivity.
505
+ # It aims for more reliable and efficient connections by performing hostname
506
+ # resolution and connection attempts in parallel, instead of serially.
507
+ #
508
+ # Starting from Ruby 3.4, this method operates as follows with this algorithm:
509
+ #
510
+ # 1. Start resolving both IPv6 and IPv4 addresses concurrently.
511
+ # 2. Start connecting to the one of the addresses that are obtained first.
512
+ # If IPv4 addresses are obtained first, the method waits 50 ms for IPv6 name
513
+ # resolution to prioritize IPv6 connections.
514
+ # 3. After starting a connection attempt, wait 250 ms for the connection to be
515
+ # established.
516
+ # If no connection is established within this time, a new connection is
517
+ # started every 250 ms
518
+ # until a connection is established or there are no more candidate
519
+ # addresses.
520
+ # (Although RFC 8305 strictly specifies sorting addresses,
521
+ # this method only alternates between IPv6 / IPv4 addresses due to the
522
+ # performance concerns)
523
+ # 4. Once a connection is established, all remaining connection attempts are
524
+ # canceled.
525
+ #
485
526
  def self.tcp: (String host, Integer port, ?String local_host, ?Integer local_port, ?resolv_timeout: Time::_Timeout, ?connect_timeout: Time::_Timeout) -> instance
486
527
  | (String host, Integer port, ?String local_host, ?Integer local_port, ?resolv_timeout: Time::_Timeout, ?connect_timeout: Time::_Timeout) { (instance) -> void } -> void
487
528
 
@@ -832,7 +873,6 @@ class Socket < BasicSocket
832
873
  # * `local_sockaddr` - the `struct` sockaddr contained in a string or an
833
874
  # Addrinfo object
834
875
  #
835
- #
836
876
  # ### Example
837
877
  # require 'socket'
838
878
  #
@@ -873,7 +913,6 @@ class Socket < BasicSocket
873
913
  # * Errno::EOPNOTSUPP - the socket type of the `socket` does not support
874
914
  # binding to an address
875
915
  #
876
- #
877
916
  # On unix-based based systems if the address family of the calling `socket` is
878
917
  # Socket::AF_UNIX the follow exceptions may be raised if the call to *bind*
879
918
  # fails:
@@ -892,7 +931,6 @@ class Socket < BasicSocket
892
931
  # *sockaddr* is not a directory
893
932
  # * Errno::EROFS - the name would reside on a read only filesystem
894
933
  #
895
- #
896
934
  # ### Windows Exceptions
897
935
  # On Windows systems the following system exceptions may be raised if the call
898
936
  # to *bind* fails:
@@ -908,7 +946,6 @@ class Socket < BasicSocket
908
946
  # * Errno::ENOBUFS - no buffer space is available
909
947
  # * Errno::ENOTSOCK - the `socket` argument does not refer to a socket
910
948
  #
911
- #
912
949
  # ### See
913
950
  # * bind manual pages on unix-based systems
914
951
  # * bind function in Microsoft's Winsock functions reference
@@ -926,7 +963,6 @@ class Socket < BasicSocket
926
963
  # * `remote_sockaddr` - the `struct` sockaddr contained in a string or
927
964
  # Addrinfo object
928
965
  #
929
- #
930
966
  # ### Example:
931
967
  # # Pull down Google's web page
932
968
  # require 'socket'
@@ -981,7 +1017,6 @@ class Socket < BasicSocket
981
1017
  # * Errno::ETIMEDOUT - the attempt to connect timed out before a connection
982
1018
  # was made.
983
1019
  #
984
- #
985
1020
  # On unix-based systems if the address family of the calling `socket` is AF_UNIX
986
1021
  # the follow exceptions may be raised if the call to *connect* fails:
987
1022
  # * Errno::EIO - an i/o error occurred while reading from or writing to the
@@ -995,7 +1030,6 @@ class Socket < BasicSocket
995
1030
  # * Errno::ENOTDIR - a component of the path prefix of the pathname in
996
1031
  # *sockaddr* is not a directory
997
1032
  #
998
- #
999
1033
  # ### Windows Exceptions
1000
1034
  # On Windows systems the following system exceptions may be raised if the call
1001
1035
  # to *connect* fails:
@@ -1028,7 +1062,6 @@ class Socket < BasicSocket
1028
1062
  # * Errno::EACCES - the attempt to connect the datagram socket to the
1029
1063
  # broadcast address failed
1030
1064
  #
1031
- #
1032
1065
  # ### See
1033
1066
  # * connect manual pages on unix-based systems
1034
1067
  # * connect function in Microsoft's Winsock functions reference
@@ -1102,7 +1135,6 @@ class Socket < BasicSocket
1102
1135
  # ### Parameter
1103
1136
  # * `backlog` - the maximum length of the queue for pending connections.
1104
1137
  #
1105
- #
1106
1138
  # ### Example 1
1107
1139
  # require 'socket'
1108
1140
  # include Socket::Constants
@@ -1139,7 +1171,6 @@ class Socket < BasicSocket
1139
1171
  # * Errno::ENOBUFS - insufficient resources are available in the system to
1140
1172
  # complete the call
1141
1173
  #
1142
- #
1143
1174
  # ### Windows Exceptions
1144
1175
  # On Windows systems the following system exceptions may be raised if the call
1145
1176
  # to *listen* fails:
@@ -1159,7 +1190,6 @@ class Socket < BasicSocket
1159
1190
  # * Errno::EOPNOTSUPP - the referenced `socket` is not a type that supports
1160
1191
  # the *listen* method
1161
1192
  #
1162
- #
1163
1193
  # ### See
1164
1194
  # * listen manual pages on unix-based systems
1165
1195
  # * listen function in Microsoft's Winsock functions reference
@@ -1180,7 +1210,6 @@ class Socket < BasicSocket
1180
1210
  # * `maxlen` - the maximum number of bytes to receive from the socket
1181
1211
  # * `flags` - zero or more of the `MSG_` options
1182
1212
  #
1183
- #
1184
1213
  # ### Example
1185
1214
  # # In one file, start this first
1186
1215
  # require 'socket'
@@ -1236,7 +1265,6 @@ class Socket < BasicSocket
1236
1265
  # * Errno::ETIMEDOUT - the connection timed out during connection
1237
1266
  # establishment or due to a transmission timeout on an active connection
1238
1267
  #
1239
- #
1240
1268
  # ### Windows Exceptions
1241
1269
  # On Windows systems the following system exceptions may be raised if the call
1242
1270
  # to *recvfrom* fails:
@@ -1298,7 +1326,6 @@ class Socket < BasicSocket
1298
1326
  # * `outbuf` - destination String buffer
1299
1327
  # * `opts` - keyword hash, supporting `exception: false`
1300
1328
  #
1301
- #
1302
1329
  # ### Example
1303
1330
  # # In one file, start this first
1304
1331
  # require 'socket'
@@ -4122,7 +4149,6 @@ class Socket::AncillaryData
4122
4149
  # * Socket::AF_UNIX, "AF_UNIX", "UNIX", :AF_UNIX, :UNIX
4123
4150
  # * etc.
4124
4151
  #
4125
- #
4126
4152
  # *cmsg_level* should be an integer, a string or a symbol.
4127
4153
  # * Socket::SOL_SOCKET, "SOL_SOCKET", "SOCKET", :SOL_SOCKET and :SOCKET
4128
4154
  # * Socket::IPPROTO_IP, "IP" and :IP
@@ -4130,7 +4156,6 @@ class Socket::AncillaryData
4130
4156
  # * Socket::IPPROTO_TCP, "TCP" and :TCP
4131
4157
  # * etc.
4132
4158
  #
4133
- #
4134
4159
  # *cmsg_type* should be an integer, a string or a symbol. If a string/symbol is
4135
4160
  # specified, it is interpreted depend on *cmsg_level*.
4136
4161
  # * Socket::SCM_RIGHTS, "SCM_RIGHTS", "RIGHTS", :SCM_RIGHTS, :RIGHTS for
@@ -4139,7 +4164,6 @@ class Socket::AncillaryData
4139
4164
  # * Socket::IPV6_PKTINFO, "PKTINFO" and :PKTINFO for IPPROTO_IPV6
4140
4165
  # * etc.
4141
4166
  #
4142
- #
4143
4167
  # *cmsg_data* should be a string.
4144
4168
  #
4145
4169
  # p Socket::AncillaryData.new(:INET, :TCP, :NODELAY, "")
@@ -91,7 +91,6 @@ class TCPServer < TCPSocket
91
91
  # ### Parameter
92
92
  # * `backlog` - the maximum length of the queue for pending connections.
93
93
  #
94
- #
95
94
  # ### Example 1
96
95
  # require 'socket'
97
96
  # include Socket::Constants
@@ -128,7 +127,6 @@ class TCPServer < TCPSocket
128
127
  # * Errno::ENOBUFS - insufficient resources are available in the system to
129
128
  # complete the call
130
129
  #
131
- #
132
130
  # ### Windows Exceptions
133
131
  # On Windows systems the following system exceptions may be raised if the call
134
132
  # to *listen* fails:
@@ -148,7 +146,6 @@ class TCPServer < TCPSocket
148
146
  # * Errno::EOPNOTSUPP - the referenced `socket` is not a type that supports
149
147
  # the *listen* method
150
148
  #
151
- #
152
149
  # ### See
153
150
  # * listen manual pages on unix-based systems
154
151
  # * listen function in Microsoft's Winsock functions reference
@@ -27,7 +27,6 @@ class TCPSocket < IPSocket
27
27
  # cannot be released since gethostbyname() is not thread safe.)
28
28
  # * This method uses gethostbyname() function already removed from POSIX.
29
29
  #
30
- #
31
30
  # This method lookups host information by *hostname*.
32
31
  #
33
32
  # TCPSocket.gethostbyname("localhost")
@@ -38,9 +37,65 @@ class TCPSocket < IPSocket
38
37
  private
39
38
 
40
39
  # <!--
41
- # rdoc-file=lib/resolv-replace.rb
42
- # - new(host, serv, *rest)
40
+ # rdoc-file=ext/socket/tcpsocket.c
41
+ # - TCPSocket.new(remote_host, remote_port, local_host=nil, local_port=nil, resolv_timeout: nil, connect_timeout: nil, fast_fallback: true)
43
42
  # -->
43
+ # Opens a TCP connection to `remote_host` on `remote_port`. If `local_host` and
44
+ # `local_port` are specified, then those parameters are used on the local end to
45
+ # establish the connection.
46
+ #
47
+ # Starting from Ruby 3.4, this method operates according to the Happy Eyeballs
48
+ # Version 2 ([RFC 8305](https://datatracker.ietf.org/doc/html/rfc8305))
49
+ # algorithm by default, except on Windows.
50
+ #
51
+ # To make it behave the same as in Ruby 3.3 and earlier, explicitly specify the
52
+ # option `fast_fallback:false`.
53
+ #
54
+ # Happy Eyeballs Version 2 is not provided on Windows, and it behaves the same
55
+ # as in Ruby 3.3 and earlier.
56
+ #
57
+ # :resolv_timeout
58
+ # : Specifies the timeout in seconds from when the hostname resolution starts.
59
+ #
60
+ # :connect_timeout
61
+ # : This method sequentially attempts connecting to all candidate destination
62
+ # addresses.
63
+ # The `connect_timeout` specifies the timeout in seconds from the start of
64
+ # the connection attempt to the last candidate.
65
+ # By default, all connection attempts continue until the timeout occurs.
66
+ # When `fast_fallback:false` is explicitly specified,
67
+ # a timeout is set for each connection attempt and any connection attempt
68
+ # that exceeds its timeout will be canceled.
69
+ #
70
+ # :fast_fallback
71
+ # : Enables the Happy Eyeballs Version 2 algorithm (enabled by default).
72
+ #
73
+ #
74
+ # ### Happy Eyeballs Version 2
75
+ # Happy Eyeballs Version 2 ([RFC
76
+ # 8305](https://datatracker.ietf.org/doc/html/rfc8305)) is an algorithm designed
77
+ # to improve client socket connectivity.
78
+ # It aims for more reliable and efficient connections by performing hostname
79
+ # resolution and connection attempts in parallel, instead of serially.
80
+ #
81
+ # Starting from Ruby 3.4, this method operates as follows with this algorithm
82
+ # except on Windows:
83
+ #
84
+ # 1. Start resolving both IPv6 and IPv4 addresses concurrently.
85
+ # 2. Start connecting to the one of the addresses that are obtained first.
86
+ # If IPv4 addresses are obtained first, the method waits 50 ms for IPv6 name
87
+ # resolution to prioritize IPv6 connections.
88
+ # 3. After starting a connection attempt, wait 250 ms for the connection to be
89
+ # established.
90
+ # If no connection is established within this time, a new connection is
91
+ # started every 250 ms
92
+ # until a connection is established or there are no more candidate
93
+ # addresses.
94
+ # (Although RFC 8305 strictly specifies sorting addresses,
95
+ # this method only alternates between IPv6 / IPv4 addresses due to the
96
+ # performance concerns)
97
+ # 4. Once a connection is established, all remaining connection attempts are
98
+ # canceled.
44
99
  #
45
100
  def initialize: (String remote_host, Integer remote_port, ?String local_host, ?Integer local_port) -> untyped
46
101
  end
@@ -53,7 +53,6 @@ class UDPSocket < IPSocket
53
53
  # * `outbuf` - destination String buffer
54
54
  # * `options` - keyword hash, supporting `exception: false`
55
55
  #
56
- #
57
56
  # ### Example
58
57
  # require 'socket'
59
58
  # s1 = UDPSocket.new
@@ -69,7 +69,6 @@ class UNIXServer < UNIXSocket
69
69
  # ### Parameter
70
70
  # * `backlog` - the maximum length of the queue for pending connections.
71
71
  #
72
- #
73
72
  # ### Example 1
74
73
  # require 'socket'
75
74
  # include Socket::Constants
@@ -106,7 +105,6 @@ class UNIXServer < UNIXSocket
106
105
  # * Errno::ENOBUFS - insufficient resources are available in the system to
107
106
  # complete the call
108
107
  #
109
- #
110
108
  # ### Windows Exceptions
111
109
  # On Windows systems the following system exceptions may be raised if the call
112
110
  # to *listen* fails:
@@ -126,7 +124,6 @@ class UNIXServer < UNIXSocket
126
124
  # * Errno::EOPNOTSUPP - the referenced `socket` is not a type that supports
127
125
  # the *listen* method
128
126
  #
129
- #
130
127
  # ### See
131
128
  # * listen manual pages on unix-based systems
132
129
  # * listen function in Microsoft's Winsock functions reference