Skip to content

Commit

Permalink
Refactor socket writing to not use sendall #481
Browse files Browse the repository at this point in the history
socket.sendall should not be used on non-blocking sockets.
  • Loading branch information
gmr committed Apr 29, 2015
1 parent 4838789 commit 7dc9bab
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pika/adapters/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,20 @@ def _handle_read(self):

def _handle_write(self):
"""Handle any outbound buffer writes that need to take place."""
bytes_written = 0
if self.outbound_buffer:
frame = self.outbound_buffer.popleft()
try:
self.socket.sendall(frame)
bytes_written = len(frame)
bytes_written = self.socket.send(frame)
if bytes_written < len(frame):
LOGGER.debug("Could not write the full frame")
self.outbound_buffer.appendleft(frame[bytes_written:])
return bytes_written
except socket.timeout:
self.outbound_buffer.appendleft(frame)
raise
except socket.error as error:
self.outbound_buffer.appendleft(frame)
return self._handle_error(error)
return bytes_written

def _init_connection_state(self):
"""Initialize or reset all of our internal state variables for a given
Expand Down

0 comments on commit 7dc9bab

Please sign in to comment.