eric7/DebugClients/Python/AsyncFile.py

branch
eric7
changeset 8954
c8b027c654bc
parent 8881
54e42bc2437a
diff -r 3e8adcb59aad -r c8b027c654bc eric7/DebugClients/Python/AsyncFile.py
--- a/eric7/DebugClients/Python/AsyncFile.py	Sun Feb 20 17:38:10 2022 +0100
+++ b/eric7/DebugClients/Python/AsyncFile.py	Mon Feb 21 17:39:06 2022 +0100
@@ -36,7 +36,10 @@
     """
     Class wrapping a socket object with a file interface.
     """
-    maxtries = 10
+    MAX_TRIES = 10
+    
+    BUFSIZE = 2 ** 14           # 16 kBytes
+    CMD_BUFSIZE = 2 ** 12       # 4 kBytes
     
     def __init__(self, sock, mode, name):
         """
@@ -117,7 +120,7 @@
                 self.nWriteErrors = 0
             except OSError:
                 self.nWriteErrors += 1
-                if self.nWriteErrors > self.maxtries:
+                if self.nWriteErrors > AsyncFile.MAX_TRIES:
                     self.wpending = []    # delete all output
         self.writeLock.release()
 
@@ -163,7 +166,7 @@
         self.__checkMode('r')
 
         if size < 0:
-            size = 20000
+            size = AsyncFile.BUFSIZE
 
         return self.sock.recv(size).decode('utf8', 'backslashreplace')
 
@@ -195,9 +198,10 @@
         length = int(length)
         data = b''
         while len(data) < length:
-            newByte = self.sock.recv(1)
-            data += newByte
-            if newByte == b'\n':
+            remaining = length - len(data)
+            newBytes = self.sock.recv(min(remaining, AsyncFile.CMD_BUFSIZE))
+            data += newBytes
+            if newBytes[-1] == b'\n':
                 break
         
         # step 2: convert the data
@@ -218,7 +222,7 @@
         self.__checkMode('r')
 
         if size < 0:
-            size = 20000
+            size = AsyncFile.BUFSIZE
 
         # The integration of the debugger client event loop and the connection
         # to the debugger relies on the two lines of the debugger command being

eric ide

mercurial