: listener_factory_(listener_factory),
address_(address), port_(port), thread_io_service_(), tcp_listener_(),
thread_pool_size_(thread_pool_size), thread_pool_(),
- tls_context_(context), connection_filter_(connection_filter) {
+ tls_context_(context), connection_filter_(connection_filter),
+ idle_timeout_(TCP_IDLE_CONNECTION_TIMEOUT) {
}
MtTcpListenerMgr::~MtTcpListenerMgr() {
thread_io_service_.reset(new IOService());
// Create a new TCPListener derivation using the factory.
- tcp_listener_ = listener_factory_(*thread_io_service_, address_,
- port_, tls_context_,
- TcpListener::IdleTimeout(TCP_IDLE_CONNECTION_TIMEOUT),
+ tcp_listener_ = listener_factory_(*thread_io_service_,
+ address_,
+ port_,
+ tls_context_,
+ idle_timeout_,
connection_filter_);
// Create the thread pool with immediate start.
namespace tcp {
/// @brief Default connection idle timeout in milliseconds.
-const long TCP_IDLE_CONNECTION_TIMEOUT = 10000;
+const long TCP_IDLE_CONNECTION_TIMEOUT = 300 * 1000;
/// @brief Defines a factory function for creating TcpListeners.
typedef std::function<
return(tcp_listener_);
}
+ /// @brief Sets the idle time per connection.
+ ///
+ /// @param timeout Amount of time in milliseconds
+ void setIdleTimeout(long milliseconds) {
+ idle_timeout_ = TcpListener::IdleTimeout(milliseconds);
+ }
+
+ long getIdleTimeout() {
+ return (idle_timeout_.value_);
+ }
+
private:
/// @brief Factory for creating TcpListener instances.
TcpListenerFactory listener_factory_;
/// @brief Callback the listener may use to reject connections during acceptance.
TcpConnectionFilterCallback connection_filter_;
+
+ /// @brief Time in milliseconds that a connection can remain idle before
+ /// it is closed.
+ TcpListener::IdleTimeout idle_timeout_;
};
/// @brief Defines a shared pointer to MtTcpListenerMgr.
/// @brief Returns local port on which server is listening.
uint16_t getLocalPort() const;
+ /// @brief Returns the idle timeout (in milliseconds).
+ long getIdleTimeout() const {
+ return (idle_timeout_);
+ }
+
protected:
/// @brief Creates @ref TcpConnection instance and adds it to the
EXPECT_TRUE(mt_listener_mgr_->isStopped());
}
+/// Verifies that idle timeout can be passed down to the internal listener.
+TEST_F(MtTcpListenerMgrTest, idleTimeout) {
+ // Create an MtTcpListenerMgr.
+ createMtTcpListenerMgr(1, std::bind(&MtTcpListenerMgrTest::synchronizedCommandHandler,
+ this, ph::_1));
+ // Verify the defualt timeout value.
+ EXPECT_EQ(TCP_IDLE_CONNECTION_TIMEOUT, mt_listener_mgr_->getIdleTimeout());
+
+ // Set a new timeout value.
+ mt_listener_mgr_->setIdleTimeout(200);
+ EXPECT_EQ(200, mt_listener_mgr_->getIdleTimeout());
+
+ // Start the listener, which should instantiate the internal listener.
+ ASSERT_NO_THROW_LOG(mt_listener_mgr_->start());
+ ASSERT_TRUE(mt_listener_mgr_->isRunning());
+
+ // Verify the internal listener's timeout value.
+ auto tcp_listener = mt_listener_mgr_->getTcpListener();
+ ASSERT_TRUE(tcp_listener);
+ EXPECT_EQ(200, tcp_listener->getIdleTimeout());
+}
+
+
} // end of anonymous namespace