lib/io/endpoint/host_endpoint.rb in io-endpoint-0.2.0 vs lib/io/endpoint/host_endpoint.rb in io-endpoint-0.3.0

- old
+ new

@@ -21,22 +21,26 @@ attr :specification def hostname - @specification.first + @specification[0] end + def service + @specification[1] + end + # Try to connect to the given host by connecting to each address in sequence until a connection is made. # @yield [Socket] the socket which is being connected, may be invoked more than once # @return [Socket] the connected socket # @raise if no connection could complete successfully def connect(wrapper = Wrapper.default, &block) last_error = nil Addrinfo.foreach(*@specification) do |address| begin - socket = wrapper.connect(@address, **@options) + 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?