class IO::Endpoint::Generic
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"
def self.parse(string, **options) uri = URI.parse(string) IO::Endpoint.public_send(uri.scheme, uri.host, uri.port, **options) end
def accept(wrapper = self.wrapper, &block)
@yields {|socket| ...} For each accepted connection, yields the socket.
@parameter wrapper [Wrapper] The wrapper to use for accepting connections.
Bind and accept connections on the given address.
def accept(wrapper = self.wrapper, &block) bind(wrapper) do |server| wrapper.accept(server, **@options, &block) end end
def bind(wrapper = self.wrapper, &block)
@parameter socket [Socket] The socket which has been bound.
@yields {|socket| ...} If a block is given, yields the bound socket.
@parameter wrapper [Wrapper] The wrapper to use for binding.
Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
def bind(wrapper = self.wrapper, &block) raise NotImplementedError end
def bound(**options)
@parameter options [Hash] Options to pass to {BoundEndpoint.bound}.
Create a bound endpoint from this endpoint.
def bound(**options) BoundEndpoint.bound(self, **options) end
def connect(wrapper = self.wrapper, &block)
@parameter wrapper [Wrapper] The wrapper to use for connecting.
Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
def connect(wrapper = self.wrapper, &block) raise NotImplementedError end
def connected(**options)
@parameter options [Hash] Options to pass to {ConnectedEndpoint.connected}.
Create a connected endpoint from this endpoint.
def connected(**options) ConnectedEndpoint.connected(self, **options) end
def each
@yields {|endpoint| ...} For each endpoint, yields it.
Enumerate all discrete paths as endpoints.
def each return to_enum unless block_given? yield self end
def hostname
def hostname @options[:hostname] end
def initialize(**options)
Initialize a new generic endpoint.
def initialize(**options) @options = options.freeze end
def linger
Controls SO_LINGER. The amount of time the socket will stay in the `TIME_WAIT` state after being closed.
def linger @options[:linger] end
def local_address
def local_address @options[:local_address] 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.
def reuse_address? @options[:reuse_address] 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.
def reuse_port? @options[:reuse_port] end
def timeout
def timeout @options[:timeout] end
def with(**options)
@parameter options [Hash] Additional options to merge with existing options.
Create a new endpoint with merged options.
def with(**options) dup = self.dup dup.options = @options.merge(options) return dup end
def wrapper
def wrapper @options[:wrapper] || Wrapper.default end