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
-
#connect(wrapper = self.wrapper, &block) ⇒ Socket
Connects a socket to the given address.
- #connected(**options) ⇒ Object
-
#each {|_self| ... } ⇒ Object
Enumerate all discrete paths as endpoints.
-
#hostname ⇒ String
The hostname of the bound socket.
-
#initialize(**options) ⇒ Generic
constructor
A new instance of Generic.
-
#linger ⇒ Integer?
Controls SO_LINGER.
-
#local_address ⇒ Address
The address to bind to before connecting.
-
#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 ⇒ Numeric
The default timeout for socket operations.
- #with(**options) ⇒ Object
-
#wrapper ⇒ Object
The default wrapper to use for binding, connecting, and accepting connections.
Constructor Details
#initialize(**options) ⇒ Generic
Returns a new instance of Generic.
15 16 17 |
# File 'lib/io/endpoint/generic.rb', line 15 def initialize(**) @options = .freeze end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
27 28 29 |
# File 'lib/io/endpoint/generic.rb', line 27 def @options 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.
107 108 109 110 111 |
# File 'lib/io/endpoint/generic.rb', line 107 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.
81 82 83 84 85 |
# File 'lib/io/endpoint/generic.rb', line 81 def accept(wrapper = self.wrapper, &block) bind(wrapper) do |server| wrapper.accept(server, **@options, &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.
67 68 69 |
# File 'lib/io/endpoint/generic.rb', line 67 def bind(wrapper = self.wrapper, &block) raise NotImplementedError end |
#bound(**options) ⇒ Object
79 80 81 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 79 def bound(**) BoundEndpoint.bound(self, **) end |
#connect(wrapper = self.wrapper, &block) ⇒ Socket
Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
74 75 76 |
# File 'lib/io/endpoint/generic.rb', line 74 def connect(wrapper = self.wrapper, &block) raise NotImplementedError end |
#connected(**options) ⇒ Object
69 70 71 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 69 def connected(**) ConnectedEndpoint.connected(self, **) end |
#each {|_self| ... } ⇒ Object
Enumerate all discrete paths as endpoints.
90 91 92 93 94 |
# File 'lib/io/endpoint/generic.rb', line 90 def each return to_enum unless block_given? yield self end |
#hostname ⇒ String
Returns The hostname of the bound socket.
30 31 32 |
# File 'lib/io/endpoint/generic.rb', line 30 def hostname @options[:hostname] end |
#linger ⇒ Integer?
Controls SO_LINGER. The amount of time the socket will stay in the ‘TIME_WAIT` state after being closed.
48 49 50 |
# File 'lib/io/endpoint/generic.rb', line 48 def linger @options[:linger] end |
#local_address ⇒ Address
Returns the address to bind to before connecting.
58 59 60 |
# File 'lib/io/endpoint/generic.rb', line 58 def local_address @options[: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.
42 43 44 |
# File 'lib/io/endpoint/generic.rb', line 42 def reuse_address? @options[: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.
36 37 38 |
# File 'lib/io/endpoint/generic.rb', line 36 def reuse_port? @options[:reuse_port] end |
#timeout ⇒ Numeric
Returns The default timeout for socket operations.
53 54 55 |
# File 'lib/io/endpoint/generic.rb', line 53 def timeout @options[:timeout] end |
#with(**options) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/io/endpoint/generic.rb', line 19 def with(**) dup = self.dup dup. = @options.merge() return dup end |