123456789_123456789_123456789_123456789_123456789_

Class: Bundler::Settings::TCPSocketProbe

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/mirror.rb

Overview

Class used for probing TCP availability for a given mirror.

Instance Method Summary

Instance Method Details

#probe_writtable_socket(socket) (private)

[ GitHub ]

  
# File 'lib/bundler/mirror.rb', line 169

def probe_writtable_socket(socket)
  # Check the pending error on the socket rather than calling
  # connect_nonblock a second time. On BSD-based systems such as macOS a
  # second connect returns EISCONN even when the asynchronous connect
  # failed, which would make a down mirror look reachable.
  socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).int == 0
end

#replies?(mirror) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/mirror.rb', line 149

def replies?(mirror)
  MirrorSockets.new(mirror).any? do |socket, address, timeout|
    socket.connect_nonblock(address)
  rescue Errno::EINPROGRESS
    wait_for_writtable_socket(socket, address, timeout)
  rescue RuntimeError # Connection failed somehow, again
    false
  end
end

#wait_for_writtable_socket(socket, address, timeout) (private)

[ GitHub ]

  
# File 'lib/bundler/mirror.rb', line 161

def wait_for_writtable_socket(socket, address, timeout)
  if IO.select(nil, [socket], nil, timeout)
    probe_writtable_socket(socket)
  else # TCP Handshake timed out, or there is something dropping packets
    false
  end
end