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
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.
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
yield msg.decode()
except UnicodeDecodeError:
yield None
- data = data[cut_off:]
msg = b''
else:
msg += bytes([c])