Split IPCServer.on_ready_read into two methods
This commit is contained in:
parent
7c3361d8da
commit
fd20b46b33
@ -288,21 +288,8 @@ class IPCServer(QObject):
|
|||||||
self._socket.error.connect(self.on_error)
|
self._socket.error.connect(self.on_error)
|
||||||
self._socket.disconnectFromServer()
|
self._socket.disconnectFromServer()
|
||||||
|
|
||||||
@pyqtSlot()
|
def _handle_data(self, data):
|
||||||
def on_ready_read(self):
|
"""Handle data (as bytes) we got from on_ready_ready_read."""
|
||||||
"""Read json data from the client."""
|
|
||||||
if self._socket is None:
|
|
||||||
# This happens when doing a connection while another one is already
|
|
||||||
# active for some reason.
|
|
||||||
log.ipc.warning("In on_ready_read with None socket!")
|
|
||||||
return
|
|
||||||
self._timer.stop()
|
|
||||||
while self._socket is not None and self._socket.canReadLine():
|
|
||||||
data = bytes(self._socket.readLine())
|
|
||||||
self.got_raw.emit(data)
|
|
||||||
log.ipc.debug("Read from socket 0x{:x}: {}".format(
|
|
||||||
id(self._socket), data))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decoded = data.decode('utf-8')
|
decoded = data.decode('utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
@ -321,8 +308,7 @@ class IPCServer(QObject):
|
|||||||
|
|
||||||
for name in ('args', 'target_arg'):
|
for name in ('args', 'target_arg'):
|
||||||
if name not in json_data:
|
if name not in json_data:
|
||||||
log.ipc.error("Missing {}: {}".format(name,
|
log.ipc.error("Missing {}: {}".format(name, decoded.strip()))
|
||||||
decoded.strip()))
|
|
||||||
self._handle_invalid_data()
|
self._handle_invalid_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -334,8 +320,7 @@ class IPCServer(QObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if protocol_version != PROTOCOL_VERSION:
|
if protocol_version != PROTOCOL_VERSION:
|
||||||
log.ipc.error("incompatible version: expected {}, "
|
log.ipc.error("incompatible version: expected {}, got {}".format(
|
||||||
"got {}".format(
|
|
||||||
PROTOCOL_VERSION, protocol_version))
|
PROTOCOL_VERSION, protocol_version))
|
||||||
self._handle_invalid_data()
|
self._handle_invalid_data()
|
||||||
return
|
return
|
||||||
@ -351,6 +336,22 @@ class IPCServer(QObject):
|
|||||||
assert cwd is not None
|
assert cwd is not None
|
||||||
|
|
||||||
self.got_args.emit(args, target_arg, cwd)
|
self.got_args.emit(args, target_arg, cwd)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def on_ready_read(self):
|
||||||
|
"""Read json data from the client."""
|
||||||
|
if self._socket is None:
|
||||||
|
# This happens when doing a connection while another one is already
|
||||||
|
# active for some reason.
|
||||||
|
log.ipc.warning("In on_ready_read with None socket!")
|
||||||
|
return
|
||||||
|
self._timer.stop()
|
||||||
|
while self._socket is not None and self._socket.canReadLine():
|
||||||
|
data = bytes(self._socket.readLine())
|
||||||
|
self.got_raw.emit(data)
|
||||||
|
log.ipc.debug("Read from socket 0x{:x}: {}".format(
|
||||||
|
id(self._socket), data))
|
||||||
|
self._handle_data(data)
|
||||||
self._timer.start()
|
self._timer.start()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
|
Loading…
Reference in New Issue
Block a user