Commit 4a025653 authored by Vincent Pelletier's avatar Vincent Pelletier

Move code outside of try block.

Cleanup actions are only appropriate if such exception happens in receive/
send, so it should not be applied to other possible sources of exceptions.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2020 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 72026f6d
...@@ -462,11 +462,6 @@ class Connection(BaseConnection): ...@@ -462,11 +462,6 @@ class Connection(BaseConnection):
"""Receive data from a connector.""" """Receive data from a connector."""
try: try:
data = self.connector.receive() data = self.connector.receive()
if not data:
logging.debug('Connection %r closed in recv', self.connector)
self._closure()
return
self.read_buf.append(data)
except ConnectorTryAgainException: except ConnectorTryAgainException:
pass pass
except ConnectorConnectionRefusedException: except ConnectorConnectionRefusedException:
...@@ -482,23 +477,21 @@ class Connection(BaseConnection): ...@@ -482,23 +477,21 @@ class Connection(BaseConnection):
self._closure() self._closure()
# unhandled connector exception # unhandled connector exception
raise raise
else:
if not data:
logging.debug('Connection %r closed in recv', self.connector)
self._closure()
return
self.read_buf.append(data)
@profiler_decorator @profiler_decorator
def _send(self): def _send(self):
"""Send data to a connector.""" """Send data to a connector."""
if not self.write_buf: if not self.write_buf:
return return
try:
msg = ''.join(self.write_buf) msg = ''.join(self.write_buf)
try:
n = self.connector.send(msg) n = self.connector.send(msg)
if not n:
logging.debug('Connection %r closed in send', self.connector)
self._closure()
return
if n == len(msg):
del self.write_buf[:]
else:
self.write_buf = [msg[n:]]
except ConnectorTryAgainException: except ConnectorTryAgainException:
pass pass
except ConnectorConnectionClosedException: except ConnectorConnectionClosedException:
...@@ -510,6 +503,15 @@ class Connection(BaseConnection): ...@@ -510,6 +503,15 @@ class Connection(BaseConnection):
# unhandled connector exception # unhandled connector exception
self._closure() self._closure()
raise raise
else:
if not n:
logging.debug('Connection %r closed in send', self.connector)
self._closure()
return
if n == len(msg):
del self.write_buf[:]
else:
self.write_buf = [msg[n:]]
@profiler_decorator @profiler_decorator
def _addPacket(self, packet): def _addPacket(self, packet):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment