[Neo-report] r2036 vincent - in /trunk/neo: connection.py tests/testConnection.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Apr 28 15:27:58 CEST 2010


Author: vincent
Date: Wed Apr 28 15:27:58 2010
New Revision: 2036

Log:
Rework r2033: clear timeout before sending.

This simplifies code (and I should have done it this way from the
beginning).
Keep the lock check wrapper in MT subclass as it should have been added in
r2025 anyway.

Modified:
    trunk/neo/connection.py
    trunk/neo/tests/testConnection.py

Modified: trunk/neo/connection.py
==============================================================================
--- trunk/neo/connection.py [iso-8859-1] (original)
+++ trunk/neo/connection.py [iso-8859-1] Wed Apr 28 15:27:58 2010
@@ -180,23 +180,17 @@
     """ Keep track of connection-level timeouts """
 
     def __init__(self):
-        self.clear()
-
-    def clear(self):
-        """
-        There is no pending request, reset ping times.
-        """
         self._ping_time = None
         self._critical_time = None
 
-    def update(self, t):
+    def update(self, t, force=False):
         """
         Send occurred:
         - set ping time if earlier than existing one
         """
         ping_time = self._ping_time
         t += PING_DELAY
-        if ping_time is None or t < ping_time:
+        if force or ping_time is None or t < ping_time:
             self._ping_time = t
 
     def refresh(self, t):
@@ -467,11 +461,7 @@
         """
         # check out packet and process it with current handler
         packet = self._queue.pop(0)
-        handlers = self._handlers
-        handlers.handle(packet)
-        if not handlers.isPending():
-            # We are not expecting any other response, clear timeout
-            self._timeout.clear()
+        self._handlers.handle(packet)
 
     def pending(self):
         return self.connector is not None and self.write_buf
@@ -576,7 +566,7 @@
         t = time()
         # If there is no pending request, initialise timeout values.
         if not self._handlers.isPending():
-            self._timeout.update(t)
+            self._timeout.update(t, force=True)
         self._handlers.emit(packet, t + timeout)
         return msg_id
 

Modified: trunk/neo/tests/testConnection.py
==============================================================================
--- trunk/neo/tests/testConnection.py [iso-8859-1] (original)
+++ trunk/neo/tests/testConnection.py [iso-8859-1] Wed Apr 28 15:27:58 2010
@@ -1027,8 +1027,8 @@
         self.assertEqual(soft, self.timeout.softExpired(at))
         self.assertEqual(hard, self.timeout.hardExpired(at))
 
-    def _updateAt(self, n):
-        self.timeout.update(self.current + n)
+    def _updateAt(self, n, force=False):
+        self.timeout.update(self.current + n, force=force)
 
     def _refreshAt(self, n):
         self.timeout.refresh(self.current + n)
@@ -1055,9 +1055,8 @@
         self._checkAt(answer_time + PING_DELAY + 0.5, True, False)
         # if there is no more pending requests, a clear will happen so next
         # send doesn't immediately trigger a ping
-        self.timeout.clear()
         new_request_time = answer_time + PING_DELAY * 2
-        self._updateAt(new_request_time)
+        self._updateAt(new_request_time, force=True)
         self._checkAt(new_request_time + PING_DELAY - 0.5, False, False)
         self._checkAt(new_request_time + PING_DELAY + 0.5, True, False)
 





More information about the Neo-report mailing list