parent
6fe5414f92
commit
4a2c6c7624
|
|
@ -356,32 +356,38 @@ class IPCServer(QObject):
|
|||
|
||||
self.got_args.emit(args, target_arg, cwd)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_ready_read(self):
|
||||
"""Read json data from the client."""
|
||||
def _get_socket(self):
|
||||
"""Get the current socket for on_ready_read."""
|
||||
if self._socket is None: # pragma: no cover
|
||||
# This happens when doing a connection while another one is already
|
||||
# active for some reason.
|
||||
if self._old_socket is None:
|
||||
log.ipc.warning("In on_ready_read with None socket and "
|
||||
"old_socket!")
|
||||
return
|
||||
log.ipc.debug("In on_ready_read with None socket!")
|
||||
log.ipc.warning("In _get_socket with None socket and old_socket!")
|
||||
return None
|
||||
log.ipc.debug("In _get_socket with None socket!")
|
||||
socket = self._old_socket
|
||||
else:
|
||||
socket = self._socket
|
||||
|
||||
if sip.isdeleted(socket): # pragma: no cover
|
||||
log.ipc.warning("Ignoring deleted IPC socket")
|
||||
return
|
||||
return None
|
||||
|
||||
return socket
|
||||
|
||||
@pyqtSlot()
|
||||
def on_ready_read(self):
|
||||
"""Read json data from the client."""
|
||||
self._timer.stop()
|
||||
|
||||
socket = self._get_socket()
|
||||
while socket is not None and socket.canReadLine():
|
||||
data = bytes(socket.readLine())
|
||||
self.got_raw.emit(data)
|
||||
log.ipc.debug("Read from socket 0x{:x}: {!r}".format(
|
||||
id(socket), data))
|
||||
self._handle_data(data)
|
||||
socket = self._get_socket()
|
||||
|
||||
if self._socket is not None:
|
||||
self._timer.start()
|
||||
|
|
|
|||
|
|
@ -605,7 +605,7 @@ def test_ipcserver_socket_none_readyread(ipc_server, caplog):
|
|||
assert ipc_server._old_socket is None
|
||||
with caplog.at_level(logging.WARNING):
|
||||
ipc_server.on_ready_read()
|
||||
msg = "In on_ready_read with None socket and old_socket!"
|
||||
msg = "In _get_socket with None socket and old_socket!"
|
||||
assert msg in caplog.messages
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue