Class: IO::Endpoint::HostEndpoint

Inherits:
Generic
  • Object
show all
Defined in:
lib/ruby_llm.rb

Instance Method Summary collapse

Instance Method Details

#connect(wrapper = self.wrapper, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_llm.rb', line 20

def connect(wrapper = self.wrapper, &block)
  last_error = nil

  Addrinfo.foreach(*@specification) do |address|
    begin
      socket = wrapper.connect(address, **@options)
    rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EHOSTUNREACH, Errno::EAGAIN => last_error
      # Try next address
    else
      return socket unless block_given?

      begin
        return yield(socket)
      ensure
        socket.close
      end
    end
  end

  raise last_error
end