260 @pyqtSlot() |
262 @pyqtSlot() |
261 def __receiveJson(self): |
263 def __receiveJson(self): |
262 """ |
264 """ |
263 Private slot handling received data from the eric remote server. |
265 Private slot handling received data from the eric remote server. |
264 """ |
266 """ |
|
267 headerSize = struct.calcsize(b"!II") |
|
268 |
265 while self.__connection and self.__connection.bytesAvailable(): |
269 while self.__connection and self.__connection.bytesAvailable(): |
|
270 now = time.monotonic() |
|
271 while self.__connection.bytesAvailable() < headerSize: |
|
272 self.__connection.waitForReadyRead(50) |
|
273 if time.monotonic() - now > 2.0: # 2 seconds timeout |
|
274 return |
266 header = self.__connection.read(struct.calcsize(b"!II")) |
275 header = self.__connection.read(struct.calcsize(b"!II")) |
267 length, datahash = struct.unpack(b"!II", header) |
276 length, datahash = struct.unpack(b"!II", header) |
268 |
277 |
269 data = bytearray() |
278 data = bytearray() |
270 while len(data) < length: |
279 while len(data) < length: |
282 # corrupted data -> discard and continue |
291 # corrupted data -> discard and continue |
283 continue |
292 continue |
284 |
293 |
285 jsonString = data.decode("utf-8", "backslashreplace") |
294 jsonString = data.decode("utf-8", "backslashreplace") |
286 |
295 |
|
296 logging.getLogger(__name__).debug( |
|
297 f"<Remote Server Interface Rx> {jsonString}" |
|
298 ) |
287 # - print("Remote Server Interface Receive: {0}".format(jsonString)) |
299 # - print("Remote Server Interface Receive: {0}".format(jsonString)) |
288 # - this is for debugging only |
300 # - this is for debugging only |
289 |
301 |
290 try: |
302 try: |
291 serverDataDict = json.loads(jsonString.strip()) |
303 serverDataDict = json.loads(jsonString.strip()) |
365 "params": params, |
377 "params": params, |
366 "uuid": reqUuid, |
378 "uuid": reqUuid, |
367 } |
379 } |
368 jsonString = json.dumps(serviceDict) + "\n" |
380 jsonString = json.dumps(serviceDict) + "\n" |
369 |
381 |
|
382 logging.getLogger(__name__).debug( |
|
383 f"<Remote Server Interface Tx> {jsonString}" |
|
384 ) |
370 # - print("Remote Server Interface Send: {0}".format(jsonString)) |
385 # - print("Remote Server Interface Send: {0}".format(jsonString)) |
371 # - this is for debugging only |
386 # - this is for debugging only |
372 |
387 |
373 if self.__connection is not None: |
388 if self.__connection is not None: |
374 data = jsonString.encode("utf8", "backslashreplace") |
389 data = jsonString.encode("utf8", "backslashreplace") |