Commit c8238d15 authored by Woo Xie's avatar Woo Xie Committed by woo

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
parent c152d43d
......@@ -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);
}
}
......
......@@ -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,
......
......@@ -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);
}
}
......
......@@ -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,
......
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