You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2009/06/17 19:13:14 UTC
svn commit: r785733 - in /qpid/trunk/qpid/cpp/src/qpid/broker:
Connection.cpp Connection.h
Author: gsim
Date: Wed Jun 17 17:13:13 2009
New Revision: 785733
URL: http://svn.apache.org/viewvc?rev=785733&view=rev
Log:
Ensure that the ConnectionTimeoutTask does not block other tasks (e.g. ConnectionHeartbeatTask) by having the timeout changed after it has been submitted.
Modified:
qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp?rev=785733&r1=785732&r2=785733&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp Wed Jun 17 17:13:13 2009
@@ -48,6 +48,38 @@
namespace qpid {
namespace broker {
+struct ConnectionTimeoutTask : public TimerTask {
+ Timer& timer;
+ Connection& connection;
+ AbsTime expires;
+
+ ConnectionTimeoutTask(uint16_t hb, Timer& t, Connection& c) :
+ TimerTask(Duration(hb*2*TIME_SEC)),
+ timer(t),
+ connection(c),
+ expires(AbsTime::now(), duration)
+ {}
+
+ void touch()
+ {
+ expires = AbsTime(AbsTime::now(), duration);
+ }
+
+ void fire() {
+ // 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);
+ }
+ }
+};
+
Connection::Connection(ConnectionOutputHandler* out_, Broker& broker_, const std::string& mgmtId_, bool isLink_, uint64_t objectId) :
ConnectionState(out_, broker_),
adapter(*this, isLink_),
@@ -325,26 +357,6 @@
}
};
-struct ConnectionTimeoutTask : public TimerTask {
- Timer& timer;
- Connection& connection;
- ConnectionTimeoutTask(uint16_t hb, Timer& t, Connection& c) :
- TimerTask(Duration(hb*2*TIME_SEC)),
- timer(t),
- connection(c)
- {}
-
- void fire() {
- // This is the best we can currently do to avoid a destruction/fire race
- if (!isCancelled()) {
- // 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();
- }
- }
-};
-
void Connection::abort()
{
out.abort();
@@ -364,7 +376,7 @@
void Connection::restartTimeout()
{
if (timeoutTimer)
- timeoutTimer->reset();
+ timeoutTimer->touch();
}
}}
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h?rev=785733&r1=785732&r2=785733&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h Wed Jun 17 17:13:13 2009
@@ -60,6 +60,7 @@
class LinkRegistry;
class SecureConnection;
+struct ConnectionTimeoutTask;
class Connection : public sys::ConnectionInputHandler,
public ConnectionState,
@@ -153,7 +154,7 @@
management::ManagementAgent* agent;
Timer& timer;
boost::intrusive_ptr<TimerTask> heartbeatTimer;
- boost::intrusive_ptr<TimerTask> timeoutTimer;
+ boost::intrusive_ptr<ConnectionTimeoutTask> timeoutTimer;
ErrorListener* errorListener;
bool shadow;
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org