diff --git a/lib/async/io/endpoint.rb b/lib/async/io/endpoint.rb index 4bba68b..1e0db12 100644 --- a/lib/async/io/endpoint.rb +++ b/lib/async/io/endpoint.rb @@ -78,23 +78,6 @@ def accept(backlog = Socket::SOMAXCONN, &block) end end - # Map all endpoints by invoking `#bind`. - # @yield the bound wrapper. - def bound - wrappers = [] - - self.each do |endpoint| - wrapper = endpoint.bind - wrappers << wrapper - - yield wrapper - end - - return wrappers - ensure - wrappers.each(&:close) if $! - end - # 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. # # @param string [String] URI as string. Scheme will decide implementation used. diff --git a/lib/async/io/shared_endpoint.rb b/lib/async/io/shared_endpoint.rb index 1e4db51..75018eb 100644 --- a/lib/async/io/shared_endpoint.rb +++ b/lib/async/io/shared_endpoint.rb @@ -12,8 +12,10 @@ module IO # Pre-connect and pre-bind sockets so that it can be used between processes. class SharedEndpoint < Endpoint # Create a new `SharedEndpoint` by binding to the given endpoint. - def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false) - wrappers = endpoint.bound do |server| + def self.bound(endpoint, backlog: Socket::SOMAXCONN, close_on_exec: false, **options) + sockets = Array(endpoint.bind(**options)) + + wrappers = sockets.each do |server| # This is somewhat optional. We want to have a generic interface as much as possible so that users of this interface can just call it without knowing a lot of internal details. Therefore, we ignore errors here if it's because the underlying socket does not support the operation. begin server.listen(backlog) @@ -117,5 +119,15 @@ def to_s "\#<#{self.class} #{@wrappers.size} descriptors for #{@endpoint}>" end end + + class Endpoint + def bound(**options) + SharedEndpoint.bound(self, **options) + end + + def connected(**options) + SharedEndpoint.connected(self, **options) + end + end end end diff --git a/lib/async/io/ssl_endpoint.rb b/lib/async/io/ssl_endpoint.rb index 17f8ca4..b088ee7 100644 --- a/lib/async/io/ssl_endpoint.rb +++ b/lib/async/io/ssl_endpoint.rb @@ -65,7 +65,9 @@ def bind yield SSLServer.new(server, context) end else - return SSLServer.new(@endpoint.bind, context) + @endpoint.bind.map do |server| + SSLServer.new(server, context) + end end end