diff options
| author | Kim van der Riet <kpvdr@apache.org> | 2009-07-13 15:00:58 +0000 |
|---|---|---|
| committer | Kim van der Riet <kpvdr@apache.org> | 2009-07-13 15:00:58 +0000 |
| commit | 15daf8342812786490f8a8dabcc5ba3cee8593e6 (patch) | |
| tree | 69ce95f978a7c6b7cfded0f025ffce7b1dd5d220 /cpp/src/qpid/broker/Connection.cpp | |
| parent | b7ec99208bb38dc0cad3a7fd42b8e652610a192a (diff) | |
| download | qpid-python-15daf8342812786490f8a8dabcc5ba3cee8593e6.tar.gz | |
Reverted checkins 793119, 793120, 793121, 793122 because of problems with heartbeats and the store tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@793602 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/Connection.cpp')
| -rw-r--r-- | cpp/src/qpid/broker/Connection.cpp | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/cpp/src/qpid/broker/Connection.cpp b/cpp/src/qpid/broker/Connection.cpp index c0e9429ba9..a54bcc6db9 100644 --- a/cpp/src/qpid/broker/Connection.cpp +++ b/cpp/src/qpid/broker/Connection.cpp @@ -49,25 +49,35 @@ namespace _qmf = qmf::org::apache::qpid::broker; namespace qpid { namespace broker { -struct ConnectionTimeoutTask : public sys::TimerTask { - sys::Timer& timer; +struct ConnectionTimeoutTask : public TimerTask { + Timer& timer; Connection& connection; + AbsTime expires; - ConnectionTimeoutTask(uint16_t hb, sys::Timer& t, Connection& c) : + ConnectionTimeoutTask(uint16_t hb, Timer& t, Connection& c) : TimerTask(Duration(hb*2*TIME_SEC)), timer(t), - connection(c) + connection(c), + expires(AbsTime::now(), duration) {} - void touch() { - restart(); + void touch() + { + expires = AbsTime(AbsTime::now(), duration); } void fire() { - // If we get here then we've not received any traffic in the timeout period - // Schedule closing the connection for the io thread - QPID_LOG(error, "Connection timed out: closing"); - connection.abort(); + // This is the best we can currently do to avoid a destruction/fire race + if (isCancelled()) return; + if (expires < AbsTime::now()) { + // If we get here then we've not received any traffic in the timeout period + // Schedule closing the connection for the io thread + QPID_LOG(error, "Connection timed out: closing"); + connection.abort(); + } else { + reset(); + timer.add(this); + } } }; @@ -328,22 +338,25 @@ void Connection::setSecureConnection(SecureConnection* s) adapter.setSecureConnection(s); } -struct ConnectionHeartbeatTask : public sys::TimerTask { - sys::Timer& timer; +struct ConnectionHeartbeatTask : public TimerTask { + Timer& timer; Connection& connection; - ConnectionHeartbeatTask(uint16_t hb, sys::Timer& t, Connection& c) : + ConnectionHeartbeatTask(uint16_t hb, Timer& t, Connection& c) : TimerTask(Duration(hb*TIME_SEC)), timer(t), connection(c) {} void fire() { - // Setup next firing - setupNextFire(); - timer.add(this); - - // Send Heartbeat - connection.sendHeartbeat(); + // This is the best we can currently do to avoid a destruction/fire race + if (!isCancelled()) { + // Setup next firing + reset(); + timer.add(this); + + // Send Heartbeat + connection.sendHeartbeat(); + } } }; |
