Class: TCPSocket
- Inherits:
-
Object
- Object
- TCPSocket
- Defined in:
- lib/tcpsocket-wait.rb
Overview
Stolen from selenium and webrat.
Class Method Summary collapse
- .listening_service?(options) ⇒ Boolean
- .wait_for_service_termination_with_timeout(options) ⇒ Object
- .wait_for_service_with_timeout(options) ⇒ Object
Class Method Details
.listening_service?(options) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tcpsocket-wait.rb', line 27 def self.listening_service?() Timeout::timeout([:timeout] || 20) do begin socket = TCPSocket.new([:host], [:port]) socket.close unless socket.nil? true rescue Errno::ECONNREFUSED, Errno::EBADF # Windows false end end end |
.wait_for_service_termination_with_timeout(options) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tcpsocket-wait.rb', line 17 def self.wait_for_service_termination_with_timeout() start_time = Time.now while listening_service?() if [:timeout] && (Time.now > start_time + [:timeout]) raise SocketError.new("Socket did not terminate within #{[:timeout]} seconds") end end end |
.wait_for_service_with_timeout(options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tcpsocket-wait.rb', line 6 def self.wait_for_service_with_timeout() start_time = Time.now until listening_service?() if [:timeout] && (Time.now > start_time + [:timeout]) raise SocketError.new("Socket did not open within #{[:timeout]} seconds") end end end |