src/eric7/RemoteServerInterface/EricServerInterface.py

branch
server
changeset 10762
d141283f7334
parent 10723
88bec462b855
child 10764
5915ca2466b2
equal deleted inserted replaced
10761:63618ecdbe57 10762:d141283f7334
7 Module implementing the interface to the eric remote server. 7 Module implementing the interface to the eric remote server.
8 """ 8 """
9 9
10 import collections 10 import collections
11 import json 11 import json
12 import logging
12 import struct 13 import struct
14 import time
13 import uuid 15 import uuid
14 import zlib 16 import zlib
15 17
16 from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot 18 from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot
17 from PyQt6.QtGui import QAction, QKeySequence 19 from PyQt6.QtGui import QAction, QKeySequence
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")

eric ide

mercurial