Class: Cucumber::Chef::TCPSocket
- Inherits:
-
Object
- Object
- Cucumber::Chef::TCPSocket
- Defined in:
- lib/cucumber/chef/tcp_socket.rb
Instance Method Summary collapse
-
#initialize(host, port, data = nil) ⇒ TCPSocket
constructor
A new instance of TCPSocket.
- #ready? ⇒ Boolean
- #wait ⇒ Object
Constructor Details
#initialize(host, port, data = nil) ⇒ TCPSocket
Returns a new instance of TCPSocket.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cucumber/chef/tcp_socket.rb', line 31 def initialize(host, port, data=nil) @host, @port, @data = host, port, data if !host = "You must supply a host!" $logger.fatal { } if $logger raise TCPSocketError, end if !port = "You must supply a port!" $logger.fatal { } if $logger raise TCPSocketError, end end |
Instance Method Details
#ready? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cucumber/chef/tcp_socket.rb', line 49 def ready? socket = ::TCPSocket.new(@host, @port) if @data.nil? $logger.debug { "read(#{@host}:#{@port})" } if $logger ((::IO.select([socket], nil, nil, 5) && socket.gets) ? true : false) else $logger.debug { "write(#{@host}:#{@port}, '#{@data}')" } if $logger ((::IO.select(nil, [socket], nil, 5) && socket.write(@data)) ? true : false) end rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e $logger.debug { "#{@host}:#{@port} - #{e.}" } if $logger false ensure (socket && socket.close) end |
#wait ⇒ Object
69 70 71 72 73 74 |
# File 'lib/cucumber/chef/tcp_socket.rb', line 69 def wait begin success = ready? sleep(1) end until success end |