Class: TCPSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/tcp_socket_extension.rb

Class Method Summary collapse

Class Method Details

.listening_service?(options) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tcp_socket_extension.rb', line 14

def self.listening_service?(options)
  Timeout::timeout(options[:timeout] || 20) do
    begin
      socket = TCPSocket.new(options[:host], options[:port])
      socket.close unless socket.nil?
      true
    rescue Errno::ECONNREFUSED, 
           Errno::EBADF           # Windows
      false
    end
  end
end

.verbose_waitObject


27
28
29
30
# File 'lib/tcp_socket_extension.rb', line 27

def self.verbose_wait
  puts ".\n"
  sleep 2
end

.wait_for_service(options) ⇒ Object


6
7
8
# File 'lib/tcp_socket_extension.rb', line 6

def self.wait_for_service(options)
  verbose_wait until listening_service?(options)
end

.wait_for_service_termination(options) ⇒ Object


10
11
12
# File 'lib/tcp_socket_extension.rb', line 10

def self.wait_for_service_termination(options)
  verbose_wait while listening_service?(options)
end