Class: IO::Endpoint::Generic
- Inherits:
-
Object
- Object
- IO::Endpoint::Generic
- Defined in:
- lib/io/endpoint/generic.rb,
lib/io/endpoint/bound_endpoint.rb,
lib/io/endpoint/connected_endpoint.rb
Overview
Endpoints represent a way of connecting or binding to an address.
Direct Known Subclasses
AddressEndpoint, BoundEndpoint, CompositeEndpoint, ConnectedEndpoint, HostEndpoint, SSLEndpoint, SocketEndpoint
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.parse(string, **options) ⇒ Object
Create an Endpoint instance by URI scheme.
Instance Method Summary collapse
-
#accept(wrapper = self.wrapper, &block) ⇒ Object
Bind and accept connections on the given address.
-
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind a socket to the given address.
-
#bound(**options) ⇒ Object
Create a bound endpoint from this endpoint.
-
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connects a socket to the given address.
-
#connected(**options) ⇒ Object
Create a connected endpoint from this endpoint.
-
#each {|_self| ... } ⇒ Object
Enumerate all discrete paths as endpoints.
- #hostname ⇒ Object
-
#initialize(**options) ⇒ Generic
constructor
Initialize a new generic endpoint.
-
#linger ⇒ Object
Controls SO_LINGER.
- #local_address ⇒ Object
-
#reuse_address? ⇒ Boolean
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.
-
#reuse_port? ⇒ Boolean
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.
- #timeout ⇒ Object
-
#with(**options) ⇒ Object
Create a new endpoint with merged options.
-
#wrapper ⇒ Object
The default wrapper to use for binding, connecting, and accepting connections.
Constructor Details
#initialize(**options) ⇒ Generic
Initialize a new generic endpoint.
17 18 19 |
# File 'lib/io/endpoint/generic.rb', line 17 def initialize(**) = .freeze end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
32 33 34 |
# File 'lib/io/endpoint/generic.rb', line 32 def end |
Class Method Details
.parse(string, **options) ⇒ Object
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.
You should not use untrusted input as it may execute arbitrary code.
113 114 115 116 117 |
# File 'lib/io/endpoint/generic.rb', line 113 def self.parse(string, **) uri = URI.parse(string) IO::Endpoint.public_send(uri.scheme, uri.host, uri.port, **) end |
Instance Method Details
#accept(wrapper = self.wrapper, &block) ⇒ Object
Bind and accept connections on the given address.
87 88 89 90 91 |
# File 'lib/io/endpoint/generic.rb', line 87 def accept(wrapper = self.wrapper, &block) bind(wrapper) do |server| wrapper.accept(server, **, &block) end end |
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
72 73 74 |
# File 'lib/io/endpoint/generic.rb', line 72 def bind(wrapper = self.wrapper, &block) raise NotImplementedError end |
#bound(**options) ⇒ Object
Create a bound endpoint from this endpoint.
104 105 106 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 104 def bound(**) BoundEndpoint.bound(self, **) end |
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
79 80 81 |
# File 'lib/io/endpoint/generic.rb', line 79 def connect(wrapper = self.wrapper, &block) raise NotImplementedError end |
#connected(**options) ⇒ Object
Create a connected endpoint from this endpoint.
93 94 95 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 93 def connected(**) ConnectedEndpoint.connected(self, **) end |
#each {|_self| ... } ⇒ Object
Enumerate all discrete paths as endpoints.
96 97 98 99 100 |
# File 'lib/io/endpoint/generic.rb', line 96 def each return to_enum unless block_given? yield self end |
#hostname ⇒ Object
35 36 37 |
# File 'lib/io/endpoint/generic.rb', line 35 def hostname [:hostname] end |
#linger ⇒ Object
Controls SO_LINGER. The amount of time the socket will stay in the ‘TIME_WAIT` state after being closed.
53 54 55 |
# File 'lib/io/endpoint/generic.rb', line 53 def linger [:linger] end |
#local_address ⇒ Object
63 64 65 |
# File 'lib/io/endpoint/generic.rb', line 63 def local_address [:local_address] end |
#reuse_address? ⇒ Boolean
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.
47 48 49 |
# File 'lib/io/endpoint/generic.rb', line 47 def reuse_address? [:reuse_address] end |
#reuse_port? ⇒ Boolean
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.
41 42 43 |
# File 'lib/io/endpoint/generic.rb', line 41 def reuse_port? [:reuse_port] end |
#timeout ⇒ Object
58 59 60 |
# File 'lib/io/endpoint/generic.rb', line 58 def timeout [:timeout] end |
#with(**options) ⇒ Object
Create a new endpoint with merged options.
24 25 26 27 28 29 30 |
# File 'lib/io/endpoint/generic.rb', line 24 def with(**) dup = self.dup dup. = .merge() return dup end |
#wrapper ⇒ Object
The default wrapper to use for binding, connecting, and accepting connections.
120 121 122 |
# File 'lib/io/endpoint/generic.rb', line 120 def wrapper [:wrapper] || Wrapper.default end |