IO::EndpointSourceIOEndpointHostEndpoint

class HostEndpoint

Definitions

def connect(wrapper = Wrapper.default, &block)

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

Implementation

def connect(wrapper = Wrapper.default, &block)
	last_error = nil
	
	Addrinfo.foreach(*@specification) do |address|
		begin
			socket = wrapper.connect(address, **@options)
		rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EAGAIN => last_error
			# Try again unless if possible, otherwise raise...
		else
			return socket unless block_given?
			
			begin
				return yield(socket)
			ensure
				socket.close
			end
		end
	end
	
	raise last_error
end

def bind(wrapper = Wrapper.default, &block)

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

Implementation

def bind(wrapper = Wrapper.default, &block)
	Addrinfo.foreach(*@specification).map do |address|
		wrapper.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