Async::IO SourceAsyncIOHostEndpoint

class HostEndpoint

Definitions

def connect

Try to connect to the given host by connecting to each address in sequence until a connection is made.

Implementation

def connect
	last_error = nil
	
	task = Task.current
	
	Addrinfo.foreach(*@specification) do |address|
		begin
			wrapper = Socket.connect(address, **@options, task: task)
		rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EAGAIN
			last_error = $!
		else
			return wrapper unless block_given?
			
			begin
				return yield wrapper, task
			ensure
				wrapper.close
			end
		end
	end
	
	raise last_error
end

def bind(&block)

Invokes the given block for every address which can be bound to.

Implementation

def bind(&block)
	Addrinfo.foreach(*@specification).map do |address|
		Socket.bind(address, **@options, &block)
	end
end

def each

Implementation

def each
	return to_enum unless block_given?
	
	Addrinfo.foreach(*@specification) do |address|
		yield AddressEndpoint.new(address, **@options)
	end
end