Class: Kitchen::Driver::QMPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/driver/qmpclient.rb

Defined Under Namespace

Classes: Timeout

Instance Method Summary collapse

Constructor Details

#initialize(io, timeout = 1) ⇒ QMPClient

Returns a new instance of QMPClient.



26
27
28
29
30
31
32
33
34
# File 'lib/kitchen/driver/qmpclient.rb', line 26

def initialize(io, timeout = 1)
  @io = io
  @ioa = [ io ]
  @timeout = timeout
  @buf = []
  readnext(timeout) or raise Timeout
  execute('qmp_capabilities') or raise Timeout
  self
end

Instance Method Details

#closeObject



61
62
63
# File 'lib/kitchen/driver/qmpclient.rb', line 61

def close
  @io.close
end

#execute(cmd, timeout = @timeout) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/kitchen/driver/qmpclient.rb', line 36

def execute(cmd, timeout = @timeout)
  send( 'execute' => cmd )
  loop do
    ret = readnext(timeout) or raise Timeout
    if ret['return']
      return ret['return']
    end
  end
end

#wait_for_eof(timeout = @timeout) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kitchen/driver/qmpclient.rb', line 46

def wait_for_eof(timeout = @timeout)
  while IO.select(@ioa, nil, nil, timeout)
    begin
      loop { @io.read_nonblock(4096) }
    rescue EOFError
      return
    rescue Errno::ECONNRESET
      return
    rescue IO::WaitReadable
      # do nothing
    end
  end
  raise Timeout
end