Use memoryview() on TcpClient.write() instead slicing the data

This commit is contained in:
Lonami Exo 2017-06-09 11:50:30 +02:00
parent c6645a555d
commit ba5bfa105f

View File

@ -50,9 +50,10 @@ class TcpClient:
# Ensure that only one thread can send data at once # Ensure that only one thread can send data at once
with self._lock: with self._lock:
total_sent = 0 view = memoryview(data)
while total_sent < len(data): total_sent, total = 0, len(data)
sent = self._socket.send(data[total_sent:]) while total_sent < total:
sent = self._socket.send(view[total_sent:])
if sent == 0: if sent == 0:
raise ConnectionResetError( raise ConnectionResetError(
'The server has closed the connection.') 'The server has closed the connection.')