class Endpoint
Endpoints represent a way of connecting or binding to an address.
Definitions
def self.each(specifications, &block)
Generate a list of endpoints from an array.
Implementation
def self.each(specifications, &block)
return to_enum(:each, specifications) unless block_given?
specifications.each do |specification|
yield try_convert(specification)
end
end
def each
Endpoints sometimes have multiple paths.
Implementation
def each
return to_enum unless block_given?
yield self
end
def hostname
Implementation
def hostname
@options[:hostname]
end
def reuse_port
If SO_REUSEPORT
is enabled on a socket, the socket can be successfully bound even if there are existing sockets bound to the same address, as long as all prior bound sockets also had SO_REUSEPORT
set before they were bound.
Implementation
def reuse_port
@options[:reuse_port]
end
def reuse_address
If SO_REUSEADDR
is enabled on a socket prior to binding it, the socket can be successfully bound unless there is a conflict with another socket bound to exactly the same combination of source address and port. Additionally, when set, binding a socket to the address of an existing socket in TIME_WAIT
is not an error.
Implementation
def reuse_address
@options[:reuse_address]
end
def linger
Controls SO_LINGER. The amount of time the socket will stay in the TIME_WAIT
state after being closed.
Implementation
def linger
@options[:linger]
end
def timeout
Implementation
def timeout
@options[:timeout]
end
def local_address
Implementation
def local_address
@options[:local_address]
end
def accept(backlog = Socket::SOMAXCONN, &block)
Accept connections from the specified endpoint.
Implementation
def accept(backlog = Socket::SOMAXCONN, &block)
bind do |server|
server.listen(backlog)
server.accept_each(&block)
end
end
def self.parse(string, **options)
Create an Endpoint instance by URI scheme. The host and port of the URI will be passed to the Endpoint factory method, along with any options.
Implementation
def self.parse(string, **options)
uri = URI.parse(string)
self.public_send(uri.scheme, uri.host, uri.port, **options)
end
def self.tcp(*args, **options)
Implementation
def self.tcp(*args, **options)
args[3] = ::Socket::SOCK_STREAM
HostEndpoint.new(args, **options)
end
def self.udp(*args, **options)
Implementation
def self.udp(*args, **options)
args[3] = ::Socket::SOCK_DGRAM
HostEndpoint.new(args, **options)
end
def self.ssl(*args, ssl_context: nil, hostname: nil, **options)
Implementation
def self.ssl(*args, ssl_context: nil, hostname: nil, **options)
SSLEndpoint.new(self.tcp(*args, **options), ssl_context: ssl_context, hostname: hostname)
end
def self.unix(path = "", type = ::Socket::SOCK_STREAM, **options)
Implementation
def self.unix(path = "", type = ::Socket::SOCK_STREAM, **options)
UNIXEndpoint.new(path, type, **options)
end