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,72 @@
1
+ # IPSocket is the super class of TCPSocket and UDPSocket.
2
+ class IPSocket < BasicSocket
3
+ # Lookups the IP address of *host*.
4
+ #
5
+ # require 'socket'
6
+ #
7
+ # IPSocket.getaddress("localhost") #=> "127.0.0.1"
8
+ # IPSocket.getaddress("ip6-localhost") #=> "::1"
9
+ #
10
+ def self.getaddress: (String host) -> String
11
+
12
+ public
13
+
14
+ # Returns the local address as an array which contains address_family, port,
15
+ # hostname and numeric_address.
16
+ #
17
+ # If `reverse_lookup` is `true` or `:hostname`, hostname is obtained from
18
+ # numeric_address using reverse lookup. Or if it is `false`, or `:numeric`,
19
+ # hostname is same as numeric_address. Or if it is `nil` or omitted, obeys to
20
+ # `ipsocket.do_not_reverse_lookup`. See `Socket.getaddrinfo` also.
21
+ #
22
+ # TCPSocket.open("www.ruby-lang.org", 80) {|sock|
23
+ # p sock.addr #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
24
+ # p sock.addr(true) #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
25
+ # p sock.addr(false) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"]
26
+ # p sock.addr(:hostname) #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
27
+ # p sock.addr(:numeric) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"]
28
+ # }
29
+ #
30
+ def addr: (?(boolish | :hostname | :numeric) reverse_lookup) -> [String, Integer, String, String]
31
+
32
+ # Return a string describing this IPSocket object.
33
+ #
34
+ def inspect: () -> String
35
+
36
+ # Returns the remote address as an array which contains address_family, port,
37
+ # hostname and numeric_address. It is defined for connection oriented socket
38
+ # such as TCPSocket.
39
+ #
40
+ # If `reverse_lookup` is `true` or `:hostname`, hostname is obtained from
41
+ # numeric_address using reverse lookup. Or if it is `false`, or `:numeric`,
42
+ # hostname is same as numeric_address. Or if it is `nil` or omitted, obeys to
43
+ # `ipsocket.do_not_reverse_lookup`. See `Socket.getaddrinfo` also.
44
+ #
45
+ # TCPSocket.open("www.ruby-lang.org", 80) {|sock|
46
+ # p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
47
+ # p sock.peeraddr(true) #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
48
+ # p sock.peeraddr(false) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
49
+ # p sock.peeraddr(:hostname) #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
50
+ # p sock.peeraddr(:numeric) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
51
+ # }
52
+ #
53
+ def peeraddr: (?(boolish | :hostname | :numeric) reverse_lookup) -> [String, Integer, String, String]
54
+
55
+ # Receives a message and return the message as a string and an address which the
56
+ # message come from.
57
+ #
58
+ # *maxlen* is the maximum number of bytes to receive.
59
+ #
60
+ # *flags* should be a bitwise OR of Socket::MSG_* constants.
61
+ #
62
+ # ipaddr is same as IPSocket#{peeraddr,addr}.
63
+ #
64
+ # u1 = UDPSocket.new
65
+ # u1.bind("127.0.0.1", 4913)
66
+ # u2 = UDPSocket.new
67
+ # u2.send "uuuu", 0, "127.0.0.1", 4913
68
+ # p u1.recvfrom(10) #=> ["uuuu", ["AF_INET", 33230, "localhost", "127.0.0.1"]]
69
+ #
70
+ #
71
+ def recvfrom: (Integer maxlen, ?Integer flags) -> [String, [String, Integer, String, String]]
72
+ end
@@ -0,0 +1,2687 @@
1
+ # Class `Socket` provides access to the underlying operating system socket
2
+ # implementations. It can be used to provide more operating system specific
3
+ # functionality than the protocol-specific socket classes.
4
+ #
5
+ # The constants defined under Socket::Constants are also defined under Socket.
6
+ # For example, Socket::AF_INET is usable as well as Socket::Constants::AF_INET.
7
+ # See Socket::Constants for the list of constants.
8
+ #
9
+ # ### What's a socket?
10
+ #
11
+ # Sockets are endpoints of a bidirectional communication channel. Sockets can
12
+ # communicate within a process, between processes on the same machine or between
13
+ # different machines. There are many types of socket: TCPSocket, UDPSocket or
14
+ # UNIXSocket for example.
15
+ #
16
+ # Sockets have their own vocabulary:
17
+ #
18
+ # **domain:** The family of protocols:
19
+ # * Socket::PF_INET
20
+ # * Socket::PF_INET6
21
+ # * Socket::PF_UNIX
22
+ # * etc.
23
+ #
24
+ #
25
+ # **type:** The type of communications between the two endpoints, typically
26
+ # * Socket::SOCK_STREAM
27
+ # * Socket::SOCK_DGRAM.
28
+ #
29
+ #
30
+ # **protocol:** Typically *zero*. This may be used to identify a variant of a
31
+ # protocol.
32
+ #
33
+ # **hostname:** The identifier of a network interface:
34
+ # * a string (hostname, IPv4 or IPv6 address or `broadcast` which specifies a
35
+ # broadcast address)
36
+ # * a zero-length string which specifies INADDR_ANY
37
+ # * an integer (interpreted as binary address in host byte order).
38
+ #
39
+ #
40
+ # ### Quick start
41
+ #
42
+ # Many of the classes, such as TCPSocket, UDPSocket or UNIXSocket, ease the use
43
+ # of sockets comparatively to the equivalent C programming interface.
44
+ #
45
+ # Let's create an internet socket using the IPv4 protocol in a C-like manner:
46
+ #
47
+ # require 'socket'
48
+ #
49
+ # s = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
50
+ # s.connect Socket.pack_sockaddr_in(80, 'example.com')
51
+ #
52
+ # You could also use the TCPSocket class:
53
+ #
54
+ # s = TCPSocket.new 'example.com', 80
55
+ #
56
+ # A simple server might look like this:
57
+ #
58
+ # require 'socket'
59
+ #
60
+ # server = TCPServer.new 2000 # Server bound to port 2000
61
+ #
62
+ # loop do
63
+ # client = server.accept # Wait for a client to connect
64
+ # client.puts "Hello !"
65
+ # client.puts "Time is #{Time.now}"
66
+ # client.close
67
+ # end
68
+ #
69
+ # A simple client may look like this:
70
+ #
71
+ # require 'socket'
72
+ #
73
+ # s = TCPSocket.new 'localhost', 2000
74
+ #
75
+ # while line = s.gets # Read lines from socket
76
+ # puts line # and print them
77
+ # end
78
+ #
79
+ # s.close # close socket when done
80
+ #
81
+ # ### Exception Handling
82
+ #
83
+ # Ruby's Socket implementation raises exceptions based on the error generated by
84
+ # the system dependent implementation. This is why the methods are documented
85
+ # in a way that isolate Unix-based system exceptions from Windows based
86
+ # exceptions. If more information on a particular exception is needed, please
87
+ # refer to the Unix manual pages or the Windows WinSock reference.
88
+ #
89
+ # ### Convenience methods
90
+ #
91
+ # Although the general way to create socket is Socket.new, there are several
92
+ # methods of socket creation for most cases.
93
+ #
94
+ # TCP client socket
95
+ # : Socket.tcp, TCPSocket.open
96
+ # TCP server socket
97
+ # : Socket.tcp_server_loop, TCPServer.open
98
+ # UNIX client socket
99
+ # : Socket.unix, UNIXSocket.open
100
+ # UNIX server socket
101
+ # : Socket.unix_server_loop, UNIXServer.open
102
+ #
103
+ #
104
+ # ### Documentation by
105
+ #
106
+ # * Zach Dennis
107
+ # * Sam Roberts
108
+ # * *Programming Ruby* from The Pragmatic Bookshelf.
109
+ #
110
+ #
111
+ # Much material in this documentation is taken with permission from *Programming
112
+ # Ruby* from The Pragmatic Bookshelf.
113
+ class Socket < BasicSocket
114
+ # yield socket and client address for each a connection accepted via given
115
+ # sockets.
116
+ #
117
+ # The arguments are a list of sockets. The individual argument should be a
118
+ # socket or an array of sockets.
119
+ #
120
+ # This method yields the block sequentially. It means that the next connection
121
+ # is not accepted until the block returns. So concurrent mechanism, thread for
122
+ # example, should be used to service multiple clients at a time.
123
+ #
124
+ def self.accept_loop: (*_ToIO sockets) { (Socket) -> void } -> void
125
+
126
+ # Obtains address information for *nodename*:*servname*.
127
+ #
128
+ # Note that Addrinfo.getaddrinfo provides the same functionality in an object
129
+ # oriented style.
130
+ #
131
+ # *family* should be an address family such as: :INET, :INET6, etc.
132
+ #
133
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
134
+ #
135
+ # *protocol* should be a protocol defined in the family, and defaults to 0 for
136
+ # the family.
137
+ #
138
+ # *flags* should be bitwise OR of Socket::AI_* constants.
139
+ #
140
+ # Socket.getaddrinfo("www.ruby-lang.org", "http", nil, :STREAM)
141
+ # #=> [["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68", 2, 1, 6]] # PF_INET/SOCK_STREAM/IPPROTO_TCP
142
+ #
143
+ # Socket.getaddrinfo("localhost", nil)
144
+ # #=> [["AF_INET", 0, "localhost", "127.0.0.1", 2, 1, 6], # PF_INET/SOCK_STREAM/IPPROTO_TCP
145
+ # # ["AF_INET", 0, "localhost", "127.0.0.1", 2, 2, 17], # PF_INET/SOCK_DGRAM/IPPROTO_UDP
146
+ # # ["AF_INET", 0, "localhost", "127.0.0.1", 2, 3, 0]] # PF_INET/SOCK_RAW/IPPROTO_IP
147
+ #
148
+ # *reverse_lookup* directs the form of the third element, and has to be one of
149
+ # below. If *reverse_lookup* is omitted, the default value is `nil`.
150
+ #
151
+ # +true+, +:hostname+: hostname is obtained from numeric address using reverse lookup, which may take a time.
152
+ # +false+, +:numeric+: hostname is same as numeric address.
153
+ # +nil+: obey to the current +do_not_reverse_lookup+ flag.
154
+ #
155
+ # If Addrinfo object is preferred, use Addrinfo.getaddrinfo.
156
+ #
157
+ def self.getaddrinfo: (String peer, String | Integer | nil protocol, ?(Integer | Symbol | nil) family, ?(Integer | Symbol | nil) socktype, ?(Integer | Symbol | nil) protocol, ?(Integer | nil) flags) -> [String, Integer, String, String, Integer, Integer, Integer]
158
+
159
+ # Use Addrinfo#getnameinfo instead. This method is deprecated for the following
160
+ # reasons:
161
+ #
162
+ # * Uncommon address representation: 4/16-bytes binary string to represent
163
+ # IPv4/IPv6 address.
164
+ # * gethostbyaddr() may take a long time and it may block other threads. (GVL
165
+ # cannot be released since gethostbyname() is not thread safe.)
166
+ # * This method uses gethostbyname() function already removed from POSIX.
167
+ #
168
+ #
169
+ # This method obtains the host information for *address*.
170
+ #
171
+ # p Socket.gethostbyaddr([221,186,184,68].pack("CCCC"))
172
+ # #=> ["carbon.ruby-lang.org", [], 2, "\xDD\xBA\xB8D"]
173
+ #
174
+ # p Socket.gethostbyaddr([127,0,0,1].pack("CCCC"))
175
+ # ["localhost", [], 2, "\x7F\x00\x00\x01"]
176
+ # p Socket.gethostbyaddr(([0]*15+[1]).pack("C"*16))
177
+ # #=> ["localhost", ["ip6-localhost", "ip6-loopback"], 10,
178
+ # "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"]
179
+ #
180
+ def self.gethostbyaddr: (String ip) -> [String, Array[String], Integer, String]
181
+
182
+ # Use Addrinfo.getaddrinfo instead. This method is deprecated for the following
183
+ # reasons:
184
+ #
185
+ # * The 3rd element of the result is the address family of the first address.
186
+ # The address families of the rest of the addresses are not returned.
187
+ # * Uncommon address representation: 4/16-bytes binary string to represent
188
+ # IPv4/IPv6 address.
189
+ # * gethostbyname() may take a long time and it may block other threads. (GVL
190
+ # cannot be released since gethostbyname() is not thread safe.)
191
+ # * This method uses gethostbyname() function already removed from POSIX.
192
+ #
193
+ #
194
+ # This method obtains the host information for *hostname*.
195
+ #
196
+ # p Socket.gethostbyname("hal") #=> ["localhost", ["hal"], 2, "\x7F\x00\x00\x01"]
197
+ #
198
+ def self.gethostbyname: (String name) -> [String, Array[String], Integer, String]
199
+
200
+ # Returns the hostname.
201
+ #
202
+ # p Socket.gethostname #=> "hal"
203
+ #
204
+ # Note that it is not guaranteed to be able to convert to IP address using
205
+ # gethostbyname, getaddrinfo, etc. If you need local IP address, use
206
+ # Socket.ip_address_list.
207
+ #
208
+ def self.gethostname: () -> String
209
+
210
+ # Returns an array of interface addresses. An element of the array is an
211
+ # instance of Socket::Ifaddr.
212
+ #
213
+ # This method can be used to find multicast-enabled interfaces:
214
+ #
215
+ # pp Socket.getifaddrs.reject {|ifaddr|
216
+ # !ifaddr.addr.ip? || (ifaddr.flags & Socket::IFF_MULTICAST == 0)
217
+ # }.map {|ifaddr| [ifaddr.name, ifaddr.ifindex, ifaddr.addr] }
218
+ # #=> [["eth0", 2, #<Addrinfo: 221.186.184.67>],
219
+ # # ["eth0", 2, #<Addrinfo: fe80::216:3eff:fe95:88bb%eth0>]]
220
+ #
221
+ # Example result on GNU/Linux:
222
+ # pp Socket.getifaddrs
223
+ # #=> [#<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 PACKET[protocol=0 lo hatype=772 HOST hwaddr=00:00:00:00:00:00]>,
224
+ # # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 PACKET[protocol=0 eth0 hatype=1 HOST hwaddr=00:16:3e:95:88:bb] broadcast=PACKET[protocol=0 eth0 hatype=1 HOST hwaddr=ff:ff:ff:ff:ff:ff]>,
225
+ # # #<Socket::Ifaddr sit0 NOARP PACKET[protocol=0 sit0 hatype=776 HOST hwaddr=00:00:00:00]>,
226
+ # # #<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 127.0.0.1 netmask=255.0.0.0>,
227
+ # # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 221.186.184.67 netmask=255.255.255.240 broadcast=221.186.184.79>,
228
+ # # #<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 ::1 netmask=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>,
229
+ # # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 fe80::216:3eff:fe95:88bb%eth0 netmask=ffff:ffff:ffff:ffff::>]
230
+ #
231
+ # Example result on FreeBSD:
232
+ # pp Socket.getifaddrs
233
+ # #=> [#<Socket::Ifaddr usbus0 UP,0x10000 LINK[usbus0]>,
234
+ # # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 LINK[re0 3a:d0:40:9a:fe:e8]>,
235
+ # # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 10.250.10.18 netmask=255.255.255.? (7 bytes for 16 bytes sockaddr_in) broadcast=10.250.10.255>,
236
+ # # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 fe80:2::38d0:40ff:fe9a:fee8 netmask=ffff:ffff:ffff:ffff::>,
237
+ # # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 2001:2e8:408:10::12 netmask=UNSPEC>,
238
+ # # #<Socket::Ifaddr plip0 POINTOPOINT,MULTICAST,0x800 LINK[plip0]>,
239
+ # # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST LINK[lo0]>,
240
+ # # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST ::1 netmask=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>,
241
+ # # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST fe80:4::1 netmask=ffff:ffff:ffff:ffff::>,
242
+ # # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST 127.0.0.1 netmask=255.?.?.? (5 bytes for 16 bytes sockaddr_in)>]
243
+ #
244
+ def self.getifaddrs: () -> Array[Socket::Ifaddr]
245
+
246
+ # Obtains name information for *sockaddr*.
247
+ #
248
+ # *sockaddr* should be one of follows.
249
+ # * packed sockaddr string such as Socket.sockaddr_in(80, "127.0.0.1")
250
+ # * 3-elements array such as ["AF_INET", 80, "127.0.0.1"]
251
+ # * 4-elements array such as ["AF_INET", 80, ignored, "127.0.0.1"]
252
+ #
253
+ #
254
+ # *flags* should be bitwise OR of Socket::NI_* constants.
255
+ #
256
+ # Note: The last form is compatible with IPSocket#addr and IPSocket#peeraddr.
257
+ #
258
+ # Socket.getnameinfo(Socket.sockaddr_in(80, "127.0.0.1")) #=> ["localhost", "www"]
259
+ # Socket.getnameinfo(["AF_INET", 80, "127.0.0.1"]) #=> ["localhost", "www"]
260
+ # Socket.getnameinfo(["AF_INET", 80, "localhost", "127.0.0.1"]) #=> ["localhost", "www"]
261
+ #
262
+ # If Addrinfo object is preferred, use Addrinfo#getnameinfo.
263
+ #
264
+ def self.getnameinfo: ([String, Integer, String]) -> Array[String]
265
+ | ([String, Integer, String, String]) -> Array[String]
266
+ | (String sockaddr) -> Array[String]
267
+ # Obtains the port number for *service_name*.
268
+ #
269
+ # If *protocol_name* is not given, "tcp" is assumed.
270
+ #
271
+ # Socket.getservbyname("smtp") #=> 25
272
+ # Socket.getservbyname("shell") #=> 514
273
+ # Socket.getservbyname("syslog", "udp") #=> 514
274
+ #
275
+ #
276
+ def self.getservbyname: (String service_proto) -> Integer
277
+ | (String service_proto, String layer4_proto) -> Integer
278
+
279
+ # Obtains the port number for *port*.
280
+ #
281
+ # If *protocol_name* is not given, "tcp" is assumed.
282
+ #
283
+ # Socket.getservbyport(80) #=> "www"
284
+ # Socket.getservbyport(514, "tcp") #=> "shell"
285
+ # Socket.getservbyport(514, "udp") #=> "syslog"
286
+ #
287
+ def self.getservbyport: (Integer service_port) -> String
288
+ | (Integer service_port, String layer4_proto) -> String
289
+
290
+ # Returns local IP addresses as an array.
291
+ #
292
+ # The array contains Addrinfo objects.
293
+ #
294
+ # pp Socket.ip_address_list
295
+ # #=> [#<Addrinfo: 127.0.0.1>,
296
+ # #<Addrinfo: 192.168.0.128>,
297
+ # #<Addrinfo: ::1>,
298
+ # ...]
299
+ #
300
+ def self.ip_address_list: () -> Array[Addrinfo]
301
+
302
+ # Packs *port* and *host* as an AF_INET/AF_INET6 sockaddr string.
303
+ #
304
+ # Socket.sockaddr_in(80, "127.0.0.1")
305
+ # #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
306
+ #
307
+ # Socket.sockaddr_in(80, "::1")
308
+ # #=> "\n\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00"
309
+ #
310
+ #
311
+ def self.pack_sockaddr_in: (Integer port, String ip) -> String
312
+
313
+ # Packs *path* as an AF_UNIX sockaddr string.
314
+ #
315
+ # Socket.sockaddr_un("/tmp/sock") #=> "\x01\x00/tmp/sock\x00\x00..."
316
+ #
317
+ #
318
+ def self.pack_sockaddr_un: (String sockpath) -> String
319
+
320
+ # Creates a pair of sockets connected each other.
321
+ #
322
+ # *domain* should be a communications domain such as: :INET, :INET6, :UNIX, etc.
323
+ #
324
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
325
+ #
326
+ # *protocol* should be a protocol defined in the domain, defaults to 0 for the
327
+ # domain.
328
+ #
329
+ # s1, s2 = Socket.pair(:UNIX, :STREAM, 0)
330
+ # s1.send "a", 0
331
+ # s1.send "b", 0
332
+ # s1.close
333
+ # p s2.recv(10) #=> "ab"
334
+ # p s2.recv(10) #=> ""
335
+ # p s2.recv(10) #=> ""
336
+ #
337
+ # s1, s2 = Socket.pair(:UNIX, :DGRAM, 0)
338
+ # s1.send "a", 0
339
+ # s1.send "b", 0
340
+ # p s2.recv(10) #=> "a"
341
+ # p s2.recv(10) #=> "b"
342
+ #
343
+ #
344
+ def self.pair: (Symbol sockdomain, Symbol socktype, Integer protocol) -> [instance, instance]
345
+
346
+ # Packs *port* and *host* as an AF_INET/AF_INET6 sockaddr string.
347
+ #
348
+ # Socket.sockaddr_in(80, "127.0.0.1")
349
+ # #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
350
+ #
351
+ # Socket.sockaddr_in(80, "::1")
352
+ # #=> "\n\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00"
353
+ #
354
+ #
355
+ def self.sockaddr_in: (Integer port, String ip) -> String
356
+
357
+ # Packs *path* as an AF_UNIX sockaddr string.
358
+ #
359
+ # Socket.sockaddr_un("/tmp/sock") #=> "\x01\x00/tmp/sock\x00\x00..."
360
+ #
361
+ #
362
+ def self.sockaddr_un: (String sockpath) -> String
363
+
364
+ # Creates a pair of sockets connected each other.
365
+ #
366
+ # *domain* should be a communications domain such as: :INET, :INET6, :UNIX, etc.
367
+ #
368
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
369
+ #
370
+ # *protocol* should be a protocol defined in the domain, defaults to 0 for the
371
+ # domain.
372
+ #
373
+ # s1, s2 = Socket.pair(:UNIX, :STREAM, 0)
374
+ # s1.send "a", 0
375
+ # s1.send "b", 0
376
+ # s1.close
377
+ # p s2.recv(10) #=> "ab"
378
+ # p s2.recv(10) #=> ""
379
+ # p s2.recv(10) #=> ""
380
+ #
381
+ # s1, s2 = Socket.pair(:UNIX, :DGRAM, 0)
382
+ # s1.send "a", 0
383
+ # s1.send "b", 0
384
+ # p s2.recv(10) #=> "a"
385
+ # p s2.recv(10) #=> "b"
386
+ #
387
+ #
388
+ def self.socketpair: (Symbol sockdomain, Symbol socktype, Integer protocol) -> [instance, instance]
389
+
390
+ # creates a new socket object connected to host:port using TCP/IP.
391
+ #
392
+ # If local_host:local_port is given, the socket is bound to it.
393
+ #
394
+ # The optional last argument *opts* is options represented by a hash. *opts* may
395
+ # have following options:
396
+ #
397
+ # :connect_timeout
398
+ # : specify the timeout in seconds.
399
+ # :resolv_timeout
400
+ # : specify the name resolution timeout in seconds.
401
+ #
402
+ #
403
+ # If a block is given, the block is called with the socket. The value of the
404
+ # block is returned. The socket is closed when this method returns.
405
+ #
406
+ # If no block is given, the socket is returned.
407
+ #
408
+ # Socket.tcp("www.ruby-lang.org", 80) {|sock|
409
+ # sock.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"
410
+ # sock.close_write
411
+ # puts sock.read
412
+ # }
413
+ #
414
+ #
415
+ def self.tcp: (String host, Integer port, ?String local_host, ?Integer local_port, ?resolv_timeout: Numeric, ?connect_timeout: Numeric) -> instance
416
+ | (String host, Integer port, ?String local_host, ?Integer local_port, ?resolv_timeout: Numeric, ?connect_timeout: Numeric) { (instance) -> void } -> void
417
+
418
+ # creates a TCP/IP server on *port* and calls the block for each connection
419
+ # accepted. The block is called with a socket and a client_address as an
420
+ # Addrinfo object.
421
+ #
422
+ # If *host* is specified, it is used with *port* to determine the server
423
+ # addresses.
424
+ #
425
+ # The socket is **not** closed when the block returns. So application should
426
+ # close it explicitly.
427
+ #
428
+ # This method calls the block sequentially. It means that the next connection is
429
+ # not accepted until the block returns. So concurrent mechanism, thread for
430
+ # example, should be used to service multiple clients at a time.
431
+ #
432
+ # Note that Addrinfo.getaddrinfo is used to determine the server socket
433
+ # addresses. When Addrinfo.getaddrinfo returns two or more addresses, IPv4 and
434
+ # IPv6 address for example, all of them are used. Socket.tcp_server_loop
435
+ # succeeds if one socket can be used at least.
436
+ #
437
+ # # Sequential echo server.
438
+ # # It services only one client at a time.
439
+ # Socket.tcp_server_loop(16807) {|sock, client_addrinfo|
440
+ # begin
441
+ # IO.copy_stream(sock, sock)
442
+ # ensure
443
+ # sock.close
444
+ # end
445
+ # }
446
+ #
447
+ # # Threaded echo server
448
+ # # It services multiple clients at a time.
449
+ # # Note that it may accept connections too much.
450
+ # Socket.tcp_server_loop(16807) {|sock, client_addrinfo|
451
+ # Thread.new {
452
+ # begin
453
+ # IO.copy_stream(sock, sock)
454
+ # ensure
455
+ # sock.close
456
+ # end
457
+ # }
458
+ # }
459
+ #
460
+ def self.tcp_server_loop: (?String host, Integer port) { (instance, Addrinfo) -> void } -> void
461
+
462
+ # creates TCP/IP server sockets for *host* and *port*. *host* is optional.
463
+ #
464
+ # If no block given, it returns an array of listening sockets.
465
+ #
466
+ # If a block is given, the block is called with the sockets. The value of the
467
+ # block is returned. The socket is closed when this method returns.
468
+ #
469
+ # If *port* is 0, actual port number is chosen dynamically. However all sockets
470
+ # in the result has same port number.
471
+ #
472
+ # # tcp_server_sockets returns two sockets.
473
+ # sockets = Socket.tcp_server_sockets(1296)
474
+ # p sockets #=> [#<Socket:fd 3>, #<Socket:fd 4>]
475
+ #
476
+ # # The sockets contains IPv6 and IPv4 sockets.
477
+ # sockets.each {|s| p s.local_address }
478
+ # #=> #<Addrinfo: [::]:1296 TCP>
479
+ # # #<Addrinfo: 0.0.0.0:1296 TCP>
480
+ #
481
+ # # IPv6 and IPv4 socket has same port number, 53114, even if it is chosen dynamically.
482
+ # sockets = Socket.tcp_server_sockets(0)
483
+ # sockets.each {|s| p s.local_address }
484
+ # #=> #<Addrinfo: [::]:53114 TCP>
485
+ # # #<Addrinfo: 0.0.0.0:53114 TCP>
486
+ #
487
+ # # The block is called with the sockets.
488
+ # Socket.tcp_server_sockets(0) {|sockets|
489
+ # p sockets #=> [#<Socket:fd 3>, #<Socket:fd 4>]
490
+ # }
491
+ #
492
+ def self.tcp_server_sockets: (?String host, Integer port) -> Array[TCPServer]
493
+ | (?String host, Integer port) { (Array[TCPServer]) -> void } -> void
494
+
495
+ # creates a UDP/IP server on *port* and calls the block for each message
496
+ # arrived. The block is called with the message and its source information.
497
+ #
498
+ # This method allocates sockets internally using *port*. If *host* is specified,
499
+ # it is used conjunction with *port* to determine the server addresses.
500
+ #
501
+ # The *msg* is a string.
502
+ #
503
+ # The *msg_src* is a Socket::UDPSource object. It is used for reply.
504
+ #
505
+ # # UDP/IP echo server.
506
+ # Socket.udp_server_loop(9261) {|msg, msg_src|
507
+ # msg_src.reply msg
508
+ # }
509
+ #
510
+ #
511
+ def self.udp_server_loop: (?String host, Integer port) { (String, Socket::UDPSource) -> void } -> void
512
+
513
+ # Run UDP/IP server loop on the given sockets.
514
+ #
515
+ # The return value of Socket.udp_server_sockets is appropriate for the argument.
516
+ #
517
+ # It calls the block for each message received.
518
+ #
519
+ def self.udp_server_loop_on: (UDPSocket sockets) { (String, Socket::UDPSource) -> void } -> void
520
+
521
+ # Receive UDP/IP packets from the given *sockets*. For each packet received, the
522
+ # block is called.
523
+ #
524
+ # The block receives *msg* and *msg_src*. *msg* is a string which is the payload
525
+ # of the received packet. *msg_src* is a Socket::UDPSource object which is used
526
+ # for reply.
527
+ #
528
+ # Socket.udp_server_loop can be implemented using this method as follows.
529
+ #
530
+ # udp_server_sockets(host, port) {|sockets|
531
+ # loop {
532
+ # readable, _, _ = IO.select(sockets)
533
+ # udp_server_recv(readable) {|msg, msg_src| ... }
534
+ # }
535
+ # }
536
+ #
537
+ def self.udp_server_recv: (Array[UDPSocket] sockets) { (String, Socket::UDPSource) -> void } -> void
538
+
539
+ # Creates UDP/IP sockets for a UDP server.
540
+ #
541
+ # If no block given, it returns an array of sockets.
542
+ #
543
+ # If a block is given, the block is called with the sockets. The value of the
544
+ # block is returned. The sockets are closed when this method returns.
545
+ #
546
+ # If *port* is zero, some port is chosen. But the chosen port is used for the
547
+ # all sockets.
548
+ #
549
+ # # UDP/IP echo server
550
+ # Socket.udp_server_sockets(0) {|sockets|
551
+ # p sockets.first.local_address.ip_port #=> 32963
552
+ # Socket.udp_server_loop_on(sockets) {|msg, msg_src|
553
+ # msg_src.reply msg
554
+ # }
555
+ # }
556
+ #
557
+ def self.udp_server_sockets: (?String host, Integer port) { (UDPSocket) -> void } -> void
558
+
559
+ # creates a new socket connected to path using UNIX socket socket.
560
+ #
561
+ # If a block is given, the block is called with the socket. The value of the
562
+ # block is returned. The socket is closed when this method returns.
563
+ #
564
+ # If no block is given, the socket is returned.
565
+ #
566
+ # # talk to /tmp/sock socket.
567
+ # Socket.unix("/tmp/sock") {|sock|
568
+ # t = Thread.new { IO.copy_stream(sock, STDOUT) }
569
+ # IO.copy_stream(STDIN, sock)
570
+ # t.join
571
+ # }
572
+ #
573
+ def self.unix: (String path) -> UNIXSocket
574
+ | (String path) { (UNIXSocket) -> void } -> void
575
+
576
+ # creates a UNIX socket server on *path*. It calls the block for each socket
577
+ # accepted.
578
+ #
579
+ # If *host* is specified, it is used with *port* to determine the server ports.
580
+ #
581
+ # The socket is **not** closed when the block returns. So application should
582
+ # close it.
583
+ #
584
+ # This method deletes the socket file pointed by *path* at first if the file is
585
+ # a socket file and it is owned by the user of the application. This is safe
586
+ # only if the directory of *path* is not changed by a malicious user. So don't
587
+ # use /tmp/malicious-users-directory/socket. Note that /tmp/socket and
588
+ # /tmp/your-private-directory/socket is safe assuming that /tmp has sticky bit.
589
+ #
590
+ # # Sequential echo server.
591
+ # # It services only one client at a time.
592
+ # Socket.unix_server_loop("/tmp/sock") {|sock, client_addrinfo|
593
+ # begin
594
+ # IO.copy_stream(sock, sock)
595
+ # ensure
596
+ # sock.close
597
+ # end
598
+ # }
599
+ #
600
+ def self.unix_server_loop: (String path) { (UNIXSocket, Addrinfo) -> void } -> void
601
+
602
+ # creates a UNIX server socket on *path*
603
+ #
604
+ # If no block given, it returns a listening socket.
605
+ #
606
+ # If a block is given, it is called with the socket and the block value is
607
+ # returned. When the block exits, the socket is closed and the socket file is
608
+ # removed.
609
+ #
610
+ # socket = Socket.unix_server_socket("/tmp/s")
611
+ # p socket #=> #<Socket:fd 3>
612
+ # p socket.local_address #=> #<Addrinfo: /tmp/s SOCK_STREAM>
613
+ #
614
+ # Socket.unix_server_socket("/tmp/sock") {|s|
615
+ # p s #=> #<Socket:fd 3>
616
+ # p s.local_address #=> # #<Addrinfo: /tmp/sock SOCK_STREAM>
617
+ # }
618
+ #
619
+ def self.unix_server_socket: (String path) -> Socket
620
+ | (String path) { (Socket) -> void } -> void
621
+
622
+ # Unpacks *sockaddr* into port and ip_address.
623
+ #
624
+ # *sockaddr* should be a string or an addrinfo for AF_INET/AF_INET6.
625
+ #
626
+ # sockaddr = Socket.sockaddr_in(80, "127.0.0.1")
627
+ # p sockaddr #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
628
+ # p Socket.unpack_sockaddr_in(sockaddr) #=> [80, "127.0.0.1"]
629
+ #
630
+ def self.unpack_sockaddr_in: (String | Addrinfo sockaddr) -> [Integer, String]
631
+
632
+ # Unpacks *sockaddr* into path.
633
+ #
634
+ # *sockaddr* should be a string or an addrinfo for AF_UNIX.
635
+ #
636
+ # sockaddr = Socket.sockaddr_un("/tmp/sock")
637
+ # p Socket.unpack_sockaddr_un(sockaddr) #=> "/tmp/sock"
638
+ #
639
+ def self.unpack_sockaddr_un: (String path) -> String
640
+
641
+ public
642
+
643
+ # Accepts a next connection. Returns a new Socket object and Addrinfo object.
644
+ #
645
+ # serv = Socket.new(:INET, :STREAM, 0)
646
+ # serv.listen(5)
647
+ # c = Socket.new(:INET, :STREAM, 0)
648
+ # c.connect(serv.connect_address)
649
+ # p serv.accept #=> [#<Socket:fd 6>, #<Addrinfo: 127.0.0.1:48555 TCP>]
650
+ #
651
+ def accept: () -> [Socket, Addrinfo]
652
+
653
+ # Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the
654
+ # underlying file descriptor. It returns an array containing the accepted socket
655
+ # for the incoming connection, *client_socket*, and an Addrinfo,
656
+ # *client_addrinfo*.
657
+ #
658
+ # ### Example
659
+ # # In one script, start this first
660
+ # require 'socket'
661
+ # include Socket::Constants
662
+ # socket = Socket.new(AF_INET, SOCK_STREAM, 0)
663
+ # sockaddr = Socket.sockaddr_in(2200, 'localhost')
664
+ # socket.bind(sockaddr)
665
+ # socket.listen(5)
666
+ # begin # emulate blocking accept
667
+ # client_socket, client_addrinfo = socket.accept_nonblock
668
+ # rescue IO::WaitReadable, Errno::EINTR
669
+ # IO.select([socket])
670
+ # retry
671
+ # end
672
+ # puts "The client said, '#{client_socket.readline.chomp}'"
673
+ # client_socket.puts "Hello from script one!"
674
+ # socket.close
675
+ #
676
+ # # In another script, start this second
677
+ # require 'socket'
678
+ # include Socket::Constants
679
+ # socket = Socket.new(AF_INET, SOCK_STREAM, 0)
680
+ # sockaddr = Socket.sockaddr_in(2200, 'localhost')
681
+ # socket.connect(sockaddr)
682
+ # socket.puts "Hello from script 2."
683
+ # puts "The server said, '#{socket.readline.chomp}'"
684
+ # socket.close
685
+ #
686
+ # Refer to Socket#accept for the exceptions that may be thrown if the call to
687
+ # *accept_nonblock* fails.
688
+ #
689
+ # Socket#accept_nonblock may raise any error corresponding to accept(2) failure,
690
+ # including Errno::EWOULDBLOCK.
691
+ #
692
+ # If the exception is Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::ECONNABORTED or
693
+ # Errno::EPROTO, it is extended by IO::WaitReadable. So IO::WaitReadable can be
694
+ # used to rescue the exceptions for retrying accept_nonblock.
695
+ #
696
+ # By specifying a keyword argument *exception* to `false`, you can indicate that
697
+ # accept_nonblock should not raise an IO::WaitReadable exception, but return the
698
+ # symbol `:wait_readable` instead.
699
+ #
700
+ # ### See
701
+ # * Socket#accept
702
+ #
703
+ #
704
+ def accept_nonblock: (?exception: boolish) -> ([Socket, Addrinfo] | :wait_readable)
705
+
706
+ # Binds to the given local address.
707
+ #
708
+ # ### Parameter
709
+ # * `local_sockaddr` - the `struct` sockaddr contained in a string or an
710
+ # Addrinfo object
711
+ #
712
+ #
713
+ # ### Example
714
+ # require 'socket'
715
+ #
716
+ # # use Addrinfo
717
+ # socket = Socket.new(:INET, :STREAM, 0)
718
+ # socket.bind(Addrinfo.tcp("127.0.0.1", 2222))
719
+ # p socket.local_address #=> #<Addrinfo: 127.0.0.1:2222 TCP>
720
+ #
721
+ # # use struct sockaddr
722
+ # include Socket::Constants
723
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
724
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
725
+ # socket.bind( sockaddr )
726
+ #
727
+ # ### Unix-based Exceptions
728
+ # On unix-based based systems the following system exceptions may be raised if
729
+ # the call to *bind* fails:
730
+ # * Errno::EACCES - the specified *sockaddr* is protected and the current user
731
+ # does not have permission to bind to it
732
+ # * Errno::EADDRINUSE - the specified *sockaddr* is already in use
733
+ # * Errno::EADDRNOTAVAIL - the specified *sockaddr* is not available from the
734
+ # local machine
735
+ # * Errno::EAFNOSUPPORT - the specified *sockaddr* is not a valid address for
736
+ # the family of the calling `socket`
737
+ # * Errno::EBADF - the *sockaddr* specified is not a valid file descriptor
738
+ # * Errno::EFAULT - the *sockaddr* argument cannot be accessed
739
+ # * Errno::EINVAL - the `socket` is already bound to an address, and the
740
+ # protocol does not support binding to the new *sockaddr* or the `socket`
741
+ # has been shut down.
742
+ # * Errno::EINVAL - the address length is not a valid length for the address
743
+ # family
744
+ # * Errno::ENAMETOOLONG - the pathname resolved had a length which exceeded
745
+ # PATH_MAX
746
+ # * Errno::ENOBUFS - no buffer space is available
747
+ # * Errno::ENOSR - there were insufficient STREAMS resources available to
748
+ # complete the operation
749
+ # * Errno::ENOTSOCK - the `socket` does not refer to a socket
750
+ # * Errno::EOPNOTSUPP - the socket type of the `socket` does not support
751
+ # binding to an address
752
+ #
753
+ #
754
+ # On unix-based based systems if the address family of the calling `socket` is
755
+ # Socket::AF_UNIX the follow exceptions may be raised if the call to *bind*
756
+ # fails:
757
+ # * Errno::EACCES - search permission is denied for a component of the prefix
758
+ # path or write access to the `socket` is denied
759
+ # * Errno::EDESTADDRREQ - the *sockaddr* argument is a null pointer
760
+ # * Errno::EISDIR - same as Errno::EDESTADDRREQ
761
+ # * Errno::EIO - an i/o error occurred
762
+ # * Errno::ELOOP - too many symbolic links were encountered in translating the
763
+ # pathname in *sockaddr*
764
+ # * Errno::ENAMETOOLLONG - a component of a pathname exceeded NAME_MAX
765
+ # characters, or an entire pathname exceeded PATH_MAX characters
766
+ # * Errno::ENOENT - a component of the pathname does not name an existing file
767
+ # or the pathname is an empty string
768
+ # * Errno::ENOTDIR - a component of the path prefix of the pathname in
769
+ # *sockaddr* is not a directory
770
+ # * Errno::EROFS - the name would reside on a read only filesystem
771
+ #
772
+ #
773
+ # ### Windows Exceptions
774
+ # On Windows systems the following system exceptions may be raised if the call
775
+ # to *bind* fails:
776
+ # * Errno::ENETDOWN-- the network is down
777
+ # * Errno::EACCES - the attempt to connect the datagram socket to the
778
+ # broadcast address failed
779
+ # * Errno::EADDRINUSE - the socket's local address is already in use
780
+ # * Errno::EADDRNOTAVAIL - the specified address is not a valid address for
781
+ # this computer
782
+ # * Errno::EFAULT - the socket's internal address or address length parameter
783
+ # is too small or is not a valid part of the user space addressed
784
+ # * Errno::EINVAL - the `socket` is already bound to an address
785
+ # * Errno::ENOBUFS - no buffer space is available
786
+ # * Errno::ENOTSOCK - the `socket` argument does not refer to a socket
787
+ #
788
+ #
789
+ # ### See
790
+ # * bind manual pages on unix-based systems
791
+ # * bind function in Microsoft's Winsock functions reference
792
+ #
793
+ #
794
+ def bind: (String | Addrinfo local_sockaddr) -> void
795
+
796
+ # Requests a connection to be made on the given `remote_sockaddr`. Returns 0 if
797
+ # successful, otherwise an exception is raised.
798
+ #
799
+ # ### Parameter
800
+ # * `remote_sockaddr` - the `struct` sockaddr contained in a string or
801
+ # Addrinfo object
802
+ #
803
+ #
804
+ # ### Example:
805
+ # # Pull down Google's web page
806
+ # require 'socket'
807
+ # include Socket::Constants
808
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
809
+ # sockaddr = Socket.pack_sockaddr_in( 80, 'www.google.com' )
810
+ # socket.connect( sockaddr )
811
+ # socket.write( "GET / HTTP/1.0\r\n\r\n" )
812
+ # results = socket.read
813
+ #
814
+ # ### Unix-based Exceptions
815
+ # On unix-based systems the following system exceptions may be raised if the
816
+ # call to *connect* fails:
817
+ # * Errno::EACCES - search permission is denied for a component of the prefix
818
+ # path or write access to the `socket` is denied
819
+ # * Errno::EADDRINUSE - the *sockaddr* is already in use
820
+ # * Errno::EADDRNOTAVAIL - the specified *sockaddr* is not available from the
821
+ # local machine
822
+ # * Errno::EAFNOSUPPORT - the specified *sockaddr* is not a valid address for
823
+ # the address family of the specified `socket`
824
+ # * Errno::EALREADY - a connection is already in progress for the specified
825
+ # socket
826
+ # * Errno::EBADF - the `socket` is not a valid file descriptor
827
+ # * Errno::ECONNREFUSED - the target *sockaddr* was not listening for
828
+ # connections refused the connection request
829
+ # * Errno::ECONNRESET - the remote host reset the connection request
830
+ # * Errno::EFAULT - the *sockaddr* cannot be accessed
831
+ # * Errno::EHOSTUNREACH - the destination host cannot be reached (probably
832
+ # because the host is down or a remote router cannot reach it)
833
+ # * Errno::EINPROGRESS - the O_NONBLOCK is set for the `socket` and the
834
+ # connection cannot be immediately established; the connection will be
835
+ # established asynchronously
836
+ # * Errno::EINTR - the attempt to establish the connection was interrupted by
837
+ # delivery of a signal that was caught; the connection will be established
838
+ # asynchronously
839
+ # * Errno::EISCONN - the specified `socket` is already connected
840
+ # * Errno::EINVAL - the address length used for the *sockaddr* is not a valid
841
+ # length for the address family or there is an invalid family in *sockaddr*
842
+ # * Errno::ENAMETOOLONG - the pathname resolved had a length which exceeded
843
+ # PATH_MAX
844
+ # * Errno::ENETDOWN - the local interface used to reach the destination is
845
+ # down
846
+ # * Errno::ENETUNREACH - no route to the network is present
847
+ # * Errno::ENOBUFS - no buffer space is available
848
+ # * Errno::ENOSR - there were insufficient STREAMS resources available to
849
+ # complete the operation
850
+ # * Errno::ENOTSOCK - the `socket` argument does not refer to a socket
851
+ # * Errno::EOPNOTSUPP - the calling `socket` is listening and cannot be
852
+ # connected
853
+ # * Errno::EPROTOTYPE - the *sockaddr* has a different type than the socket
854
+ # bound to the specified peer address
855
+ # * Errno::ETIMEDOUT - the attempt to connect time out before a connection was
856
+ # made.
857
+ #
858
+ #
859
+ # On unix-based systems if the address family of the calling `socket` is AF_UNIX
860
+ # the follow exceptions may be raised if the call to *connect* fails:
861
+ # * Errno::EIO - an i/o error occurred while reading from or writing to the
862
+ # file system
863
+ # * Errno::ELOOP - too many symbolic links were encountered in translating the
864
+ # pathname in *sockaddr*
865
+ # * Errno::ENAMETOOLLONG - a component of a pathname exceeded NAME_MAX
866
+ # characters, or an entire pathname exceeded PATH_MAX characters
867
+ # * Errno::ENOENT - a component of the pathname does not name an existing file
868
+ # or the pathname is an empty string
869
+ # * Errno::ENOTDIR - a component of the path prefix of the pathname in
870
+ # *sockaddr* is not a directory
871
+ #
872
+ #
873
+ # ### Windows Exceptions
874
+ # On Windows systems the following system exceptions may be raised if the call
875
+ # to *connect* fails:
876
+ # * Errno::ENETDOWN - the network is down
877
+ # * Errno::EADDRINUSE - the socket's local address is already in use
878
+ # * Errno::EINTR - the socket was cancelled
879
+ # * Errno::EINPROGRESS - a blocking socket is in progress or the service
880
+ # provider is still processing a callback function. Or a nonblocking connect
881
+ # call is in progress on the `socket`.
882
+ # * Errno::EALREADY - see Errno::EINVAL
883
+ # * Errno::EADDRNOTAVAIL - the remote address is not a valid address, such as
884
+ # ADDR_ANY TODO check ADDRANY TO INADDR_ANY
885
+ # * Errno::EAFNOSUPPORT - addresses in the specified family cannot be used
886
+ # with with this `socket`
887
+ # * Errno::ECONNREFUSED - the target *sockaddr* was not listening for
888
+ # connections refused the connection request
889
+ # * Errno::EFAULT - the socket's internal address or address length parameter
890
+ # is too small or is not a valid part of the user space address
891
+ # * Errno::EINVAL - the `socket` is a listening socket
892
+ # * Errno::EISCONN - the `socket` is already connected
893
+ # * Errno::ENETUNREACH - the network cannot be reached from this host at this
894
+ # time
895
+ # * Errno::EHOSTUNREACH - no route to the network is present
896
+ # * Errno::ENOBUFS - no buffer space is available
897
+ # * Errno::ENOTSOCK - the `socket` argument does not refer to a socket
898
+ # * Errno::ETIMEDOUT - the attempt to connect time out before a connection was
899
+ # made.
900
+ # * Errno::EWOULDBLOCK - the socket is marked as nonblocking and the
901
+ # connection cannot be completed immediately
902
+ # * Errno::EACCES - the attempt to connect the datagram socket to the
903
+ # broadcast address failed
904
+ #
905
+ #
906
+ # ### See
907
+ # * connect manual pages on unix-based systems
908
+ # * connect function in Microsoft's Winsock functions reference
909
+ #
910
+ #
911
+ def connect: (String | Addrinfo remote_sockaddr) -> Integer
912
+
913
+ # Requests a connection to be made on the given `remote_sockaddr` after
914
+ # O_NONBLOCK is set for the underlying file descriptor. Returns 0 if successful,
915
+ # otherwise an exception is raised.
916
+ #
917
+ # ### Parameter
918
+ # # +remote_sockaddr+ - the +struct+ sockaddr contained in a string or Addrinfo object
919
+ #
920
+ # ### Example:
921
+ # # Pull down Google's web page
922
+ # require 'socket'
923
+ # include Socket::Constants
924
+ # socket = Socket.new(AF_INET, SOCK_STREAM, 0)
925
+ # sockaddr = Socket.sockaddr_in(80, 'www.google.com')
926
+ # begin # emulate blocking connect
927
+ # socket.connect_nonblock(sockaddr)
928
+ # rescue IO::WaitWritable
929
+ # IO.select(nil, [socket]) # wait 3-way handshake completion
930
+ # begin
931
+ # socket.connect_nonblock(sockaddr) # check connection failure
932
+ # rescue Errno::EISCONN
933
+ # end
934
+ # end
935
+ # socket.write("GET / HTTP/1.0\r\n\r\n")
936
+ # results = socket.read
937
+ #
938
+ # Refer to Socket#connect for the exceptions that may be thrown if the call to
939
+ # *connect_nonblock* fails.
940
+ #
941
+ # Socket#connect_nonblock may raise any error corresponding to connect(2)
942
+ # failure, including Errno::EINPROGRESS.
943
+ #
944
+ # If the exception is Errno::EINPROGRESS, it is extended by IO::WaitWritable. So
945
+ # IO::WaitWritable can be used to rescue the exceptions for retrying
946
+ # connect_nonblock.
947
+ #
948
+ # By specifying a keyword argument *exception* to `false`, you can indicate that
949
+ # connect_nonblock should not raise an IO::WaitWritable exception, but return
950
+ # the symbol `:wait_writable` instead.
951
+ #
952
+ # ### See
953
+ # # Socket#connect
954
+ #
955
+ def connect_nonblock: (untyped addr, ?exception: untyped) -> (Integer | :wait_writable)
956
+
957
+ # enable the socket option IPV6_V6ONLY if IPV6_V6ONLY is available.
958
+ #
959
+ def ipv6only!: () -> void
960
+
961
+ # Listens for connections, using the specified `int` as the backlog. A call to
962
+ # *listen* only applies if the `socket` is of type SOCK_STREAM or
963
+ # SOCK_SEQPACKET.
964
+ #
965
+ # ### Parameter
966
+ # * `backlog` - the maximum length of the queue for pending connections.
967
+ #
968
+ #
969
+ # ### Example 1
970
+ # require 'socket'
971
+ # include Socket::Constants
972
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
973
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
974
+ # socket.bind( sockaddr )
975
+ # socket.listen( 5 )
976
+ #
977
+ # ### Example 2 (listening on an arbitrary port, unix-based systems only):
978
+ # require 'socket'
979
+ # include Socket::Constants
980
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
981
+ # socket.listen( 1 )
982
+ #
983
+ # ### Unix-based Exceptions
984
+ # On unix based systems the above will work because a new `sockaddr` struct is
985
+ # created on the address ADDR_ANY, for an arbitrary port number as handed off by
986
+ # the kernel. It will not work on Windows, because Windows requires that the
987
+ # `socket` is bound by calling *bind* before it can *listen*.
988
+ #
989
+ # If the *backlog* amount exceeds the implementation-dependent maximum queue
990
+ # length, the implementation's maximum queue length will be used.
991
+ #
992
+ # On unix-based based systems the following system exceptions may be raised if
993
+ # the call to *listen* fails:
994
+ # * Errno::EBADF - the *socket* argument is not a valid file descriptor
995
+ # * Errno::EDESTADDRREQ - the *socket* is not bound to a local address, and
996
+ # the protocol does not support listening on an unbound socket
997
+ # * Errno::EINVAL - the *socket* is already connected
998
+ # * Errno::ENOTSOCK - the *socket* argument does not refer to a socket
999
+ # * Errno::EOPNOTSUPP - the *socket* protocol does not support listen
1000
+ # * Errno::EACCES - the calling process does not have appropriate privileges
1001
+ # * Errno::EINVAL - the *socket* has been shut down
1002
+ # * Errno::ENOBUFS - insufficient resources are available in the system to
1003
+ # complete the call
1004
+ #
1005
+ #
1006
+ # ### Windows Exceptions
1007
+ # On Windows systems the following system exceptions may be raised if the call
1008
+ # to *listen* fails:
1009
+ # * Errno::ENETDOWN - the network is down
1010
+ # * Errno::EADDRINUSE - the socket's local address is already in use. This
1011
+ # usually occurs during the execution of *bind* but could be delayed if the
1012
+ # call to *bind* was to a partially wildcard address (involving ADDR_ANY)
1013
+ # and if a specific address needs to be committed at the time of the call to
1014
+ # *listen*
1015
+ # * Errno::EINPROGRESS - a Windows Sockets 1.1 call is in progress or the
1016
+ # service provider is still processing a callback function
1017
+ # * Errno::EINVAL - the `socket` has not been bound with a call to *bind*.
1018
+ # * Errno::EISCONN - the `socket` is already connected
1019
+ # * Errno::EMFILE - no more socket descriptors are available
1020
+ # * Errno::ENOBUFS - no buffer space is available
1021
+ # * Errno::ENOTSOC - `socket` is not a socket
1022
+ # * Errno::EOPNOTSUPP - the referenced `socket` is not a type that supports
1023
+ # the *listen* method
1024
+ #
1025
+ #
1026
+ # ### See
1027
+ # * listen manual pages on unix-based systems
1028
+ # * listen function in Microsoft's Winsock functions reference
1029
+ #
1030
+ #
1031
+ def listen: (Integer backlog_len) -> void
1032
+
1033
+ # Receives up to *maxlen* bytes from `socket`. *flags* is zero or more of the
1034
+ # `MSG_` options. The first element of the results, *mesg*, is the data
1035
+ # received. The second element, *sender_addrinfo*, contains protocol-specific
1036
+ # address information of the sender.
1037
+ #
1038
+ # ### Parameters
1039
+ # * `maxlen` - the maximum number of bytes to receive from the socket
1040
+ # * `flags` - zero or more of the `MSG_` options
1041
+ #
1042
+ #
1043
+ # ### Example
1044
+ # # In one file, start this first
1045
+ # require 'socket'
1046
+ # include Socket::Constants
1047
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
1048
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
1049
+ # socket.bind( sockaddr )
1050
+ # socket.listen( 5 )
1051
+ # client, client_addrinfo = socket.accept
1052
+ # data = client.recvfrom( 20 )[0].chomp
1053
+ # puts "I only received 20 bytes '#{data}'"
1054
+ # sleep 1
1055
+ # socket.close
1056
+ #
1057
+ # # In another file, start this second
1058
+ # require 'socket'
1059
+ # include Socket::Constants
1060
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
1061
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
1062
+ # socket.connect( sockaddr )
1063
+ # socket.puts "Watch this get cut short!"
1064
+ # socket.close
1065
+ #
1066
+ # ### Unix-based Exceptions
1067
+ # On unix-based based systems the following system exceptions may be raised if
1068
+ # the call to *recvfrom* fails:
1069
+ # * Errno::EAGAIN - the `socket` file descriptor is marked as O_NONBLOCK and
1070
+ # no data is waiting to be received; or MSG_OOB is set and no out-of-band
1071
+ # data is available and either the `socket` file descriptor is marked as
1072
+ # O_NONBLOCK or the `socket` does not support blocking to wait for
1073
+ # out-of-band-data
1074
+ # * Errno::EWOULDBLOCK - see Errno::EAGAIN
1075
+ # * Errno::EBADF - the `socket` is not a valid file descriptor
1076
+ # * Errno::ECONNRESET - a connection was forcibly closed by a peer
1077
+ # * Errno::EFAULT - the socket's internal buffer, address or address length
1078
+ # cannot be accessed or written
1079
+ # * Errno::EINTR - a signal interrupted *recvfrom* before any data was
1080
+ # available
1081
+ # * Errno::EINVAL - the MSG_OOB flag is set and no out-of-band data is
1082
+ # available
1083
+ # * Errno::EIO - an i/o error occurred while reading from or writing to the
1084
+ # filesystem
1085
+ # * Errno::ENOBUFS - insufficient resources were available in the system to
1086
+ # perform the operation
1087
+ # * Errno::ENOMEM - insufficient memory was available to fulfill the request
1088
+ # * Errno::ENOSR - there were insufficient STREAMS resources available to
1089
+ # complete the operation
1090
+ # * Errno::ENOTCONN - a receive is attempted on a connection-mode socket that
1091
+ # is not connected
1092
+ # * Errno::ENOTSOCK - the `socket` does not refer to a socket
1093
+ # * Errno::EOPNOTSUPP - the specified flags are not supported for this socket
1094
+ # type
1095
+ # * Errno::ETIMEDOUT - the connection timed out during connection
1096
+ # establishment or due to a transmission timeout on an active connection
1097
+ #
1098
+ #
1099
+ # ### Windows Exceptions
1100
+ # On Windows systems the following system exceptions may be raised if the call
1101
+ # to *recvfrom* fails:
1102
+ # * Errno::ENETDOWN - the network is down
1103
+ # * Errno::EFAULT - the internal buffer and from parameters on `socket` are
1104
+ # not part of the user address space, or the internal fromlen parameter is
1105
+ # too small to accommodate the peer address
1106
+ # * Errno::EINTR - the (blocking) call was cancelled by an internal call to
1107
+ # the WinSock function WSACancelBlockingCall
1108
+ # * Errno::EINPROGRESS - a blocking Windows Sockets 1.1 call is in progress or
1109
+ # the service provider is still processing a callback function
1110
+ # * Errno::EINVAL - `socket` has not been bound with a call to *bind*, or an
1111
+ # unknown flag was specified, or MSG_OOB was specified for a socket with
1112
+ # SO_OOBINLINE enabled, or (for byte stream-style sockets only) the internal
1113
+ # len parameter on `socket` was zero or negative
1114
+ # * Errno::EISCONN - `socket` is already connected. The call to *recvfrom* is
1115
+ # not permitted with a connected socket on a socket that is connection
1116
+ # oriented or connectionless.
1117
+ # * Errno::ENETRESET - the connection has been broken due to the keep-alive
1118
+ # activity detecting a failure while the operation was in progress.
1119
+ # * Errno::EOPNOTSUPP - MSG_OOB was specified, but `socket` is not
1120
+ # stream-style such as type SOCK_STREAM. OOB data is not supported in the
1121
+ # communication domain associated with `socket`, or `socket` is
1122
+ # unidirectional and supports only send operations
1123
+ # * Errno::ESHUTDOWN - `socket` has been shutdown. It is not possible to call
1124
+ # *recvfrom* on a socket after *shutdown* has been invoked.
1125
+ # * Errno::EWOULDBLOCK - `socket` is marked as nonblocking and a call to
1126
+ # *recvfrom* would block.
1127
+ # * Errno::EMSGSIZE - the message was too large to fit into the specified
1128
+ # buffer and was truncated.
1129
+ # * Errno::ETIMEDOUT - the connection has been dropped, because of a network
1130
+ # failure or because the system on the other end went down without notice
1131
+ # * Errno::ECONNRESET - the virtual circuit was reset by the remote side
1132
+ # executing a hard or abortive close. The application should close the
1133
+ # socket; it is no longer usable. On a UDP-datagram socket this error
1134
+ # indicates a previous send operation resulted in an ICMP Port Unreachable
1135
+ # message.
1136
+ #
1137
+ #
1138
+ #
1139
+ def recvfrom: (Integer maxlen, ?Integer flags) -> [String, Addrinfo]
1140
+
1141
+ # Receives up to *maxlen* bytes from `socket` using recvfrom(2) after O_NONBLOCK
1142
+ # is set for the underlying file descriptor. *flags* is zero or more of the
1143
+ # `MSG_` options. The first element of the results, *mesg*, is the data
1144
+ # received. The second element, *sender_addrinfo*, contains protocol-specific
1145
+ # address information of the sender.
1146
+ #
1147
+ # When recvfrom(2) returns 0, Socket#recvfrom_nonblock returns an empty string
1148
+ # as data. The meaning depends on the socket: EOF on TCP, empty packet on UDP,
1149
+ # etc.
1150
+ #
1151
+ # ### Parameters
1152
+ # * `maxlen` - the maximum number of bytes to receive from the socket
1153
+ # * `flags` - zero or more of the `MSG_` options
1154
+ # * `outbuf` - destination String buffer
1155
+ # * `opts` - keyword hash, supporting `exception: false`
1156
+ #
1157
+ #
1158
+ # ### Example
1159
+ # # In one file, start this first
1160
+ # require 'socket'
1161
+ # include Socket::Constants
1162
+ # socket = Socket.new(AF_INET, SOCK_STREAM, 0)
1163
+ # sockaddr = Socket.sockaddr_in(2200, 'localhost')
1164
+ # socket.bind(sockaddr)
1165
+ # socket.listen(5)
1166
+ # client, client_addrinfo = socket.accept
1167
+ # begin # emulate blocking recvfrom
1168
+ # pair = client.recvfrom_nonblock(20)
1169
+ # rescue IO::WaitReadable
1170
+ # IO.select([client])
1171
+ # retry
1172
+ # end
1173
+ # data = pair[0].chomp
1174
+ # puts "I only received 20 bytes '#{data}'"
1175
+ # sleep 1
1176
+ # socket.close
1177
+ #
1178
+ # # In another file, start this second
1179
+ # require 'socket'
1180
+ # include Socket::Constants
1181
+ # socket = Socket.new(AF_INET, SOCK_STREAM, 0)
1182
+ # sockaddr = Socket.sockaddr_in(2200, 'localhost')
1183
+ # socket.connect(sockaddr)
1184
+ # socket.puts "Watch this get cut short!"
1185
+ # socket.close
1186
+ #
1187
+ # Refer to Socket#recvfrom for the exceptions that may be thrown if the call to
1188
+ # *recvfrom_nonblock* fails.
1189
+ #
1190
+ # Socket#recvfrom_nonblock may raise any error corresponding to recvfrom(2)
1191
+ # failure, including Errno::EWOULDBLOCK.
1192
+ #
1193
+ # If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by
1194
+ # IO::WaitReadable. So IO::WaitReadable can be used to rescue the exceptions for
1195
+ # retrying recvfrom_nonblock.
1196
+ #
1197
+ # By specifying a keyword argument *exception* to `false`, you can indicate that
1198
+ # recvfrom_nonblock should not raise an IO::WaitReadable exception, but return
1199
+ # the symbol `:wait_readable` instead.
1200
+ #
1201
+ # ### See
1202
+ # * Socket#recvfrom
1203
+ #
1204
+ #
1205
+ def recvfrom_nonblock: (Integer maxlen, ?Integer flags, ?untyped outbuf, ?exception: boolish) -> ([String, Addrinfo] | :wait_readable)
1206
+
1207
+ # Accepts an incoming connection returning an array containing the (integer)
1208
+ # file descriptor for the incoming connection, *client_socket_fd*, and an
1209
+ # Addrinfo, *client_addrinfo*.
1210
+ #
1211
+ # ### Example
1212
+ # # In one script, start this first
1213
+ # require 'socket'
1214
+ # include Socket::Constants
1215
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
1216
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
1217
+ # socket.bind( sockaddr )
1218
+ # socket.listen( 5 )
1219
+ # client_fd, client_addrinfo = socket.sysaccept
1220
+ # client_socket = Socket.for_fd( client_fd )
1221
+ # puts "The client said, '#{client_socket.readline.chomp}'"
1222
+ # client_socket.puts "Hello from script one!"
1223
+ # socket.close
1224
+ #
1225
+ # # In another script, start this second
1226
+ # require 'socket'
1227
+ # include Socket::Constants
1228
+ # socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
1229
+ # sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
1230
+ # socket.connect( sockaddr )
1231
+ # socket.puts "Hello from script 2."
1232
+ # puts "The server said, '#{socket.readline.chomp}'"
1233
+ # socket.close
1234
+ #
1235
+ # Refer to Socket#accept for the exceptions that may be thrown if the call to
1236
+ # *sysaccept* fails.
1237
+ #
1238
+ # ### See
1239
+ # * Socket#accept
1240
+ #
1241
+ #
1242
+ def sysaccept: () -> [Integer, Addrinfo]
1243
+
1244
+ private
1245
+
1246
+ def __accept_nonblock: (untyped) -> untyped
1247
+
1248
+ def __connect_nonblock: (untyped, untyped) -> untyped
1249
+
1250
+ def __recvfrom_nonblock: (untyped, untyped, untyped, untyped) -> untyped
1251
+
1252
+ # Creates a new socket object.
1253
+ #
1254
+ # *domain* should be a communications domain such as: :INET, :INET6, :UNIX, etc.
1255
+ #
1256
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
1257
+ #
1258
+ # *protocol* is optional and should be a protocol defined in the domain. If
1259
+ # protocol is not given, 0 is used internally.
1260
+ #
1261
+ # Socket.new(:INET, :STREAM) # TCP socket
1262
+ # Socket.new(:INET, :DGRAM) # UDP socket
1263
+ # Socket.new(:UNIX, :STREAM) # UNIX stream socket
1264
+ # Socket.new(:UNIX, :DGRAM) # UNIX datagram socket
1265
+ #
1266
+ def initialize: (Symbol domain, Symbol socktype, ?Integer protocol) -> untyped
1267
+ end
1268
+
1269
+ # AppleTalk protocol
1270
+ #
1271
+ Socket::AF_APPLETALK: Integer
1272
+
1273
+ # CCITT (now ITU-T) protocols
1274
+ #
1275
+ Socket::AF_CCITT: Integer
1276
+
1277
+ # MIT CHAOS protocols
1278
+ #
1279
+ Socket::AF_CHAOS: Integer
1280
+
1281
+ # Computer Network Technology
1282
+ #
1283
+ Socket::AF_CNT: Integer
1284
+
1285
+ # Connection-oriented IP
1286
+ #
1287
+ Socket::AF_COIP: Integer
1288
+
1289
+ # Datakit protocol
1290
+ #
1291
+ Socket::AF_DATAKIT: Integer
1292
+
1293
+ # DEC Direct Data Link Interface protocol
1294
+ #
1295
+ Socket::AF_DLI: Integer
1296
+
1297
+ # CCITT (ITU-T) E.164 recommendation
1298
+ #
1299
+ Socket::AF_E164: Integer
1300
+
1301
+ # European Computer Manufacturers protocols
1302
+ #
1303
+ Socket::AF_ECMA: Integer
1304
+
1305
+ # NSC Hyperchannel protocol
1306
+ #
1307
+ Socket::AF_HYLINK: Integer
1308
+
1309
+ # ARPANET IMP protocol
1310
+ #
1311
+ Socket::AF_IMPLINK: Integer
1312
+
1313
+ # IPv4 protocol
1314
+ #
1315
+ Socket::AF_INET: Integer
1316
+
1317
+ # IPv6 protocol
1318
+ #
1319
+ Socket::AF_INET6: Integer
1320
+
1321
+ # IPX protocol
1322
+ #
1323
+ Socket::AF_IPX: Integer
1324
+
1325
+ # Integrated Services Digital Network
1326
+ #
1327
+ Socket::AF_ISDN: Integer
1328
+
1329
+ # ISO Open Systems Interconnection protocols
1330
+ #
1331
+ Socket::AF_ISO: Integer
1332
+
1333
+ # Local Area Transport protocol
1334
+ #
1335
+ Socket::AF_LAT: Integer
1336
+
1337
+ # Link layer interface
1338
+ #
1339
+ Socket::AF_LINK: Integer
1340
+
1341
+ # Host-internal protocols
1342
+ #
1343
+ Socket::AF_LOCAL: Integer
1344
+
1345
+ # Maximum address family for this platform
1346
+ #
1347
+ Socket::AF_MAX: Integer
1348
+
1349
+ # Native ATM access
1350
+ #
1351
+ Socket::AF_NATM: Integer
1352
+
1353
+ # Network driver raw access
1354
+ #
1355
+ Socket::AF_NDRV: Integer
1356
+
1357
+ # NetBIOS
1358
+ #
1359
+ Socket::AF_NETBIOS: Integer
1360
+
1361
+ # XEROX NS protocols
1362
+ #
1363
+ Socket::AF_NS: Integer
1364
+
1365
+ # ISO Open Systems Interconnection protocols
1366
+ #
1367
+ Socket::AF_OSI: Integer
1368
+
1369
+ # Point-to-Point Protocol
1370
+ #
1371
+ Socket::AF_PPP: Integer
1372
+
1373
+ # PARC Universal Packet protocol
1374
+ #
1375
+ Socket::AF_PUP: Integer
1376
+
1377
+ # Internal routing protocol
1378
+ #
1379
+ Socket::AF_ROUTE: Integer
1380
+
1381
+ # Simple Internet Protocol
1382
+ #
1383
+ Socket::AF_SIP: Integer
1384
+
1385
+ # IBM SNA protocol
1386
+ #
1387
+ Socket::AF_SNA: Integer
1388
+
1389
+ Socket::AF_SYSTEM: Integer
1390
+
1391
+ # UNIX sockets
1392
+ #
1393
+ Socket::AF_UNIX: Integer
1394
+
1395
+ # Unspecified protocol, any supported address family
1396
+ #
1397
+ Socket::AF_UNSPEC: Integer
1398
+
1399
+ # Accept only if any address is assigned
1400
+ #
1401
+ Socket::AI_ADDRCONFIG: Integer
1402
+
1403
+ # Allow all addresses
1404
+ #
1405
+ Socket::AI_ALL: Integer
1406
+
1407
+ # Fill in the canonical name
1408
+ #
1409
+ Socket::AI_CANONNAME: Integer
1410
+
1411
+ # Default flags for getaddrinfo
1412
+ #
1413
+ Socket::AI_DEFAULT: Integer
1414
+
1415
+ # Valid flag mask for getaddrinfo (not for application use)
1416
+ #
1417
+ Socket::AI_MASK: Integer
1418
+
1419
+ # Prevent host name resolution
1420
+ #
1421
+ Socket::AI_NUMERICHOST: Integer
1422
+
1423
+ # Prevent service name resolution
1424
+ #
1425
+ Socket::AI_NUMERICSERV: Integer
1426
+
1427
+ # Get address to use with bind()
1428
+ #
1429
+ Socket::AI_PASSIVE: Integer
1430
+
1431
+ # Accept IPv4-mapped IPv6 addresses
1432
+ #
1433
+ Socket::AI_V4MAPPED: Integer
1434
+
1435
+ # Accept IPv4 mapped addresses if the kernel supports it
1436
+ #
1437
+ Socket::AI_V4MAPPED_CFG: Integer
1438
+
1439
+ # Address family for hostname not supported
1440
+ #
1441
+ Socket::EAI_ADDRFAMILY: Integer
1442
+
1443
+ # Temporary failure in name resolution
1444
+ #
1445
+ Socket::EAI_AGAIN: Integer
1446
+
1447
+ # Invalid flags
1448
+ #
1449
+ Socket::EAI_BADFLAGS: Integer
1450
+
1451
+ # Invalid value for hints
1452
+ #
1453
+ Socket::EAI_BADHINTS: Integer
1454
+
1455
+ # Non-recoverable failure in name resolution
1456
+ #
1457
+ Socket::EAI_FAIL: Integer
1458
+
1459
+ # Address family not supported
1460
+ #
1461
+ Socket::EAI_FAMILY: Integer
1462
+
1463
+ # Maximum error code from getaddrinfo
1464
+ #
1465
+ Socket::EAI_MAX: Integer
1466
+
1467
+ # Memory allocation failure
1468
+ #
1469
+ Socket::EAI_MEMORY: Integer
1470
+
1471
+ # No address associated with hostname
1472
+ #
1473
+ Socket::EAI_NODATA: Integer
1474
+
1475
+ # Hostname nor servname, or not known
1476
+ #
1477
+ Socket::EAI_NONAME: Integer
1478
+
1479
+ # Argument buffer overflow
1480
+ #
1481
+ Socket::EAI_OVERFLOW: Integer
1482
+
1483
+ # Resolved protocol is unknown
1484
+ #
1485
+ Socket::EAI_PROTOCOL: Integer
1486
+
1487
+ # Servname not supported for socket type
1488
+ #
1489
+ Socket::EAI_SERVICE: Integer
1490
+
1491
+ # Socket type not supported
1492
+ #
1493
+ Socket::EAI_SOCKTYPE: Integer
1494
+
1495
+ # System error returned in errno
1496
+ #
1497
+ Socket::EAI_SYSTEM: Integer
1498
+
1499
+ # receive all multicast packets
1500
+ #
1501
+ Socket::IFF_ALLMULTI: Integer
1502
+
1503
+ # use alternate physical connection
1504
+ #
1505
+ Socket::IFF_ALTPHYS: Integer
1506
+
1507
+ # broadcast address valid
1508
+ #
1509
+ Socket::IFF_BROADCAST: Integer
1510
+
1511
+ # turn on debugging
1512
+ #
1513
+ Socket::IFF_DEBUG: Integer
1514
+
1515
+ # per link layer defined bit 0
1516
+ #
1517
+ Socket::IFF_LINK0: Integer
1518
+
1519
+ # per link layer defined bit 1
1520
+ #
1521
+ Socket::IFF_LINK1: Integer
1522
+
1523
+ # per link layer defined bit 2
1524
+ #
1525
+ Socket::IFF_LINK2: Integer
1526
+
1527
+ # loopback net
1528
+ #
1529
+ Socket::IFF_LOOPBACK: Integer
1530
+
1531
+ # supports multicast
1532
+ #
1533
+ Socket::IFF_MULTICAST: Integer
1534
+
1535
+ # no address resolution protocol
1536
+ #
1537
+ Socket::IFF_NOARP: Integer
1538
+
1539
+ # avoid use of trailers
1540
+ #
1541
+ Socket::IFF_NOTRAILERS: Integer
1542
+
1543
+ # transmission in progress
1544
+ #
1545
+ Socket::IFF_OACTIVE: Integer
1546
+
1547
+ # point-to-point link
1548
+ #
1549
+ Socket::IFF_POINTOPOINT: Integer
1550
+
1551
+ # receive all packets
1552
+ #
1553
+ Socket::IFF_PROMISC: Integer
1554
+
1555
+ # resources allocated
1556
+ #
1557
+ Socket::IFF_RUNNING: Integer
1558
+
1559
+ # can't hear own transmissions
1560
+ #
1561
+ Socket::IFF_SIMPLEX: Integer
1562
+
1563
+ # interface is up
1564
+ #
1565
+ Socket::IFF_UP: Integer
1566
+
1567
+ # Maximum interface name size
1568
+ #
1569
+ Socket::IFNAMSIZ: Integer
1570
+
1571
+ # Maximum interface name size
1572
+ #
1573
+ Socket::IF_NAMESIZE: Integer
1574
+
1575
+ # Multicast group for all systems on this subset
1576
+ #
1577
+ Socket::INADDR_ALLHOSTS_GROUP: Integer
1578
+
1579
+ # A socket bound to INADDR_ANY receives packets from all interfaces and sends
1580
+ # from the default IP address
1581
+ #
1582
+ Socket::INADDR_ANY: Integer
1583
+
1584
+ # The network broadcast address
1585
+ #
1586
+ Socket::INADDR_BROADCAST: Integer
1587
+
1588
+ # The loopback address
1589
+ #
1590
+ Socket::INADDR_LOOPBACK: Integer
1591
+
1592
+ # The last local network multicast group
1593
+ #
1594
+ Socket::INADDR_MAX_LOCAL_GROUP: Integer
1595
+
1596
+ # A bitmask for matching no valid IP address
1597
+ #
1598
+ Socket::INADDR_NONE: Integer
1599
+
1600
+ # The reserved multicast group
1601
+ #
1602
+ Socket::INADDR_UNSPEC_GROUP: Integer
1603
+
1604
+ # Maximum length of an IPv6 address string
1605
+ #
1606
+ Socket::INET6_ADDRSTRLEN: Integer
1607
+
1608
+ # Maximum length of an IPv4 address string
1609
+ #
1610
+ Socket::INET_ADDRSTRLEN: Integer
1611
+
1612
+ # Default minimum address for bind or connect
1613
+ #
1614
+ Socket::IPPORT_RESERVED: Integer
1615
+
1616
+ # Default maximum address for bind or connect
1617
+ #
1618
+ Socket::IPPORT_USERRESERVED: Integer
1619
+
1620
+ # IP6 auth header
1621
+ #
1622
+ Socket::IPPROTO_AH: Integer
1623
+
1624
+ # IP6 destination option
1625
+ #
1626
+ Socket::IPPROTO_DSTOPTS: Integer
1627
+
1628
+ # Exterior Gateway Protocol
1629
+ #
1630
+ Socket::IPPROTO_EGP: Integer
1631
+
1632
+ # ISO cnlp
1633
+ #
1634
+ Socket::IPPROTO_EON: Integer
1635
+
1636
+ # IP6 Encapsulated Security Payload
1637
+ #
1638
+ Socket::IPPROTO_ESP: Integer
1639
+
1640
+ # IP6 fragmentation header
1641
+ #
1642
+ Socket::IPPROTO_FRAGMENT: Integer
1643
+
1644
+ # Gateway to Gateway Protocol
1645
+ #
1646
+ Socket::IPPROTO_GGP: Integer
1647
+
1648
+ # "hello" routing protocol
1649
+ #
1650
+ Socket::IPPROTO_HELLO: Integer
1651
+
1652
+ # IP6 hop-by-hop options
1653
+ #
1654
+ Socket::IPPROTO_HOPOPTS: Integer
1655
+
1656
+ # Control message protocol
1657
+ #
1658
+ Socket::IPPROTO_ICMP: Integer
1659
+
1660
+ # ICMP6
1661
+ #
1662
+ Socket::IPPROTO_ICMPV6: Integer
1663
+
1664
+ # XNS IDP
1665
+ #
1666
+ Socket::IPPROTO_IDP: Integer
1667
+
1668
+ # Group Management Protocol
1669
+ #
1670
+ Socket::IPPROTO_IGMP: Integer
1671
+
1672
+ # Dummy protocol for IP
1673
+ #
1674
+ Socket::IPPROTO_IP: Integer
1675
+
1676
+ # IP6 header
1677
+ #
1678
+ Socket::IPPROTO_IPV6: Integer
1679
+
1680
+ # Maximum IPPROTO constant
1681
+ #
1682
+ Socket::IPPROTO_MAX: Integer
1683
+
1684
+ # Sun net disk protocol
1685
+ #
1686
+ Socket::IPPROTO_ND: Integer
1687
+
1688
+ # IP6 no next header
1689
+ #
1690
+ Socket::IPPROTO_NONE: Integer
1691
+
1692
+ # PARC Universal Packet protocol
1693
+ #
1694
+ Socket::IPPROTO_PUP: Integer
1695
+
1696
+ # Raw IP packet
1697
+ #
1698
+ Socket::IPPROTO_RAW: Integer
1699
+
1700
+ # IP6 routing header
1701
+ #
1702
+ Socket::IPPROTO_ROUTING: Integer
1703
+
1704
+ # TCP
1705
+ #
1706
+ Socket::IPPROTO_TCP: Integer
1707
+
1708
+ # ISO transport protocol class 4
1709
+ #
1710
+ Socket::IPPROTO_TP: Integer
1711
+
1712
+ # UDP
1713
+ #
1714
+ Socket::IPPROTO_UDP: Integer
1715
+
1716
+ # Xpress Transport Protocol
1717
+ #
1718
+ Socket::IPPROTO_XTP: Integer
1719
+
1720
+ # Checksum offset for raw sockets
1721
+ #
1722
+ Socket::IPV6_CHECKSUM: Integer
1723
+
1724
+ # Don't fragment packets
1725
+ #
1726
+ Socket::IPV6_DONTFRAG: Integer
1727
+
1728
+ # Destination option
1729
+ #
1730
+ Socket::IPV6_DSTOPTS: Integer
1731
+
1732
+ # Hop limit
1733
+ #
1734
+ Socket::IPV6_HOPLIMIT: Integer
1735
+
1736
+ # Hop-by-hop option
1737
+ #
1738
+ Socket::IPV6_HOPOPTS: Integer
1739
+
1740
+ # Join a group membership
1741
+ #
1742
+ Socket::IPV6_JOIN_GROUP: Integer
1743
+
1744
+ # Leave a group membership
1745
+ #
1746
+ Socket::IPV6_LEAVE_GROUP: Integer
1747
+
1748
+ # IP6 multicast hops
1749
+ #
1750
+ Socket::IPV6_MULTICAST_HOPS: Integer
1751
+
1752
+ # IP6 multicast interface
1753
+ #
1754
+ Socket::IPV6_MULTICAST_IF: Integer
1755
+
1756
+ # IP6 multicast loopback
1757
+ #
1758
+ Socket::IPV6_MULTICAST_LOOP: Integer
1759
+
1760
+ # Next hop address
1761
+ #
1762
+ Socket::IPV6_NEXTHOP: Integer
1763
+
1764
+ # Retrieve current path MTU
1765
+ #
1766
+ Socket::IPV6_PATHMTU: Integer
1767
+
1768
+ # Receive packet information with datagram
1769
+ #
1770
+ Socket::IPV6_PKTINFO: Integer
1771
+
1772
+ # Receive all IP6 options for response
1773
+ #
1774
+ Socket::IPV6_RECVDSTOPTS: Integer
1775
+
1776
+ # Receive hop limit with datagram
1777
+ #
1778
+ Socket::IPV6_RECVHOPLIMIT: Integer
1779
+
1780
+ # Receive hop-by-hop options
1781
+ #
1782
+ Socket::IPV6_RECVHOPOPTS: Integer
1783
+
1784
+ # Receive current path MTU with datagram
1785
+ #
1786
+ Socket::IPV6_RECVPATHMTU: Integer
1787
+
1788
+ # Receive destination IP address and incoming interface
1789
+ #
1790
+ Socket::IPV6_RECVPKTINFO: Integer
1791
+
1792
+ # Receive routing header
1793
+ #
1794
+ Socket::IPV6_RECVRTHDR: Integer
1795
+
1796
+ # Receive traffic class
1797
+ #
1798
+ Socket::IPV6_RECVTCLASS: Integer
1799
+
1800
+ # Allows removal of sticky routing headers
1801
+ #
1802
+ Socket::IPV6_RTHDR: Integer
1803
+
1804
+ # Allows removal of sticky destination options header
1805
+ #
1806
+ Socket::IPV6_RTHDRDSTOPTS: Integer
1807
+
1808
+ # Routing header type 0
1809
+ #
1810
+ Socket::IPV6_RTHDR_TYPE_0: Integer
1811
+
1812
+ # Specify the traffic class
1813
+ #
1814
+ Socket::IPV6_TCLASS: Integer
1815
+
1816
+ # IP6 unicast hops
1817
+ #
1818
+ Socket::IPV6_UNICAST_HOPS: Integer
1819
+
1820
+ # Use the minimum MTU size
1821
+ #
1822
+ Socket::IPV6_USE_MIN_MTU: Integer
1823
+
1824
+ # Only bind IPv6 with a wildcard bind
1825
+ #
1826
+ Socket::IPV6_V6ONLY: Integer
1827
+
1828
+ # Add a multicast group membership
1829
+ #
1830
+ Socket::IP_ADD_MEMBERSHIP: Integer
1831
+
1832
+ # Add a multicast group membership
1833
+ #
1834
+ Socket::IP_ADD_SOURCE_MEMBERSHIP: Integer
1835
+
1836
+ # Block IPv4 multicast packets with a give source address
1837
+ #
1838
+ Socket::IP_BLOCK_SOURCE: Integer
1839
+
1840
+ # Default multicast loopback
1841
+ #
1842
+ Socket::IP_DEFAULT_MULTICAST_LOOP: Integer
1843
+
1844
+ # Default multicast TTL
1845
+ #
1846
+ Socket::IP_DEFAULT_MULTICAST_TTL: Integer
1847
+
1848
+ # Drop a multicast group membership
1849
+ #
1850
+ Socket::IP_DROP_MEMBERSHIP: Integer
1851
+
1852
+ # Drop a multicast group membership
1853
+ #
1854
+ Socket::IP_DROP_SOURCE_MEMBERSHIP: Integer
1855
+
1856
+ # Header is included with data
1857
+ #
1858
+ Socket::IP_HDRINCL: Integer
1859
+
1860
+ # IPsec security policy
1861
+ #
1862
+ Socket::IP_IPSEC_POLICY: Integer
1863
+
1864
+ # Maximum number multicast groups a socket can join
1865
+ #
1866
+ Socket::IP_MAX_MEMBERSHIPS: Integer
1867
+
1868
+ # Multicast source filtering
1869
+ #
1870
+ Socket::IP_MSFILTER: Integer
1871
+
1872
+ # IP multicast interface
1873
+ #
1874
+ Socket::IP_MULTICAST_IF: Integer
1875
+
1876
+ # IP multicast loopback
1877
+ #
1878
+ Socket::IP_MULTICAST_LOOP: Integer
1879
+
1880
+ # IP multicast TTL
1881
+ #
1882
+ Socket::IP_MULTICAST_TTL: Integer
1883
+
1884
+ # IP options to be included in packets
1885
+ #
1886
+ Socket::IP_OPTIONS: Integer
1887
+
1888
+ # Receive packet information with datagrams
1889
+ #
1890
+ Socket::IP_PKTINFO: Integer
1891
+
1892
+ # Set the port range for sockets with unspecified port numbers
1893
+ #
1894
+ Socket::IP_PORTRANGE: Integer
1895
+
1896
+ # Receive IP destination address with datagram
1897
+ #
1898
+ Socket::IP_RECVDSTADDR: Integer
1899
+
1900
+ # Receive interface information with datagrams
1901
+ #
1902
+ Socket::IP_RECVIF: Integer
1903
+
1904
+ # Receive all IP options with datagram
1905
+ #
1906
+ Socket::IP_RECVOPTS: Integer
1907
+
1908
+ # Receive all IP options for response
1909
+ #
1910
+ Socket::IP_RECVRETOPTS: Integer
1911
+
1912
+ # Receive TOS with incoming packets
1913
+ #
1914
+ Socket::IP_RECVTOS: Integer
1915
+
1916
+ # Receive IP TTL with datagrams
1917
+ #
1918
+ Socket::IP_RECVTTL: Integer
1919
+
1920
+ # IP options to be included in datagrams
1921
+ #
1922
+ Socket::IP_RETOPTS: Integer
1923
+
1924
+ # IP type-of-service
1925
+ #
1926
+ Socket::IP_TOS: Integer
1927
+
1928
+ # IP time-to-live
1929
+ #
1930
+ Socket::IP_TTL: Integer
1931
+
1932
+ # Unblock IPv4 multicast packets with a give source address
1933
+ #
1934
+ Socket::IP_UNBLOCK_SOURCE: Integer
1935
+
1936
+ # Retrieve peer credentials
1937
+ #
1938
+ Socket::LOCAL_PEERCRED: Integer
1939
+
1940
+ # Block multicast packets from this source
1941
+ #
1942
+ Socket::MCAST_BLOCK_SOURCE: Integer
1943
+
1944
+ # Exclusive multicast source filter
1945
+ #
1946
+ Socket::MCAST_EXCLUDE: Integer
1947
+
1948
+ # Inclusive multicast source filter
1949
+ #
1950
+ Socket::MCAST_INCLUDE: Integer
1951
+
1952
+ # Join a multicast group
1953
+ #
1954
+ Socket::MCAST_JOIN_GROUP: Integer
1955
+
1956
+ # Join a multicast source group
1957
+ #
1958
+ Socket::MCAST_JOIN_SOURCE_GROUP: Integer
1959
+
1960
+ # Leave a multicast group
1961
+ #
1962
+ Socket::MCAST_LEAVE_GROUP: Integer
1963
+
1964
+ # Leave a multicast source group
1965
+ #
1966
+ Socket::MCAST_LEAVE_SOURCE_GROUP: Integer
1967
+
1968
+ # Unblock multicast packets from this source
1969
+ #
1970
+ Socket::MCAST_UNBLOCK_SOURCE: Integer
1971
+
1972
+ # Control data lost before delivery
1973
+ #
1974
+ Socket::MSG_CTRUNC: Integer
1975
+
1976
+ # Send without using the routing tables
1977
+ #
1978
+ Socket::MSG_DONTROUTE: Integer
1979
+
1980
+ # This message should be non-blocking
1981
+ #
1982
+ Socket::MSG_DONTWAIT: Integer
1983
+
1984
+ # Data completes connection
1985
+ #
1986
+ Socket::MSG_EOF: Integer
1987
+
1988
+ # Data completes record
1989
+ #
1990
+ Socket::MSG_EOR: Integer
1991
+
1992
+ # Start of a hold sequence. Dumps to so_temp
1993
+ #
1994
+ Socket::MSG_FLUSH: Integer
1995
+
1996
+ # Data ready to be read
1997
+ #
1998
+ Socket::MSG_HAVEMORE: Integer
1999
+
2000
+ # Hold fragment in so_temp
2001
+ #
2002
+ Socket::MSG_HOLD: Integer
2003
+
2004
+ # Process out-of-band data
2005
+ #
2006
+ Socket::MSG_OOB: Integer
2007
+
2008
+ # Peek at incoming message
2009
+ #
2010
+ Socket::MSG_PEEK: Integer
2011
+
2012
+ # Data remains in the current packet
2013
+ #
2014
+ Socket::MSG_RCVMORE: Integer
2015
+
2016
+ # Send the packet in so_temp
2017
+ #
2018
+ Socket::MSG_SEND: Integer
2019
+
2020
+ # Data discarded before delivery
2021
+ #
2022
+ Socket::MSG_TRUNC: Integer
2023
+
2024
+ # Wait for full request or error
2025
+ #
2026
+ Socket::MSG_WAITALL: Integer
2027
+
2028
+ # The service specified is a datagram service (looks up UDP ports)
2029
+ #
2030
+ Socket::NI_DGRAM: Integer
2031
+
2032
+ # Maximum length of a hostname
2033
+ #
2034
+ Socket::NI_MAXHOST: Integer
2035
+
2036
+ # Maximum length of a service name
2037
+ #
2038
+ Socket::NI_MAXSERV: Integer
2039
+
2040
+ # A name is required
2041
+ #
2042
+ Socket::NI_NAMEREQD: Integer
2043
+
2044
+ # An FQDN is not required for local hosts, return only the local part
2045
+ #
2046
+ Socket::NI_NOFQDN: Integer
2047
+
2048
+ # Return a numeric address
2049
+ #
2050
+ Socket::NI_NUMERICHOST: Integer
2051
+
2052
+ # Return the service name as a digit string
2053
+ #
2054
+ Socket::NI_NUMERICSERV: Integer
2055
+
2056
+ # AppleTalk protocol
2057
+ #
2058
+ Socket::PF_APPLETALK: Integer
2059
+
2060
+ # CCITT (now ITU-T) protocols
2061
+ #
2062
+ Socket::PF_CCITT: Integer
2063
+
2064
+ # MIT CHAOS protocols
2065
+ #
2066
+ Socket::PF_CHAOS: Integer
2067
+
2068
+ # Computer Network Technology
2069
+ #
2070
+ Socket::PF_CNT: Integer
2071
+
2072
+ # Connection-oriented IP
2073
+ #
2074
+ Socket::PF_COIP: Integer
2075
+
2076
+ # Datakit protocol
2077
+ #
2078
+ Socket::PF_DATAKIT: Integer
2079
+
2080
+ # DEC Direct Data Link Interface protocol
2081
+ #
2082
+ Socket::PF_DLI: Integer
2083
+
2084
+ # European Computer Manufacturers protocols
2085
+ #
2086
+ Socket::PF_ECMA: Integer
2087
+
2088
+ # NSC Hyperchannel protocol
2089
+ #
2090
+ Socket::PF_HYLINK: Integer
2091
+
2092
+ # ARPANET IMP protocol
2093
+ #
2094
+ Socket::PF_IMPLINK: Integer
2095
+
2096
+ # IPv4 protocol
2097
+ #
2098
+ Socket::PF_INET: Integer
2099
+
2100
+ # IPv6 protocol
2101
+ #
2102
+ Socket::PF_INET6: Integer
2103
+
2104
+ # IPX protocol
2105
+ #
2106
+ Socket::PF_IPX: Integer
2107
+
2108
+ # Integrated Services Digital Network
2109
+ #
2110
+ Socket::PF_ISDN: Integer
2111
+
2112
+ # ISO Open Systems Interconnection protocols
2113
+ #
2114
+ Socket::PF_ISO: Integer
2115
+
2116
+ Socket::PF_KEY: Integer
2117
+
2118
+ # Local Area Transport protocol
2119
+ #
2120
+ Socket::PF_LAT: Integer
2121
+
2122
+ # Link layer interface
2123
+ #
2124
+ Socket::PF_LINK: Integer
2125
+
2126
+ # Host-internal protocols
2127
+ #
2128
+ Socket::PF_LOCAL: Integer
2129
+
2130
+ # Maximum address family for this platform
2131
+ #
2132
+ Socket::PF_MAX: Integer
2133
+
2134
+ # Native ATM access
2135
+ #
2136
+ Socket::PF_NATM: Integer
2137
+
2138
+ # Network driver raw access
2139
+ #
2140
+ Socket::PF_NDRV: Integer
2141
+
2142
+ # NetBIOS
2143
+ #
2144
+ Socket::PF_NETBIOS: Integer
2145
+
2146
+ # XEROX NS protocols
2147
+ #
2148
+ Socket::PF_NS: Integer
2149
+
2150
+ # ISO Open Systems Interconnection protocols
2151
+ #
2152
+ Socket::PF_OSI: Integer
2153
+
2154
+ Socket::PF_PIP: Integer
2155
+
2156
+ # Point-to-Point Protocol
2157
+ #
2158
+ Socket::PF_PPP: Integer
2159
+
2160
+ # PARC Universal Packet protocol
2161
+ #
2162
+ Socket::PF_PUP: Integer
2163
+
2164
+ # Internal routing protocol
2165
+ #
2166
+ Socket::PF_ROUTE: Integer
2167
+
2168
+ Socket::PF_RTIP: Integer
2169
+
2170
+ # Simple Internet Protocol
2171
+ #
2172
+ Socket::PF_SIP: Integer
2173
+
2174
+ # IBM SNA protocol
2175
+ #
2176
+ Socket::PF_SNA: Integer
2177
+
2178
+ Socket::PF_SYSTEM: Integer
2179
+
2180
+ # UNIX sockets
2181
+ #
2182
+ Socket::PF_UNIX: Integer
2183
+
2184
+ # Unspecified protocol, any supported address family
2185
+ #
2186
+ Socket::PF_UNSPEC: Integer
2187
+
2188
+ # eXpress Transfer Protocol
2189
+ #
2190
+ Socket::PF_XTP: Integer
2191
+
2192
+ # Process credentials
2193
+ #
2194
+ Socket::SCM_CREDS: Integer
2195
+
2196
+ # Access rights
2197
+ #
2198
+ Socket::SCM_RIGHTS: Integer
2199
+
2200
+ # Timestamp (timeval)
2201
+ #
2202
+ Socket::SCM_TIMESTAMP: Integer
2203
+
2204
+ # Shut down the reading side of the socket
2205
+ #
2206
+ Socket::SHUT_RD: Integer
2207
+
2208
+ # Shut down the both sides of the socket
2209
+ #
2210
+ Socket::SHUT_RDWR: Integer
2211
+
2212
+ # Shut down the writing side of the socket
2213
+ #
2214
+ Socket::SHUT_WR: Integer
2215
+
2216
+ # A datagram socket provides connectionless, unreliable messaging
2217
+ #
2218
+ Socket::SOCK_DGRAM: Integer
2219
+
2220
+ # A raw socket provides low-level access for direct access or implementing
2221
+ # network protocols
2222
+ #
2223
+ Socket::SOCK_RAW: Integer
2224
+
2225
+ # A reliable datagram socket provides reliable delivery of messages
2226
+ #
2227
+ Socket::SOCK_RDM: Integer
2228
+
2229
+ # A sequential packet socket provides sequenced, reliable two-way connection for
2230
+ # datagrams
2231
+ #
2232
+ Socket::SOCK_SEQPACKET: Integer
2233
+
2234
+ # A stream socket provides a sequenced, reliable two-way connection for a byte
2235
+ # stream
2236
+ #
2237
+ Socket::SOCK_STREAM: Integer
2238
+
2239
+ # Socket-level options
2240
+ #
2241
+ Socket::SOL_SOCKET: Integer
2242
+
2243
+ # Maximum connection requests that may be queued for a socket
2244
+ #
2245
+ Socket::SOMAXCONN: Integer
2246
+
2247
+ # Socket has had listen() called on it
2248
+ #
2249
+ Socket::SO_ACCEPTCONN: Integer
2250
+
2251
+ # Permit sending of broadcast messages
2252
+ #
2253
+ Socket::SO_BROADCAST: Integer
2254
+
2255
+ # Debug info recording
2256
+ #
2257
+ Socket::SO_DEBUG: Integer
2258
+
2259
+ # Use interface addresses
2260
+ #
2261
+ Socket::SO_DONTROUTE: Integer
2262
+
2263
+ # Retain unread data
2264
+ #
2265
+ Socket::SO_DONTTRUNC: Integer
2266
+
2267
+ # Get and clear the error status
2268
+ #
2269
+ Socket::SO_ERROR: Integer
2270
+
2271
+ # Keep connections alive
2272
+ #
2273
+ Socket::SO_KEEPALIVE: Integer
2274
+
2275
+ # Linger on close if data is present
2276
+ #
2277
+ Socket::SO_LINGER: Integer
2278
+
2279
+ # Install socket-level Network Kernel Extension
2280
+ #
2281
+ Socket::SO_NKE: Integer
2282
+
2283
+ # Don't SIGPIPE on EPIPE
2284
+ #
2285
+ Socket::SO_NOSIGPIPE: Integer
2286
+
2287
+ # Get first packet byte count
2288
+ #
2289
+ Socket::SO_NREAD: Integer
2290
+
2291
+ # Leave received out-of-band data in-line
2292
+ #
2293
+ Socket::SO_OOBINLINE: Integer
2294
+
2295
+ # Receive buffer size
2296
+ #
2297
+ Socket::SO_RCVBUF: Integer
2298
+
2299
+ # Receive low-water mark
2300
+ #
2301
+ Socket::SO_RCVLOWAT: Integer
2302
+
2303
+ # Receive timeout
2304
+ #
2305
+ Socket::SO_RCVTIMEO: Integer
2306
+
2307
+ # Allow local address reuse
2308
+ #
2309
+ Socket::SO_REUSEADDR: Integer
2310
+
2311
+ # Allow local address and port reuse
2312
+ #
2313
+ Socket::SO_REUSEPORT: Integer
2314
+
2315
+ # Send buffer size
2316
+ #
2317
+ Socket::SO_SNDBUF: Integer
2318
+
2319
+ # Send low-water mark
2320
+ #
2321
+ Socket::SO_SNDLOWAT: Integer
2322
+
2323
+ # Send timeout
2324
+ #
2325
+ Socket::SO_SNDTIMEO: Integer
2326
+
2327
+ # Receive timestamp with datagrams (timeval)
2328
+ #
2329
+ Socket::SO_TIMESTAMP: Integer
2330
+
2331
+ # Get the socket type
2332
+ #
2333
+ Socket::SO_TYPE: Integer
2334
+
2335
+ # Bypass hardware when possible
2336
+ #
2337
+ Socket::SO_USELOOPBACK: Integer
2338
+
2339
+ # Give a hint when more data is ready
2340
+ #
2341
+ Socket::SO_WANTMORE: Integer
2342
+
2343
+ # OOB data is wanted in MSG_FLAG on receive
2344
+ #
2345
+ Socket::SO_WANTOOBFLAG: Integer
2346
+
2347
+ # Reduce step of the handshake process (Linux 3.7, glibc 2.18)
2348
+ #
2349
+ Socket::TCP_FASTOPEN: Integer
2350
+
2351
+ # Maximum number of keepalive probes allowed before dropping a connection (Linux
2352
+ # 2.4, glibc 2.2)
2353
+ #
2354
+ Socket::TCP_KEEPCNT: Integer
2355
+
2356
+ # Time between keepalive probes (Linux 2.4, glibc 2.2)
2357
+ #
2358
+ Socket::TCP_KEEPINTVL: Integer
2359
+
2360
+ # Set maximum segment size
2361
+ #
2362
+ Socket::TCP_MAXSEG: Integer
2363
+
2364
+ # Don't delay sending to coalesce packets
2365
+ #
2366
+ Socket::TCP_NODELAY: Integer
2367
+
2368
+ # Don't use TCP options
2369
+ #
2370
+ Socket::TCP_NOOPT: Integer
2371
+
2372
+ # Don't push the last block of write
2373
+ #
2374
+ Socket::TCP_NOPUSH: Integer
2375
+
2376
+ # Socket::Ifaddr represents a result of getifaddrs() function.
2377
+ class Socket::Ifaddr
2378
+ public
2379
+
2380
+ # Returns the address of *ifaddr*. nil is returned if address is not available
2381
+ # in *ifaddr*.
2382
+ #
2383
+ def addr: () -> Addrinfo?
2384
+
2385
+ # Returns the broadcast address of *ifaddr*. nil is returned if the flags
2386
+ # doesn't have IFF_BROADCAST.
2387
+ #
2388
+ def broadaddr: () -> Addrinfo?
2389
+
2390
+ # Returns the destination address of *ifaddr*. nil is returned if the flags
2391
+ # doesn't have IFF_POINTOPOINT.
2392
+ #
2393
+ def dstaddr: () -> Addrinfo?
2394
+
2395
+ # Returns the flags of *ifaddr*.
2396
+ #
2397
+ def flags: () -> Integer
2398
+
2399
+ # Returns the interface index of *ifaddr*.
2400
+ #
2401
+ def ifindex: () -> Integer
2402
+
2403
+ # Returns a string to show contents of *ifaddr*.
2404
+ #
2405
+ def inspect: () -> String
2406
+
2407
+ # Returns the interface name of *ifaddr*.
2408
+ #
2409
+ def name: () -> String
2410
+
2411
+ # Returns the netmask address of *ifaddr*. nil is returned if netmask is not
2412
+ # available in *ifaddr*.
2413
+ #
2414
+ def netmask: () -> Addrinfo?
2415
+ end
2416
+
2417
+ # UDP/IP address information used by Socket.udp_server_loop.
2418
+ class Socket::UDPSource
2419
+ public
2420
+
2421
+ def inspect: () -> String
2422
+
2423
+ # Local address
2424
+ #
2425
+ def local_address: () -> Addrinfo
2426
+
2427
+ # Address of the source
2428
+ #
2429
+ def remote_address: () -> Addrinfo
2430
+
2431
+ # Sends the String `msg` to the source
2432
+ #
2433
+ def reply: (String msg) -> void
2434
+
2435
+ private
2436
+
2437
+ # `remote_address` is an Addrinfo object.
2438
+ #
2439
+ # `local_address` is an Addrinfo object.
2440
+ #
2441
+ # `reply_proc` is a Proc used to send reply back to the source.
2442
+ #
2443
+ def initialize: (Addrinfo remote_address, Addrinfo local_address) { (String) -> void } -> void
2444
+ end
2445
+
2446
+ # Socket::AncillaryData represents the ancillary data (control information) used
2447
+ # by sendmsg and recvmsg system call. It contains socket #family, control
2448
+ # message (cmsg) #level, cmsg #type and cmsg #data.
2449
+ class Socket::AncillaryData
2450
+ # Creates a new Socket::AncillaryData object which contains a int as data.
2451
+ #
2452
+ # The size and endian is dependent on the host.
2453
+ #
2454
+ # require 'socket'
2455
+ #
2456
+ # p Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, STDERR.fileno)
2457
+ # #=> #<Socket::AncillaryData: UNIX SOCKET RIGHTS 2>
2458
+ #
2459
+ def self.int: (Symbol, Symbol, Symbol, Symbol) -> instance
2460
+
2461
+ # Returns new ancillary data for IP_PKTINFO.
2462
+ #
2463
+ # If spec_dst is not given, addr is used.
2464
+ #
2465
+ # IP_PKTINFO is not standard.
2466
+ #
2467
+ # Supported platform: GNU/Linux
2468
+ #
2469
+ # addr = Addrinfo.ip("127.0.0.1")
2470
+ # ifindex = 0
2471
+ # spec_dst = Addrinfo.ip("127.0.0.1")
2472
+ # p Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dst)
2473
+ # #=> #<Socket::AncillaryData: INET IP PKTINFO 127.0.0.1 ifindex:0 spec_dst:127.0.0.1>
2474
+ #
2475
+ def self.ip_pktinfo: (Addrinfo addr, Integer ifindex, ?Addrinfo spec_dst) -> instance
2476
+
2477
+ # Returns new ancillary data for IPV6_PKTINFO.
2478
+ #
2479
+ # IPV6_PKTINFO is defined by RFC 3542.
2480
+ #
2481
+ # addr = Addrinfo.ip("::1")
2482
+ # ifindex = 0
2483
+ # p Socket::AncillaryData.ipv6_pktinfo(addr, ifindex)
2484
+ # #=> #<Socket::AncillaryData: INET6 IPV6 PKTINFO ::1 ifindex:0>
2485
+ #
2486
+ def self.ipv6_pktinfo: (Addrinfo addr, Integer ifindex) -> instance
2487
+
2488
+ # Creates a new Socket::AncillaryData object which contains file descriptors as
2489
+ # data.
2490
+ #
2491
+ # p Socket::AncillaryData.unix_rights(STDERR)
2492
+ # #=> #<Socket::AncillaryData: UNIX SOCKET RIGHTS 2>
2493
+ #
2494
+ def self.unix_rights: (IO fd) -> instance
2495
+
2496
+ public
2497
+
2498
+ # tests the level and type of *ancillarydata*.
2499
+ #
2500
+ # ancdata = Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "")
2501
+ # ancdata.cmsg_is?(Socket::IPPROTO_IPV6, Socket::IPV6_PKTINFO) #=> true
2502
+ # ancdata.cmsg_is?(:IPV6, :PKTINFO) #=> true
2503
+ # ancdata.cmsg_is?(:IP, :PKTINFO) #=> false
2504
+ # ancdata.cmsg_is?(:SOCKET, :RIGHTS) #=> false
2505
+ #
2506
+ def cmsg_is?: (Integer level, Integer ancillary_type) -> bool
2507
+
2508
+ # returns the cmsg data as a string.
2509
+ #
2510
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "").data
2511
+ # #=> ""
2512
+ #
2513
+ def data: () -> String
2514
+
2515
+ # returns the socket family as an integer.
2516
+ #
2517
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "").family
2518
+ # #=> 10
2519
+ #
2520
+ def family: () -> Integer
2521
+
2522
+ # returns a string which shows ancillarydata in human-readable form.
2523
+ #
2524
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "").inspect
2525
+ # #=> "#<Socket::AncillaryData: INET6 IPV6 PKTINFO \"\">"
2526
+ #
2527
+ def inspect: () -> String
2528
+
2529
+ # Returns the data in *ancillarydata* as an int.
2530
+ #
2531
+ # The size and endian is dependent on the host.
2532
+ #
2533
+ # ancdata = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, STDERR.fileno)
2534
+ # p ancdata.int #=> 2
2535
+ #
2536
+ def int: () -> Integer
2537
+
2538
+ # Extracts addr, ifindex and spec_dst from IP_PKTINFO ancillary data.
2539
+ #
2540
+ # IP_PKTINFO is not standard.
2541
+ #
2542
+ # Supported platform: GNU/Linux
2543
+ #
2544
+ # addr = Addrinfo.ip("127.0.0.1")
2545
+ # ifindex = 0
2546
+ # spec_dest = Addrinfo.ip("127.0.0.1")
2547
+ # ancdata = Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dest)
2548
+ # p ancdata.ip_pktinfo
2549
+ # #=> [#<Addrinfo: 127.0.0.1>, 0, #<Addrinfo: 127.0.0.1>]
2550
+ #
2551
+ def ip_pktinfo: () -> [Addrinfo, Integer, Addrinfo]
2552
+
2553
+ # Extracts addr and ifindex from IPV6_PKTINFO ancillary data.
2554
+ #
2555
+ # IPV6_PKTINFO is defined by RFC 3542.
2556
+ #
2557
+ # addr = Addrinfo.ip("::1")
2558
+ # ifindex = 0
2559
+ # ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex)
2560
+ # p ancdata.ipv6_pktinfo #=> [#<Addrinfo: ::1>, 0]
2561
+ #
2562
+ def ipv6_pktinfo: () -> [Addrinfo, Integer]
2563
+
2564
+ # Extracts addr from IPV6_PKTINFO ancillary data.
2565
+ #
2566
+ # IPV6_PKTINFO is defined by RFC 3542.
2567
+ #
2568
+ # addr = Addrinfo.ip("::1")
2569
+ # ifindex = 0
2570
+ # ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex)
2571
+ # p ancdata.ipv6_pktinfo_addr #=> #<Addrinfo: ::1>
2572
+ #
2573
+ def ipv6_pktinfo_addr: () -> Addrinfo
2574
+
2575
+ # Extracts ifindex from IPV6_PKTINFO ancillary data.
2576
+ #
2577
+ # IPV6_PKTINFO is defined by RFC 3542.
2578
+ #
2579
+ # addr = Addrinfo.ip("::1")
2580
+ # ifindex = 0
2581
+ # ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex)
2582
+ # p ancdata.ipv6_pktinfo_ifindex #=> 0
2583
+ #
2584
+ def ipv6_pktinfo_ifindex: () -> Integer
2585
+
2586
+ # returns the cmsg level as an integer.
2587
+ #
2588
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "").level
2589
+ # #=> 41
2590
+ #
2591
+ def level: () -> Integer
2592
+
2593
+ # returns the timestamp as a time object.
2594
+ #
2595
+ # *ancillarydata* should be one of following type:
2596
+ # * SOL_SOCKET/SCM_TIMESTAMP (microsecond) GNU/Linux, FreeBSD, NetBSD,
2597
+ # OpenBSD, Solaris, MacOS X
2598
+ # * SOL_SOCKET/SCM_TIMESTAMPNS (nanosecond) GNU/Linux
2599
+ # * SOL_SOCKET/SCM_BINTIME (2**(-64) second) FreeBSD
2600
+ #
2601
+ # Addrinfo.udp("127.0.0.1", 0).bind {|s1|
2602
+ # Addrinfo.udp("127.0.0.1", 0).bind {|s2|
2603
+ # s1.setsockopt(:SOCKET, :TIMESTAMP, true)
2604
+ # s2.send "a", 0, s1.local_address
2605
+ # ctl = s1.recvmsg.last
2606
+ # p ctl #=> #<Socket::AncillaryData: INET SOCKET TIMESTAMP 2009-02-24 17:35:46.775581>
2607
+ # t = ctl.timestamp
2608
+ # p t #=> 2009-02-24 17:35:46 +0900
2609
+ # p t.usec #=> 775581
2610
+ # p t.nsec #=> 775581000
2611
+ # }
2612
+ #
2613
+ # }
2614
+ #
2615
+ #
2616
+ def timestamp: () -> Time
2617
+
2618
+ # returns the cmsg type as an integer.
2619
+ #
2620
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "").type
2621
+ # #=> 2
2622
+ #
2623
+ def type: () -> Integer
2624
+
2625
+ # returns the array of IO objects for SCM_RIGHTS control message in UNIX domain
2626
+ # socket.
2627
+ #
2628
+ # The class of the IO objects in the array is IO or Socket.
2629
+ #
2630
+ # The array is attached to *ancillarydata* when it is instantiated. For example,
2631
+ # BasicSocket#recvmsg attach the array when receives a SCM_RIGHTS control
2632
+ # message and :scm_rights=>true option is given.
2633
+ #
2634
+ # # recvmsg needs :scm_rights=>true for unix_rights
2635
+ # s1, s2 = UNIXSocket.pair
2636
+ # p s1 #=> #<UNIXSocket:fd 3>
2637
+ # s1.sendmsg "stdin and a socket", 0, nil, Socket::AncillaryData.unix_rights(STDIN, s1)
2638
+ # _, _, _, ctl = s2.recvmsg(:scm_rights=>true)
2639
+ # p ctl #=> #<Socket::AncillaryData: UNIX SOCKET RIGHTS 6 7>
2640
+ # p ctl.unix_rights #=> [#<IO:fd 6>, #<Socket:fd 7>]
2641
+ # p File.identical?(STDIN, ctl.unix_rights[0]) #=> true
2642
+ # p File.identical?(s1, ctl.unix_rights[1]) #=> true
2643
+ #
2644
+ # # If :scm_rights=>true is not given, unix_rights returns nil
2645
+ # s1, s2 = UNIXSocket.pair
2646
+ # s1.sendmsg "stdin and a socket", 0, nil, Socket::AncillaryData.unix_rights(STDIN, s1)
2647
+ # _, _, _, ctl = s2.recvmsg
2648
+ # p ctl #=> #<Socket::AncillaryData: UNIX SOCKET RIGHTS 6 7>
2649
+ # p ctl.unix_rights #=> nil
2650
+ #
2651
+ def unix_rights: () -> Array[IO]?
2652
+
2653
+ private
2654
+
2655
+ # *family* should be an integer, a string or a symbol.
2656
+ # * Socket::AF_INET, "AF_INET", "INET", :AF_INET, :INET
2657
+ # * Socket::AF_UNIX, "AF_UNIX", "UNIX", :AF_UNIX, :UNIX
2658
+ # * etc.
2659
+ #
2660
+ #
2661
+ # *cmsg_level* should be an integer, a string or a symbol.
2662
+ # * Socket::SOL_SOCKET, "SOL_SOCKET", "SOCKET", :SOL_SOCKET and :SOCKET
2663
+ # * Socket::IPPROTO_IP, "IP" and :IP
2664
+ # * Socket::IPPROTO_IPV6, "IPV6" and :IPV6
2665
+ # * Socket::IPPROTO_TCP, "TCP" and :TCP
2666
+ # * etc.
2667
+ #
2668
+ #
2669
+ # *cmsg_type* should be an integer, a string or a symbol. If a string/symbol is
2670
+ # specified, it is interpreted depend on *cmsg_level*.
2671
+ # * Socket::SCM_RIGHTS, "SCM_RIGHTS", "RIGHTS", :SCM_RIGHTS, :RIGHTS for
2672
+ # SOL_SOCKET
2673
+ # * Socket::IP_RECVTTL, "RECVTTL" and :RECVTTL for IPPROTO_IP
2674
+ # * Socket::IPV6_PKTINFO, "PKTINFO" and :PKTINFO for IPPROTO_IPV6
2675
+ # * etc.
2676
+ #
2677
+ #
2678
+ # *cmsg_data* should be a string.
2679
+ #
2680
+ # p Socket::AncillaryData.new(:INET, :TCP, :NODELAY, "")
2681
+ # #=> #<Socket::AncillaryData: INET TCP NODELAY "">
2682
+ #
2683
+ # p Socket::AncillaryData.new(:INET6, :IPV6, :PKTINFO, "")
2684
+ # #=> #<Socket::AncillaryData: INET6 IPV6 PKTINFO "">
2685
+ #
2686
+ def initialize: (Symbol | String | Integer family, Symbol | String | Integer cmsg_level, Symbol | String | Integer cmsg_data, String cmsg_data) -> untyped
2687
+ end