specify connection's idle tiemout
authorWoo Xie <woo@fb.com>
Fri, 23 Jan 2015 18:21:38 +0000 (10:21 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:12:32 +0000 (13:12 -0800)
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

folly/wangle/acceptor/ConnectionManager.cpp
folly/wangle/acceptor/ConnectionManager.h
folly/wangle/acceptor/ManagedConnection.cpp
folly/wangle/acceptor/ManagedConnection.h

index 72b1492f850129f511a750ae20a170340a35e084..a0299e7357bb2d78f54a0be0d7a5e55b1a11bcd7 100644 (file)
@@ -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);
   }
 }
 
index 2b0daa8dd22968804ba5a86a45cab70f0ff485ca..3af2de89e359fc7988a1b1bc230fca986b4b9d9e 100644 (file)
@@ -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,
index 9011d5987a7d5a7c7343bb78b04433280ab12661..f993bd28aa10fadb022c9ec52dd01f17164bec24 100644 (file)
@@ -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);
   }
 }
 
index 50e7c0575acf88762f2a8e0a35f3749a8ecc6dfb..0fd419774fd0f0b713a1e76a977c0a0519e7cb12 100644 (file)
@@ -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,