From 31d5ee2ee37c0e82e776053a1311c99dda2255e7 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 4 Nov 2020 01:17:20 +0100
Subject: [PATCH] Fix/simplify PlomSocket code.

---
 new2/plomrogue/io_tcp.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/new2/plomrogue/io_tcp.py b/new2/plomrogue/io_tcp.py
index 203021c..f0a49a9 100644
--- a/new2/plomrogue/io_tcp.py
+++ b/new2/plomrogue/io_tcp.py
@@ -46,6 +46,7 @@ class PlomSocket:
             try:
                 sent = self.socket.send(data[totalsent:])
                 socket_broken = sent == 0
+                totalsent = totalsent + sent
             except OSError as err:
                 if err.errno == 9:  # "Bad file descriptor", when connection broken
                     socket_broken = True
@@ -53,7 +54,6 @@ class PlomSocket:
                     raise err
             if socket_broken and not silent_connection_break:
                 raise BrokenSocketConnection
-            totalsent = totalsent + sent
 
     def recv(self):
         """Get full send()-prepared message from self.socket.
@@ -77,12 +77,10 @@ class PlomSocket:
         data = b''
         msg = b''
         while True:
-            data += self.socket.recv(1024)
+            data = self.socket.recv(1024)
             if 0 == len(data):
-                return
-            cut_off = 0
+                break
             for c in data:
-                cut_off += 1
                 if esc:
                     msg += bytes([c])
                     esc = False
@@ -93,7 +91,6 @@ class PlomSocket:
                         yield msg.decode()
                     except UnicodeDecodeError:
                         yield None
-                    data = data[cut_off:]
                     msg = b''
                 else:
                     msg += bytes([c])
-- 
2.30.2