Sha256: 117ea6d820e9e559e3fd297f5461f088522f93d643352dc186c0ae9eeb0ed4b8

Contents?: true

Size: 695 Bytes

Versions: 36

Compression:

Stored size: 695 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("173.194.113.176", 80, 5)
      true
    rescue
      false
    end
  end
end

Version data entries

36 entries across 34 versions & 6 rubygems

Version Path
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/webmock-1.21.0/spec/support/network_connection.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/webmock-1.21.0/spec/support/network_connection.rb
webmock-1.24.2 spec/support/network_connection.rb
webmock-1.24.1 spec/support/network_connection.rb
webmock-1.24.0 spec/support/network_connection.rb
webmock-1.23.0 spec/support/network_connection.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/webmock-1.20.4/spec/support/network_connection.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/webmock-1.20.4/spec/support/network_connection.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/webmock-1.20.4/spec/support/network_connection.rb
webmock-1.22.6 spec/support/network_connection.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/webmock-1.22.5/spec/support/network_connection.rb
webmock-1.22.5 spec/support/network_connection.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/webmock-1.22.3/spec/support/network_connection.rb
webmock-1.22.3 spec/support/network_connection.rb
webmock-1.22.2 spec/support/network_connection.rb
webmock-1.22.1 spec/support/network_connection.rb
webmock-1.21.0 spec/support/network_connection.rb
webmock-1.20.4 spec/support/network_connection.rb
webmock-1.20.3 spec/support/network_connection.rb
webmock-1.20.2 spec/support/network_connection.rb