Class: IO::Endpoint::BoundEndpoint
- Defined in:
- lib/io/endpoint/bound_endpoint.rb
Overview
Represents an endpoint that has been bound to one or more sockets.
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#sockets ⇒ Object
readonly
Returns the value of attribute sockets.
- #The original endpoint that was bound.(originalendpointthatwasbound.) ⇒ Object readonly
- #The sockets that were bound.(socketsthatwerebound.) ⇒ Object readonly
Attributes inherited from Generic
Class Method Summary collapse
-
.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) ⇒ Object
Create a bound endpoint from an existing endpoint.
Instance Method Summary collapse
-
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind the endpoint using the given wrapper.
-
#close ⇒ Object
Close all bound sockets.
-
#initialize(endpoint, sockets, **options) ⇒ BoundEndpoint
constructor
Initialize a new bound endpoint.
-
#inspect ⇒ Object
Get a detailed string representation of the bound endpoint.
-
#local_address_endpoint(**options) ⇒ Object
A endpoint for the local end of the bound socket.
-
#remote_address_endpoint(**options) ⇒ Object
A endpoint for the remote end of the bound socket.
-
#to_s ⇒ Object
Get a string representation of the bound endpoint.
Methods inherited from Generic
#accept, #bound, #connect, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper
Constructor Details
#initialize(endpoint, sockets, **options) ⇒ BoundEndpoint
Initialize a new bound endpoint.
32 33 34 35 36 37 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 32 def initialize(endpoint, sockets, **) super(**) @endpoint = endpoint @sockets = sockets end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
40 41 42 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 40 def endpoint @endpoint end |
#sockets ⇒ Object (readonly)
Returns the value of attribute sockets.
42 43 44 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 42 def sockets @sockets end |
#The original endpoint that was bound.(originalendpointthatwasbound.) ⇒ Object (readonly)
40 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 40 attr :endpoint |
#The sockets that were bound.(socketsthatwerebound.) ⇒ Object (readonly)
42 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 42 attr :sockets |
Class Method Details
.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) ⇒ Object
Create a bound endpoint from an existing endpoint.
18 19 20 21 22 23 24 25 26 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 18 def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) sockets = endpoint.bind sockets.each do |socket| socket.close_on_exec = close_on_exec end return self.new(endpoint, sockets, **endpoint.) end |
Instance Method Details
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind the endpoint using the given wrapper.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 87 def bind(wrapper = self.wrapper, &block) @sockets.map do |server| if block_given? wrapper.schedule do yield server end else server.dup end end end |
#close ⇒ Object
Close all bound sockets.
65 66 67 68 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 65 def close @sockets.each(&:close) @sockets.clear end |
#inspect ⇒ Object
Get a detailed string representation of the bound endpoint.
78 79 80 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 78 def inspect "\#<#{self.class} #{@sockets.size} bound sockets for #{@endpoint}>" end |
#local_address_endpoint(**options) ⇒ Object
A endpoint for the local end of the bound socket.
46 47 48 49 50 51 52 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 46 def local_address_endpoint(**) endpoints = @sockets.map do |socket| AddressEndpoint.new(socket.to_io.local_address, **) end return CompositeEndpoint.new(endpoints) end |
#remote_address_endpoint(**options) ⇒ Object
A endpoint for the remote end of the bound socket.
56 57 58 59 60 61 62 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 56 def remote_address_endpoint(**) endpoints = @sockets.map do |wrapper| AddressEndpoint.new(socket.to_io.remote_address, **) end return CompositeEndpoint.new(endpoints) end |
#to_s ⇒ Object
Get a string representation of the bound endpoint.
72 73 74 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 72 def to_s "bound:#{@endpoint}" end |