Commit cf90e63e authored by Vincent Pelletier's avatar Vincent Pelletier

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.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2036 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent d7748d3c
...@@ -180,23 +180,17 @@ class Timeout(object): ...@@ -180,23 +180,17 @@ class Timeout(object):
""" Keep track of connection-level timeouts """ """ Keep track of connection-level timeouts """
def __init__(self): def __init__(self):
self.clear()
def clear(self):
"""
There is no pending request, reset ping times.
"""
self._ping_time = None self._ping_time = None
self._critical_time = None self._critical_time = None
def update(self, t): def update(self, t, force=False):
""" """
Send occurred: Send occurred:
- set ping time if earlier than existing one - set ping time if earlier than existing one
""" """
ping_time = self._ping_time ping_time = self._ping_time
t += PING_DELAY 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 self._ping_time = t
def refresh(self, t): def refresh(self, t):
...@@ -467,11 +461,7 @@ class Connection(BaseConnection): ...@@ -467,11 +461,7 @@ class Connection(BaseConnection):
""" """
# check out packet and process it with current handler # check out packet and process it with current handler
packet = self._queue.pop(0) packet = self._queue.pop(0)
handlers = self._handlers self._handlers.handle(packet)
handlers.handle(packet)
if not handlers.isPending():
# We are not expecting any other response, clear timeout
self._timeout.clear()
def pending(self): def pending(self):
return self.connector is not None and self.write_buf return self.connector is not None and self.write_buf
...@@ -576,7 +566,7 @@ class Connection(BaseConnection): ...@@ -576,7 +566,7 @@ class Connection(BaseConnection):
t = time() t = time()
# If there is no pending request, initialise timeout values. # If there is no pending request, initialise timeout values.
if not self._handlers.isPending(): if not self._handlers.isPending():
self._timeout.update(t) self._timeout.update(t, force=True)
self._handlers.emit(packet, t + timeout) self._handlers.emit(packet, t + timeout)
return msg_id return msg_id
......
...@@ -1027,8 +1027,8 @@ class TestTimeout(NeoTestBase): ...@@ -1027,8 +1027,8 @@ class TestTimeout(NeoTestBase):
self.assertEqual(soft, self.timeout.softExpired(at)) self.assertEqual(soft, self.timeout.softExpired(at))
self.assertEqual(hard, self.timeout.hardExpired(at)) self.assertEqual(hard, self.timeout.hardExpired(at))
def _updateAt(self, n): def _updateAt(self, n, force=False):
self.timeout.update(self.current + n) self.timeout.update(self.current + n, force=force)
def _refreshAt(self, n): def _refreshAt(self, n):
self.timeout.refresh(self.current + n) self.timeout.refresh(self.current + n)
...@@ -1055,9 +1055,8 @@ class TestTimeout(NeoTestBase): ...@@ -1055,9 +1055,8 @@ class TestTimeout(NeoTestBase):
self._checkAt(answer_time + PING_DELAY + 0.5, True, False) self._checkAt(answer_time + PING_DELAY + 0.5, True, False)
# if there is no more pending requests, a clear will happen so next # if there is no more pending requests, a clear will happen so next
# send doesn't immediately trigger a ping # send doesn't immediately trigger a ping
self.timeout.clear()
new_request_time = answer_time + PING_DELAY * 2 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, False, False)
self._checkAt(new_request_time + PING_DELAY + 0.5, True, False) self._checkAt(new_request_time + PING_DELAY + 0.5, True, False)
......
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