[Neo-report] r2020 vincent - /trunk/neo/connection.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 23 18:36:07 CEST 2010
Author: vincent
Date: Fri Apr 23 18:36:07 2010
New Revision: 2020
Log:
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.
Modified:
trunk/neo/connection.py
Modified: trunk/neo/connection.py
==============================================================================
--- trunk/neo/connection.py [iso-8859-1] (original)
+++ trunk/neo/connection.py [iso-8859-1] Fri Apr 23 18:36:07 2010
@@ -462,11 +462,6 @@
"""Receive data from a connector."""
try:
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:
pass
except ConnectorConnectionRefusedException:
@@ -482,23 +477,21 @@
self._closure()
# unhandled connector exception
raise
+ else:
+ if not data:
+ logging.debug('Connection %r closed in recv', self.connector)
+ self._closure()
+ return
+ self.read_buf.append(data)
@profiler_decorator
def _send(self):
"""Send data to a connector."""
if not self.write_buf:
return
- try:
- msg = ''.join(self.write_buf)
+ msg = ''.join(self.write_buf)
+ try:
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:
pass
except ConnectorConnectionClosedException:
@@ -510,6 +503,15 @@
# unhandled connector exception
self._closure()
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
def _addPacket(self, packet):
More information about the Neo-report
mailing list