class Async::IO::Endpoint
Endpoints represent a way of connecting or binding to an address.
def self.each(specifications, &block)
def self.each(specifications, &block) return to_enum(:each, specifications) unless block_given? specifications.each do |specification| yield try_convert(specification) end end
def self.parse(string, **options)
- See: Endpoint.unix - unix - invoked when parsing a URL with the unix scheme: "unix://127.0.0.1"
See: Endpoint.udp - udp - invoked when parsing a URL with the udp scheme: "udp://127.0.0.1"
See: Endpoint.tcp - tcp - invoked when parsing a URL with the tcp scheme: "tcp://127.0.0.1"
See: Endpoint.ssl - ssl - invoked when parsing a URL with the ssl scheme "ssl://127.0.0.1"
Parameters:
-
options() -- keyword arguments passed through to {#initialize} -
string(String) -- URI as string. Scheme will decide implementation used.
def self.parse(string, **options) uri = URI.parse(string) self.public_send(uri.scheme, uri.host, uri.port, **options) end
def self.socket(socket, **options)
def self.socket(socket, **options) SocketEndpoint.new(socket, **options) end
def self.ssl(*args, ssl_context: nil, hostname: nil, **options)
-
(SSLEndpoint)-
Parameters:
-
options() -- keyword arguments passed through to {Endpoint.tcp} -
hostname(String, nil) -- -
ssl_context(OpenSSL::SSL::SSLContext, nil) -- -
args() --
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.tcp(*args, **options)
-
(HostEndpoint)-
Parameters:
-
options() -- keyword arguments passed on to {HostEndpoint#initialize} -
args() -- nodename, service, family, socktype, protocol, flags. `socktype` will be set to Socket::SOCK_STREAM.
def self.tcp(*args, **options) args[3] = ::Socket::SOCK_STREAM HostEndpoint.new(args, **options) end
def self.try_convert(specification)
def self.try_convert(specification) if specification.is_a? self specification elsif specification.is_a? Array self.send(*specification) elsif specification.is_a? String self.parse(specification) elsif specification.is_a? ::BasicSocket self.socket(specification) elsif specification.is_a? Generic self.new(specification) else raise ArgumentError.new("Not sure how to convert #{specification} to endpoint!") end end
def self.udp(*args, **options)
-
(HostEndpoint)-
Parameters:
-
options() -- keyword arguments passed on to {HostEndpoint#initialize} -
args() -- nodename, service, family, socktype, protocol, flags. `socktype` will be set to Socket::SOCK_DGRAM.
def self.udp(*args, **options) args[3] = ::Socket::SOCK_DGRAM HostEndpoint.new(args, **options) end
def self.unix(path, type = ::Socket::SOCK_STREAM, **options)
-
(UNIXEndpoint)-
Parameters:
-
options() -- keyword arguments passed through to {UNIXEndpoint#initialize} -
type() -- Socket type -
path(String) --
def self.unix(path, type = ::Socket::SOCK_STREAM, **options) UNIXEndpoint.new(path, type, **options) end
def accept(backlog = Socket::SOMAXCONN, &block)
-
backlog(Integer) -- the number of connections to listen for.
def accept(backlog = Socket::SOMAXCONN, &block) bind do |server| server.listen(backlog) server.accept_each(&block) end end
def bound
- Yield: - the bound wrapper.
def bound wrappers = [] self.each do |endpoint| wrapper = endpoint.bind wrappers << wrapper yield wrapper end return wrappers ensure wrappers.each(&:close) if $! end
def each
- Yield: - Enumerate all discrete paths as endpoints.
def each return to_enum unless block_given? yield self end
def hostname
-
(String)- The hostname of the bound socket.
def hostname @options[:hostname] end
def initialize(**options)
def initialize(**options) @options = options.freeze end
def linger
-
(Integer, nil)- The value for SO_LINGER.
def linger @options[:linger] end
def local_address
-
(Address)- the address to bind to before connecting.
def local_address @options[:local_address] end
def reuse_address
-
(Boolean)- The value for `SO_REUSEADDR`.
def reuse_address @options[:reuse_address] end
def reuse_port
-
(Boolean, nil)- The value for `SO_REUSEPORT`.
def reuse_port @options[:reuse_port] end
def timeout
-
(Numeric)- The default timeout for socket operations.
def timeout @options[:timeout] end
def with(**options)
def with(**options) dup = self.dup dup.options = @options.merge(options) return dup end