class Async::IO::SharedEndpoint
Pre-connect and pre-bind sockets so that it can be used between processes.
Attributes
endpoint[R]
wrappers[R]
Public Class Methods
bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false)
click to toggle source
Create a new `SharedEndpoint` by binding to the given endpoint.
# File lib/async/io/shared_endpoint.rb, line 30 def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) wrappers = endpoint.bound do |server| server.listen(backlog) server.close_on_exec = close_on_exec server.reactor = nil end return self.new(endpoint, wrappers) end
connected(endpoint, close_on_exec: false)
click to toggle source
Create a new `SharedEndpoint` by connecting to the given endpoint.
# File lib/async/io/shared_endpoint.rb, line 41 def self.connected(endpoint, close_on_exec: false) wrapper = endpoint.connect wrapper.close_on_exec = close_on_exec wrapper.reactor = nil return self.new(endpoint, [wrapper]) end
new(endpoint, wrappers, **options)
click to toggle source
Calls superclass method
Async::IO::Endpoint::new
# File lib/async/io/shared_endpoint.rb, line 50 def initialize(endpoint, wrappers, **options) super(**options) @endpoint = endpoint @wrappers = wrappers end
Public Instance Methods
accept(backlog = nil, &block)
click to toggle source
# File lib/async/io/shared_endpoint.rb, line 102 def accept(backlog = nil, &block) bind do |server| server.accept_each(&block) end end
bind() { |server, task| ... }
click to toggle source
# File lib/async/io/shared_endpoint.rb, line 66 def bind task = Async::Task.current @wrappers.each do |server| server = server.dup task.async do |task| task.annotate "binding to #{server.inspect}" begin yield server, task ensure server.close end end end end
close()
click to toggle source
Close all the internal wrappers.
# File lib/async/io/shared_endpoint.rb, line 61 def close @wrappers.each(&:close) @wrappers.clear end
connect() { |peer, task| ... }
click to toggle source
# File lib/async/io/shared_endpoint.rb, line 84 def connect task = Async::Task.current @wrappers.each do |peer| peer = peer.dup task.async do |task| task.annotate "connected to #{peer.inspect} [#{peer.fileno}]" begin yield peer, task ensure peer.close end end end end
to_s()
click to toggle source
# File lib/async/io/shared_endpoint.rb, line 108 def to_s "\#<#{self.class} #{@wrappers.size} descriptors for #{@endpoint}>" end