Class: IO::Endpoint::BoundEndpoint
- Defined in:
- lib/io/endpoint/bound_endpoint.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#sockets ⇒ Object
readonly
Returns the value of attribute sockets.
Attributes inherited from Generic
Class Method Summary collapse
Instance Method Summary collapse
- #bind(wrapper = self.wrapper, &block) ⇒ Object
- #close ⇒ Object
-
#initialize(endpoint, sockets, **options) ⇒ BoundEndpoint
constructor
A new instance of BoundEndpoint.
- #inspect ⇒ Object
-
#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
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
Returns a new instance of BoundEndpoint.
22 23 24 25 26 27 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 22 def initialize(endpoint, sockets, **) super(**) @endpoint = endpoint @sockets = sockets end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
29 30 31 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 29 def endpoint @endpoint end |
#sockets ⇒ Object (readonly)
Returns the value of attribute sockets.
30 31 32 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 30 def sockets @sockets end |
Class Method Details
.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 12 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 65 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
52 53 54 55 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 52 def close @sockets.each(&:close) @sockets.clear end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 61 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.
34 35 36 37 38 39 40 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 34 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.
44 45 46 47 48 49 50 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 44 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
57 58 59 |
# File 'lib/io/endpoint/bound_endpoint.rb', line 57 def to_s "bound:#{@endpoint}" end |