Sha256: 61bd6fdde1c06061069727b3dbcf7ac89a0c14666c65a4ea6f0fa1ceb362c5ba

Contents?: true

Size: 691 Bytes

Versions: 40

Compression:

Stored size: 691 Bytes

Contents

module NetworkConnection
  def self.connect_to(host, port, timeout=nil)
    addr = Socket.getaddrinfo(host, nil)
    sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)

    if timeout
      secs = Integer(timeout)
      usecs = Integer((timeout - secs) * 1_000_000)
      optval = [secs, usecs].pack("l_2")
      sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
      sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
    end
    sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
    sock
  end

  def self.is_network_available?
    begin
      self.connect_to("192.0.32.10", 80, 5)
      true
    rescue
      false
    end
  end
end

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/webmock-1.8.11/spec/support/network_connection.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/webmock-1.8.11/spec/support/network_connection.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/webmock-1.8.11/spec/support/network_connection.rb
webmock-1.13.0 spec/support/network_connection.rb
webmock-1.12.3 spec/support/network_connection.rb
webmock-1.12.2 spec/support/network_connection.rb
webmock-1.12.1 spec/support/network_connection.rb
webmock-1.12.0 spec/support/network_connection.rb
webmock-1.11.0 spec/support/network_connection.rb
webmock-1.10.2 spec/support/network_connection.rb
webmock-1.10.1 spec/support/network_connection.rb
webmock-1.10.0 spec/support/network_connection.rb
webmock-1.9.3 spec/support/network_connection.rb
webmock-1.9.2 spec/support/network_connection.rb
webmock-1.9.1 spec/support/network_connection.rb
simple-client-0.0.3 vendor/bundle/ruby/1.9.1/gems/webmock-1.8.8/spec/support/network_connection.rb
webmock-1.9.0 spec/support/network_connection.rb
webmock-1.8.11 spec/support/network_connection.rb
webmock-1.8.10 spec/support/network_connection.rb
webmock-1.8.9 spec/support/network_connection.rb