summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gear/__init__.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/gear/__init__.py b/gear/__init__.py
index 435f8ed..28fef6a 100644
--- a/gear/__init__.py
+++ b/gear/__init__.py
@@ -142,6 +142,7 @@ class Connection(object):
self.input_buffer = b''
self.need_bytes = False
self.echo_lock = threading.Lock()
+ self.send_lock = threading.Lock()
self._init()
def _init(self):
@@ -237,17 +238,18 @@ class Connection(object):
:arg bytes data The raw data to send
"""
- while True:
- try:
- self.conn.send(data)
- except ssl.SSLError as e:
- if e.errno == ssl.SSL_ERROR_WANT_READ:
- continue
- elif e.errno == ssl.SSL_ERROR_WANT_WRITE:
- continue
- else:
- raise
- break
+ with self.send_lock:
+ sent = 0
+ while sent < len(data):
+ try:
+ sent += self.conn.send(data)
+ except ssl.SSLError as e:
+ if e.errno == ssl.SSL_ERROR_WANT_READ:
+ continue
+ elif e.errno == ssl.SSL_ERROR_WANT_WRITE:
+ continue
+ else:
+ raise
def sendPacket(self, packet):
"""Send a packet to the server.