rbs 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,469 @@
1
+ class Addrinfo
2
+ # iterates over the list of Addrinfo objects obtained by Addrinfo.getaddrinfo.
3
+ #
4
+ # Addrinfo.foreach(nil, 80) {|x| p x }
5
+ # #=> #<Addrinfo: 127.0.0.1:80 TCP (:80)>
6
+ # # #<Addrinfo: 127.0.0.1:80 UDP (:80)>
7
+ # # #<Addrinfo: [::1]:80 TCP (:80)>
8
+ # # #<Addrinfo: [::1]:80 UDP (:80)>
9
+ #
10
+ def self.foreach: (String? nodename, String | Integer service, ?Integer? family, ?Symbol socktype, ?(Symbol | Integer) protocol, ?Integer flags, ?timeout: Numeric) { (Addrinfo) -> void } -> void
11
+ |(String? nodename, String | Integer service, ?Integer? family, ?Symbol socktype, ?(Symbol | Integer) protocol, ?Integer flags, ?timeout: Numeric) -> Enumerable[Addrinfo]
12
+
13
+ # returns a list of addrinfo objects as an array.
14
+ #
15
+ # This method converts nodename (hostname) and service (port) to addrinfo. Since
16
+ # the conversion is not unique, the result is a list of addrinfo objects.
17
+ #
18
+ # nodename or service can be nil if no conversion intended.
19
+ #
20
+ # family, socktype and protocol are hint for preferred protocol. If the result
21
+ # will be used for a socket with SOCK_STREAM, SOCK_STREAM should be specified as
22
+ # socktype. If so, Addrinfo.getaddrinfo returns addrinfo list appropriate for
23
+ # SOCK_STREAM. If they are omitted or nil is given, the result is not
24
+ # restricted.
25
+ #
26
+ # Similarly, PF_INET6 as family restricts for IPv6.
27
+ #
28
+ # flags should be bitwise OR of Socket::AI_??? constants such as follows. Note
29
+ # that the exact list of the constants depends on OS.
30
+ #
31
+ # AI_PASSIVE Get address to use with bind()
32
+ # AI_CANONNAME Fill in the canonical name
33
+ # AI_NUMERICHOST Prevent host name resolution
34
+ # AI_NUMERICSERV Prevent service name resolution
35
+ # AI_V4MAPPED Accept IPv4-mapped IPv6 addresses
36
+ # AI_ALL Allow all addresses
37
+ # AI_ADDRCONFIG Accept only if any address is assigned
38
+ #
39
+ # Note that socktype should be specified whenever application knows the usage of
40
+ # the address. Some platform causes an error when socktype is omitted and
41
+ # servname is specified as an integer because some port numbers, 512 for
42
+ # example, are ambiguous without socktype.
43
+ #
44
+ # Addrinfo.getaddrinfo("www.kame.net", 80, nil, :STREAM)
45
+ # #=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net)>,
46
+ # # #<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP (www.kame.net)>]
47
+ #
48
+ def self.getaddrinfo: (String nodename, ?(String | Integer) service, ?Symbol? family, ?(Symbol | Integer) protocol) -> Array[Addrinfo]
49
+
50
+ # returns an addrinfo object for IP address.
51
+ #
52
+ # The port, socktype, protocol of the result is filled by zero. So, it is not
53
+ # appropriate to create a socket.
54
+ #
55
+ # Addrinfo.ip("localhost") #=> #<Addrinfo: 127.0.0.1 (localhost)>
56
+ #
57
+ def self.ip: (String host) -> Addrinfo
58
+
59
+ # returns an addrinfo object for TCP address.
60
+ #
61
+ # Addrinfo.tcp("localhost", "smtp") #=> #<Addrinfo: 127.0.0.1:25 TCP (localhost:smtp)>
62
+ #
63
+ def self.tcp: (String host, String | Integer service) -> Addrinfo
64
+
65
+ # returns an addrinfo object for UDP address.
66
+ #
67
+ # Addrinfo.udp("localhost", "daytime") #=> #<Addrinfo: 127.0.0.1:13 UDP (localhost:daytime)>
68
+ #
69
+ def self.udp: (String host, String | Integer service) -> Addrinfo
70
+
71
+ # returns an addrinfo object for UNIX socket address.
72
+ #
73
+ # *socktype* specifies the socket type. If it is omitted, :STREAM is used.
74
+ #
75
+ # Addrinfo.unix("/tmp/sock") #=> #<Addrinfo: /tmp/sock SOCK_STREAM>
76
+ # Addrinfo.unix("/tmp/sock", :DGRAM) #=> #<Addrinfo: /tmp/sock SOCK_DGRAM>
77
+ #
78
+ def self.unix: (String path, ?Symbol socktype) -> Addrinfo
79
+
80
+ public
81
+
82
+ # returns the address family as an integer.
83
+ #
84
+ # Addrinfo.tcp("localhost", 80).afamily == Socket::AF_INET #=> true
85
+ #
86
+ def afamily: () -> Integer
87
+
88
+ # creates a socket bound to self.
89
+ #
90
+ # If a block is given, it is called with the socket and the value of the block
91
+ # is returned. The socket is returned otherwise.
92
+ #
93
+ # Addrinfo.udp("0.0.0.0", 9981).bind {|s|
94
+ # s.local_address.connect {|s| s.send "hello", 0 }
95
+ # p s.recv(10) #=> "hello"
96
+ # }
97
+ #
98
+ def bind: () -> Socket
99
+ | () { (Socket) -> void } -> void
100
+
101
+ # returns the canonical name as a string.
102
+ #
103
+ # nil is returned if no canonical name.
104
+ #
105
+ # The canonical name is set by Addrinfo.getaddrinfo when AI_CANONNAME is
106
+ # specified.
107
+ #
108
+ # list = Addrinfo.getaddrinfo("www.ruby-lang.org", 80, :INET, :STREAM, nil, Socket::AI_CANONNAME)
109
+ # p list[0] #=> #<Addrinfo: 221.186.184.68:80 TCP carbon.ruby-lang.org (www.ruby-lang.org)>
110
+ # p list[0].canonname #=> "carbon.ruby-lang.org"
111
+ #
112
+ def canonname: () -> String
113
+
114
+ # creates a socket connected to the address of self.
115
+ #
116
+ # The optional argument *opts* is options represented by a hash. *opts* may have
117
+ # following options:
118
+ #
119
+ # :timeout
120
+ # : specify the timeout in seconds.
121
+ #
122
+ #
123
+ # If a block is given, it is called with the socket and the value of the block
124
+ # is returned. The socket is returned otherwise.
125
+ #
126
+ # Addrinfo.tcp("www.ruby-lang.org", 80).connect {|s|
127
+ # s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
128
+ # puts s.read
129
+ # }
130
+ #
131
+ def connect: (?timeout: Numeric) { (Socket) -> void } -> void
132
+ | (?timeout: Numeric) -> Socket
133
+
134
+ # creates a socket connected to the address of self.
135
+ #
136
+ # If one or more arguments given as *local_addr_args*, it is used as the local
137
+ # address of the socket. *local_addr_args* is given for family_addrinfo to
138
+ # obtain actual address.
139
+ #
140
+ # If *local_addr_args* is not given, the local address of the socket is not
141
+ # bound.
142
+ #
143
+ # The optional last argument *opts* is options represented by a hash. *opts* may
144
+ # have following options:
145
+ #
146
+ # :timeout
147
+ # : specify the timeout in seconds.
148
+ #
149
+ #
150
+ # If a block is given, it is called with the socket and the value of the block
151
+ # is returned. The socket is returned otherwise.
152
+ #
153
+ # Addrinfo.tcp("www.ruby-lang.org", 80).connect_from("0.0.0.0", 4649) {|s|
154
+ # s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
155
+ # puts s.read
156
+ # }
157
+ #
158
+ # # Addrinfo object can be taken for the argument.
159
+ # Addrinfo.tcp("www.ruby-lang.org", 80).connect_from(Addrinfo.tcp("0.0.0.0", 4649)) {|s|
160
+ # s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
161
+ # puts s.read
162
+ # }
163
+ #
164
+ def connect_from: (String host, Integer port, ?timeout: Numeric) { (Socket) -> void } -> void
165
+ | (String host, Integer port, ?timeout: Numeric) -> Socket
166
+ | (Addrinfo sockaddr, ?timeout: Numeric) { (Socket) -> void } -> void
167
+ | (Addrinfo sockaddr, ?timeout: Numeric) -> Socket
168
+
169
+ # creates a socket connected to *remote_addr_args* and bound to self.
170
+ #
171
+ # The optional last argument *opts* is options represented by a hash. *opts* may
172
+ # have following options:
173
+ #
174
+ # :timeout
175
+ # : specify the timeout in seconds.
176
+ #
177
+ #
178
+ # If a block is given, it is called with the socket and the value of the block
179
+ # is returned. The socket is returned otherwise.
180
+ #
181
+ # Addrinfo.tcp("0.0.0.0", 4649).connect_to("www.ruby-lang.org", 80) {|s|
182
+ # s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
183
+ # puts s.read
184
+ # }
185
+ #
186
+ def connect_to: (String host, Integer port, ?timeout: Numeric) { (Socket) -> void } -> void
187
+ | (String host, Integer port, ?timeout: Numeric) -> Socket
188
+ | (Addrinfo sockaddr, ?timeout: Numeric) { (Socket) -> void } -> void
189
+ | (Addrinfo sockaddr, ?timeout: Numeric) -> Socket
190
+
191
+ # creates an Addrinfo object from the arguments.
192
+ #
193
+ # The arguments are interpreted as similar to self.
194
+ #
195
+ # Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80)
196
+ # #=> #<Addrinfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)>
197
+ #
198
+ # Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2")
199
+ # #=> #<Addrinfo: /tmp/sock2 SOCK_STREAM>
200
+ #
201
+ def family_addrinfo: (String host, Integer port) -> Addrinfo
202
+ | (String path) -> Addrinfo
203
+
204
+ # returns nodename and service as a pair of strings. This converts struct
205
+ # sockaddr in addrinfo to textual representation.
206
+ #
207
+ # flags should be bitwise OR of Socket::NI_??? constants.
208
+ #
209
+ # Addrinfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"]
210
+ #
211
+ # Addrinfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV)
212
+ # #=> ["localhost", "80"]
213
+ #
214
+ def getnameinfo: (?Integer flags) -> [String, Integer]
215
+
216
+ # returns a string which shows addrinfo in human-readable form.
217
+ #
218
+ # Addrinfo.tcp("localhost", 80).inspect #=> "#<Addrinfo: 127.0.0.1:80 TCP (localhost)>"
219
+ # Addrinfo.unix("/tmp/sock").inspect #=> "#<Addrinfo: /tmp/sock SOCK_STREAM>"
220
+ #
221
+ def inspect: () -> String
222
+
223
+ # returns a string which shows the sockaddr in *addrinfo* with human-readable
224
+ # form.
225
+ #
226
+ # Addrinfo.tcp("localhost", 80).inspect_sockaddr #=> "127.0.0.1:80"
227
+ # Addrinfo.tcp("ip6-localhost", 80).inspect_sockaddr #=> "[::1]:80"
228
+ # Addrinfo.unix("/tmp/sock").inspect_sockaddr #=> "/tmp/sock"
229
+ #
230
+ def inspect_sockaddr: () -> String
231
+
232
+ # returns true if addrinfo is internet (IPv4/IPv6) address. returns false
233
+ # otherwise.
234
+ #
235
+ # Addrinfo.tcp("127.0.0.1", 80).ip? #=> true
236
+ # Addrinfo.tcp("::1", 80).ip? #=> true
237
+ # Addrinfo.unix("/tmp/sock").ip? #=> false
238
+ #
239
+ def ip?: () -> bool
240
+
241
+ # Returns the IP address as a string.
242
+ #
243
+ # Addrinfo.tcp("127.0.0.1", 80).ip_address #=> "127.0.0.1"
244
+ # Addrinfo.tcp("::1", 80).ip_address #=> "::1"
245
+ #
246
+ def ip_address: () -> String
247
+
248
+ # Returns the port number as an integer.
249
+ #
250
+ # Addrinfo.tcp("127.0.0.1", 80).ip_port #=> 80
251
+ # Addrinfo.tcp("::1", 80).ip_port #=> 80
252
+ #
253
+ def ip_port: () -> Integer
254
+
255
+ # Returns the IP address and port number as 2-element array.
256
+ #
257
+ # Addrinfo.tcp("127.0.0.1", 80).ip_unpack #=> ["127.0.0.1", 80]
258
+ # Addrinfo.tcp("::1", 80).ip_unpack #=> ["::1", 80]
259
+ #
260
+ def ip_unpack: () -> [String, Integer]
261
+
262
+ # returns true if addrinfo is IPv4 address. returns false otherwise.
263
+ #
264
+ # Addrinfo.tcp("127.0.0.1", 80).ipv4? #=> true
265
+ # Addrinfo.tcp("::1", 80).ipv4? #=> false
266
+ # Addrinfo.unix("/tmp/sock").ipv4? #=> false
267
+ #
268
+ def ipv4?: () -> bool
269
+
270
+ # Returns true for IPv4 loopback address (127.0.0.0/8). It returns false
271
+ # otherwise.
272
+ #
273
+ def ipv4_loopback?: () -> bool
274
+
275
+ # Returns true for IPv4 multicast address (224.0.0.0/4). It returns false
276
+ # otherwise.
277
+ #
278
+ def ipv4_multicast?: () -> bool
279
+
280
+ # Returns true for IPv4 private address (10.0.0.0/8, 172.16.0.0/12,
281
+ # 192.168.0.0/16). It returns false otherwise.
282
+ #
283
+ def ipv4_private?: () -> bool
284
+
285
+ # returns true if addrinfo is IPv6 address. returns false otherwise.
286
+ #
287
+ # Addrinfo.tcp("127.0.0.1", 80).ipv6? #=> false
288
+ # Addrinfo.tcp("::1", 80).ipv6? #=> true
289
+ # Addrinfo.unix("/tmp/sock").ipv6? #=> false
290
+ #
291
+ def ipv6?: () -> bool
292
+
293
+ # Returns true for IPv6 link local address (ff80::/10). It returns false
294
+ # otherwise.
295
+ #
296
+ def ipv6_linklocal?: () -> bool
297
+
298
+ # Returns true for IPv6 loopback address (::1). It returns false otherwise.
299
+ #
300
+ def ipv6_loopback?: () -> bool
301
+
302
+ # Returns true for IPv6 multicast global scope address. It returns false
303
+ # otherwise.
304
+ #
305
+ def ipv6_mc_global?: () -> bool
306
+
307
+ # Returns true for IPv6 multicast link-local scope address. It returns false
308
+ # otherwise.
309
+ #
310
+ def ipv6_mc_linklocal?: () -> bool
311
+
312
+ # Returns true for IPv6 multicast node-local scope address. It returns false
313
+ # otherwise.
314
+ #
315
+ def ipv6_mc_nodelocal?: () -> bool
316
+
317
+ # Returns true for IPv6 multicast organization-local scope address. It returns
318
+ # false otherwise.
319
+ #
320
+ def ipv6_mc_orglocal?: () -> bool
321
+
322
+ # Returns true for IPv6 multicast site-local scope address. It returns false
323
+ # otherwise.
324
+ #
325
+ def ipv6_mc_sitelocal?: () -> bool
326
+
327
+ # Returns true for IPv6 multicast address (ff00::/8). It returns false
328
+ # otherwise.
329
+ #
330
+ def ipv6_multicast?: () -> bool
331
+
332
+ # Returns true for IPv6 site local address (ffc0::/10). It returns false
333
+ # otherwise.
334
+ #
335
+ def ipv6_sitelocal?: () -> bool
336
+
337
+ # Returns IPv4 address of IPv4 mapped/compatible IPv6 address. It returns nil if
338
+ # `self` is not IPv4 mapped/compatible IPv6 address.
339
+ #
340
+ # Addrinfo.ip("::192.0.2.3").ipv6_to_ipv4 #=> #<Addrinfo: 192.0.2.3>
341
+ # Addrinfo.ip("::ffff:192.0.2.3").ipv6_to_ipv4 #=> #<Addrinfo: 192.0.2.3>
342
+ # Addrinfo.ip("::1").ipv6_to_ipv4 #=> nil
343
+ # Addrinfo.ip("192.0.2.3").ipv6_to_ipv4 #=> nil
344
+ # Addrinfo.unix("/tmp/sock").ipv6_to_ipv4 #=> nil
345
+ #
346
+ def ipv6_to_ipv4: () -> Addrinfo?
347
+
348
+ # Returns true for IPv6 unique local address (fc00::/7, RFC4193). It returns
349
+ # false otherwise.
350
+ #
351
+ def ipv6_unique_local?: () -> bool
352
+
353
+ # Returns true for IPv6 unspecified address (::). It returns false otherwise.
354
+ #
355
+ def ipv6_unspecified?: () -> bool
356
+
357
+ # Returns true for IPv4-compatible IPv6 address (::/80). It returns false
358
+ # otherwise.
359
+ #
360
+ def ipv6_v4compat?: () -> bool
361
+
362
+ # Returns true for IPv4-mapped IPv6 address (::ffff:0:0/80). It returns false
363
+ # otherwise.
364
+ #
365
+ def ipv6_v4mapped?: () -> bool
366
+
367
+ # creates a listening socket bound to self.
368
+ #
369
+ def listen: (Integer backlog) -> void
370
+
371
+ def marshal_dump: () -> String
372
+
373
+ def marshal_load: (String) -> instance
374
+
375
+ # returns the protocol family as an integer.
376
+ #
377
+ # Addrinfo.tcp("localhost", 80).pfamily == Socket::PF_INET #=> true
378
+ #
379
+ def pfamily: () -> Integer
380
+
381
+ # returns the socket type as an integer.
382
+ #
383
+ # Addrinfo.tcp("localhost", 80).protocol == Socket::IPPROTO_TCP #=> true
384
+ #
385
+ def protocol: () -> Integer
386
+
387
+ # returns the socket type as an integer.
388
+ #
389
+ # Addrinfo.tcp("localhost", 80).socktype == Socket::SOCK_STREAM #=> true
390
+ #
391
+ def socktype: () -> Integer
392
+
393
+ # returns the socket address as packed struct sockaddr string.
394
+ #
395
+ # Addrinfo.tcp("localhost", 80).to_sockaddr
396
+ # #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
397
+ #
398
+ def to_s: () -> String
399
+
400
+ # returns the socket address as packed struct sockaddr string.
401
+ #
402
+ # Addrinfo.tcp("localhost", 80).to_sockaddr
403
+ # #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
404
+ #
405
+ def to_sockaddr: () -> String
406
+
407
+ # returns true if addrinfo is UNIX address. returns false otherwise.
408
+ #
409
+ # Addrinfo.tcp("127.0.0.1", 80).unix? #=> false
410
+ # Addrinfo.tcp("::1", 80).unix? #=> false
411
+ # Addrinfo.unix("/tmp/sock").unix? #=> true
412
+ #
413
+ def unix?: () -> bool
414
+
415
+ # Returns the socket path as a string.
416
+ #
417
+ # Addrinfo.unix("/tmp/sock").unix_path #=> "/tmp/sock"
418
+ #
419
+ def unix_path: () -> String
420
+
421
+ private
422
+
423
+ # returns a new instance of Addrinfo. The instance contains sockaddr, family,
424
+ # socktype, protocol. sockaddr means struct sockaddr which can be used for
425
+ # connect(2), etc. family, socktype and protocol are integers which is used for
426
+ # arguments of socket(2).
427
+ #
428
+ # sockaddr is specified as an array or a string. The array should be compatible
429
+ # to the value of IPSocket#addr or UNIXSocket#addr. The string should be struct
430
+ # sockaddr as generated by Socket.sockaddr_in or Socket.unpack_sockaddr_un.
431
+ #
432
+ # sockaddr examples:
433
+ #
434
+ # "AF_INET", 46102, "localhost.localdomain", "127.0.0.1"
435
+ # :
436
+ #
437
+ # "AF_INET6", 42304, "ip6-localhost", "::1"
438
+ # :
439
+ #
440
+ # "AF_UNIX", "/tmp/sock"
441
+ # :
442
+ # * Socket.sockaddr_in("smtp", "2001:DB8::1")
443
+ # * Socket.sockaddr_in(80, "172.18.22.42")
444
+ # * Socket.sockaddr_in(80, "www.ruby-lang.org")
445
+ # * Socket.sockaddr_un("/tmp/sock")
446
+ #
447
+ #
448
+ # In an AF_INET/AF_INET6 sockaddr array, the 4th element, numeric IP address, is
449
+ # used to construct socket address in the Addrinfo instance. If the 3rd element,
450
+ # textual host name, is non-nil, it is also recorded but used only for
451
+ # Addrinfo#inspect.
452
+ #
453
+ # family is specified as an integer to specify the protocol family such as
454
+ # Socket::PF_INET. It can be a symbol or a string which is the constant name
455
+ # with or without PF_ prefix such as :INET, :INET6, :UNIX, "PF_INET", etc. If
456
+ # omitted, PF_UNSPEC is assumed.
457
+ #
458
+ # socktype is specified as an integer to specify the socket type such as
459
+ # Socket::SOCK_STREAM. It can be a symbol or a string which is the constant name
460
+ # with or without SOCK_ prefix such as :STREAM, :DGRAM, :RAW, "SOCK_STREAM",
461
+ # etc. If omitted, 0 is assumed.
462
+ #
463
+ # protocol is specified as an integer to specify the protocol such as
464
+ # Socket::IPPROTO_TCP. It must be an integer, unlike family and socktype. If
465
+ # omitted, 0 is assumed. Note that 0 is reasonable value for most protocols,
466
+ # except raw socket.
467
+ #
468
+ def initialize: (String sockaddr, ?Symbol family, ?(Symbol | Integer)? socktype, ?Integer? protocol) -> untyped
469
+ end