Sha256: dafa976d01d20cf4d69f4a07ef094d77cf68e2b89d6bf3d68157be6aa91afed5

Contents?: true

Size: 879 Bytes

Versions: 34

Compression:

Stored size: 879 Bytes

Contents

module PoolParty
  module Pinger
    module ClassMethods
      # Test to see if the host has the available port open
      # for response. 
      def ping_port(host, port=22, retry_times=400)
        connected = false
        retry_times.times do |i|
          begin
            break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
          rescue Exception => e
            sleep(2)
          end
        end
        connected
      end
    end
  
    module InstanceMethods
      def ping_port(ip, port=22, retry_times=500);self.class.ping_port(ip, port, retry_times);end
      def ping_port_and(ip, port=22, retry_times=500, &block)        
        block.call if ping_port(ip, port, retry_times) && block
      end
    end
  
    def self.included(receiver)
      receiver.extend         ClassMethods
      receiver.send :include, InstanceMethods
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
auser-poolparty-1.2.10 lib/poolparty/modules/pinger.rb
auser-poolparty-1.2.3 lib/poolparty/modules/pinger.rb
auser-poolparty-1.2.4 lib/poolparty/modules/pinger.rb
auser-poolparty-1.2.7 lib/poolparty/modules/pinger.rb
auser-poolparty-1.2.8 lib/poolparty/modules/pinger.rb
auser-poolparty-1.2.9 lib/poolparty/modules/pinger.rb
auser-poolparty-1.3.0 lib/mixins/pinger.rb
auser-poolparty-1.3.1 lib/mixins/pinger.rb
auser-poolparty-1.3.10 lib/mixins/pinger.rb
auser-poolparty-1.3.11 lib/mixins/pinger.rb
auser-poolparty-1.3.12 lib/mixins/pinger.rb
auser-poolparty-1.3.13 lib/mixins/pinger.rb
auser-poolparty-1.3.14 lib/mixins/pinger.rb
auser-poolparty-1.3.15 lib/mixins/pinger.rb
auser-poolparty-1.3.16 lib/mixins/pinger.rb
auser-poolparty-1.3.17 lib/mixins/pinger.rb
auser-poolparty-1.3.2 lib/mixins/pinger.rb
auser-poolparty-1.3.3 lib/mixins/pinger.rb
auser-poolparty-1.3.4 lib/mixins/pinger.rb
auser-poolparty-1.3.5 lib/mixins/pinger.rb