From: Woo Xie Date: Fri, 23 Jan 2015 18:21:38 +0000 (-0800) Subject: specify connection's idle tiemout X-Git-Tag: v0.23.0~27 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c8238d15ad6365cb1b051dc404b70992edba9401;p=folly.git specify connection's idle tiemout Summary: Now all connections are always scheduled with connectionManager's default timeout. This diff enables us to specify the different timeouts for each managed connections. Test Plan: prospect testing Reviewed By: davejwatson@fb.com Subscribers: trunkagent, fugalh, folly-diffs@, jsedgwick FB internal diff: D1797193 Tasks: 5343753 Signature: t1:1797193:1422034092:ed67b96efe8af8f8d1355d3f86fb1289daafb178 --- diff --git a/folly/wangle/acceptor/ConnectionManager.cpp b/folly/wangle/acceptor/ConnectionManager.cpp index 72b1492f..a0299e73 100644 --- a/folly/wangle/acceptor/ConnectionManager.cpp +++ b/folly/wangle/acceptor/ConnectionManager.cpp @@ -53,14 +53,15 @@ ConnectionManager::addConnection(ManagedConnection* connection, } } if (timeout) { - scheduleTimeout(connection); + scheduleTimeout(connection, timeout_); } } void -ConnectionManager::scheduleTimeout(ManagedConnection* connection) { - if (timeout_ > std::chrono::milliseconds(0)) { - connTimeouts_->scheduleTimeout(connection, timeout_); +ConnectionManager::scheduleTimeout(ManagedConnection* const connection, + std::chrono::milliseconds timeout) { + if (timeout > std::chrono::milliseconds(0)) { + connTimeouts_->scheduleTimeout(connection, timeout); } } diff --git a/folly/wangle/acceptor/ConnectionManager.h b/folly/wangle/acceptor/ConnectionManager.h index 2b0daa8d..3af2de89 100644 --- a/folly/wangle/acceptor/ConnectionManager.h +++ b/folly/wangle/acceptor/ConnectionManager.h @@ -90,7 +90,8 @@ class ConnectionManager: public folly::DelayedDestruction { /** * Schedule a timeout callback for a connection. */ - void scheduleTimeout(ManagedConnection* connection); + void scheduleTimeout(ManagedConnection* const connection, + std::chrono::milliseconds timeout); /* * Schedule a callback on the wheel timer @@ -130,6 +131,10 @@ class ConnectionManager: public folly::DelayedDestruction { } } + std::chrono::milliseconds getDefaultTimeout() const { + return timeout_; + } + private: class CloseIdleConnsCallback : public folly::EventBase::LoopCallback, diff --git a/folly/wangle/acceptor/ManagedConnection.cpp b/folly/wangle/acceptor/ManagedConnection.cpp index 9011d598..f993bd28 100644 --- a/folly/wangle/acceptor/ManagedConnection.cpp +++ b/folly/wangle/acceptor/ManagedConnection.cpp @@ -33,7 +33,14 @@ ManagedConnection::~ManagedConnection() { void ManagedConnection::resetTimeout() { if (connectionManager_) { - connectionManager_->scheduleTimeout(this); + resetTimeoutTo(connectionManager_->getDefaultTimeout()); + } +} + +void +ManagedConnection::resetTimeoutTo(std::chrono::milliseconds timeout) { + if (connectionManager_) { + connectionManager_->scheduleTimeout(this, timeout); } } diff --git a/folly/wangle/acceptor/ManagedConnection.h b/folly/wangle/acceptor/ManagedConnection.h index 50e7c057..0fd41977 100644 --- a/folly/wangle/acceptor/ManagedConnection.h +++ b/folly/wangle/acceptor/ManagedConnection.h @@ -76,8 +76,8 @@ class ManagedConnection: virtual void dumpConnectionState(uint8_t loglevel) = 0; /** - * If the connection has a connection manager, reset the timeout - * countdown. + * If the connection has a connection manager, reset the timeout countdown to + * connection manager's default timeout. * @note If the connection manager doesn't have the connection scheduled * for a timeout already, this method will schedule one. If the * connection manager does have the connection connection scheduled @@ -86,6 +86,12 @@ class ManagedConnection: */ virtual void resetTimeout(); + /** + * If the connection has a connection manager, reset the timeout countdown to + * user specified timeout. + */ + void resetTimeoutTo(std::chrono::milliseconds); + // Schedule an arbitrary timeout on the HHWheelTimer virtual void scheduleTimeout( folly::HHWheelTimer::Callback* callback,