class Async::IO::Socket
def self.bind(local_address, protocol: 0, reuse_port: nil, reuse_address: true, task: Task.current, **options, &block)
(**reuse_port)-
Allow(Boolean) -- this port to be bound in multiple processes. -
The(Integer) -- socket protocol to use.
Parameters:
-
local_address(Address) -- The local address to bind to.
def self.bind(local_address, protocol: 0, reuse_port: nil, reuse_address: true, task: Task.current, **options, &block) Async.logger.debug(self) {"Binding to #{local_address.inspect}"} wrapper = build(local_address.afamily, local_address.socktype, protocol, **options) do |socket| if reuse_address socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1) end if reuse_port socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, 1) end socket.bind(local_address.to_sockaddr) end return wrapper unless block_given? task.async do |task| task.annotate "binding to #{wrapper.local_address.inspect}" begin yield wrapper, task ensure wrapper.close end end end