Sha256: 85790de894f4e33e2f9bca053202746ffe4bfa47dce8d4c56e3483bdcd035c4d

Contents?: true

Size: 628 Bytes

Versions: 12

Compression:

Stored size: 628 Bytes

Contents

module Cute
  module Network
    require 'socket'

    def Network::port_open?(ip, port)
      begin
        s = TCPSocket.new(ip, port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT
        return false
      end
    end

    def Network::wait_open_port(host, port, timeout = 120)
      def now()
        return Time.now.to_f
      end
      bound = now() + timeout
      while now() < bound do
        t = now()
        return true if port_open?(host, port)
        dt = now() - t
        sleep(0.5 - dt) if dt < 0.5
      end
      return false
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby-cute-0.13 lib/cute/net.rb
ruby-cute-0.12 lib/cute/net.rb
ruby-cute-0.11 lib/cute/net.rb
ruby-cute-0.10 lib/cute/net.rb
ruby-cute-0.9 lib/cute/net.rb
ruby-cute-0.8 lib/cute/net.rb
ruby-cute-0.7 lib/cute/net.rb
ruby-cute-0.6 lib/cute/net.rb
ruby-cute-0.5 lib/cute/net.rb
ruby-cute-0.4 lib/cute/net.rb
ruby-cute-0.3 lib/cute/net.rb
ruby-cute-0.0.2 lib/cute/net.rb