diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-10-09 15:40:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-10-09 15:40:40 +0000 |
commit | c4a5decdc68cb04a9e79435eef21f028a96ce035 (patch) | |
tree | 1cfac5a4065401710f755adfb7d1ed6ff82a8b84 | |
parent | ca4666f005735078727c5158c518031c9f09c72b (diff) | |
parent | b24b4d2f6ee27efcf293db87423b901cedac3d7b (diff) | |
download | gear-0.10.1.tar.gz |
Merge "Add a send lock to the base Connection class"0.10.1
-rw-r--r-- | gear/__init__.py | 24 |
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. |