3 # Copyright (C) 2015 Red Hat Inc.
8 # This work is licensed under the terms of the GNU GPL, version 2. See
9 # the COPYING file in the top-level directory.
17 class QEMUQtestProtocol(object):
18 def __init__(self, address, server=False):
20 Create a QEMUQtestProtocol object.
22 @param address: QEMU address, can be either a unix socket path (string)
23 or a tuple in the form ( address, port ) for a TCP
25 @param server: server mode, listens on the socket (bool)
26 @raise socket.error on socket connection errors
27 @note No connection is established, this is done by the connect() or
30 self._address = address
31 self._sock = self._get_sock()
33 self._sock.bind(self._address)
37 if isinstance(self._address, tuple):
38 family = socket.AF_INET
40 family = socket.AF_UNIX
41 return socket.socket(family, socket.SOCK_STREAM)
45 Connect to the qtest socket.
47 @raise socket.error on socket connection errors
49 self._sock.connect(self._address)
53 Await connection from QEMU.
55 @raise socket.error on socket connection errors
57 self._sock, _ = self._sock.accept()
59 def cmd(self, qtest_cmd):
61 Send a qtest command on the wire.
63 @param qtest_cmd: qtest command text to be sent
65 self._sock.sendall(qtest_cmd + "\n")
70 def settimeout(self, timeout):
71 self._sock.settimeout(timeout)