src/eric7/EricNetwork/EricJsonServer.py

branch
eric7
changeset 10697
8a609e4c71b6
parent 10524
ed4fd87c4d4c
child 10928
46651e194fbe
diff -r 55e4a7497833 -r 8a609e4c71b6 src/eric7/EricNetwork/EricJsonServer.py
--- a/src/eric7/EricNetwork/EricJsonServer.py	Wed Apr 24 15:15:33 2024 +0200
+++ b/src/eric7/EricNetwork/EricJsonServer.py	Wed Apr 24 15:16:12 2024 +0200
@@ -10,6 +10,7 @@
 import contextlib
 import json
 import struct
+import time
 import zlib
 
 from PyQt6.QtCore import (
@@ -149,6 +150,8 @@
         @param idString id of the connection
         @type str
         """
+        headerSize = struct.calcsize(b"!II")
+
         if idString:
             try:
                 connection = self.__connections[idString]
@@ -158,15 +161,26 @@
             connection = self.__connection
 
         while connection and connection.bytesAvailable():
-            header = connection.read(struct.calcsize(b"!II"))
+            now = time.monotonic()
+            while connection.bytesAvailable() < headerSize:
+                connection.waitForReadyRead(50)
+                if time.monotonic() - now > 2.0:  # 2 seconds timeout
+                    return
+            header = connection.read(headerSize)
             length, datahash = struct.unpack(b"!II", header)
 
             data = bytearray()
+            now = time.monotonic()
             while len(data) < length:
                 maxSize = length - len(data)
                 if connection.bytesAvailable() < maxSize:
                     connection.waitForReadyRead(50)
-                data += connection.read(maxSize)
+                newData = connection.read(maxSize)
+                if newData:
+                    data += newData
+                else:
+                    if time.monotonic() - now > 2.0:  # 2 seconds timeout
+                        break
 
             if zlib.adler32(data) & 0xFFFFFFFF != datahash:
                 # corrupted data -> discard and continue

eric ide

mercurial