diff --git a/src/io/tcp_session.cc b/src/io/tcp_session.cc index 175a5ffb2fe..188b6dfac7c 100644 --- a/src/io/tcp_session.cc +++ b/src/io/tcp_session.cc @@ -248,6 +248,7 @@ void TcpSession::Accepted() { bool TcpSession::Connected(Endpoint remote) { assert(refcount_); + { tbb::mutex::scoped_lock lock(mutex_); if (closed_) { @@ -255,6 +256,7 @@ bool TcpSession::Connected(Endpoint remote) { } SessionEstablished(remote, TcpSession::ACTIVE); } + SetSocketOptions(); TCP_SESSION_LOG_DEBUG(this, TCP_DIR_IN, "Active session connection complete"); @@ -675,7 +677,7 @@ bool TcpSession::IsSocketErrorHard(const boost::system::error_code &ec) { } boost::system::error_code TcpSession::SetSocketKeepaliveOptions(int keepalive_time, - int keepalive_intvl, int keepalive_probes) { + int keepalive_intvl, int keepalive_probes, int tcp_user_timeout_val) { boost::system::error_code ec; socket_base::keep_alive keep_alive_option(true); socket()->set_option(keep_alive_option, ec); @@ -724,6 +726,17 @@ boost::system::error_code TcpSession::SetSocketKeepaliveOptions(int keepalive_ti return ec; } #endif +#ifdef TCP_USER_TIMEOUT + typedef boost::asio::detail::socket_option::integer< IPPROTO_TCP, TCP_USER_TIMEOUT > tcp_user_timeout; + tcp_user_timeout tcp_user_timeout_option(tcp_user_timeout_val); + socket()->set_option(tcp_user_timeout_option, ec); + if (ec) { + TCP_SESSION_LOG_ERROR(this, TCP_DIR_OUT, + "tcp_user_timeout: " << tcp_user_timeout_val << " set error: " << ec); + return ec; + } +#endif + return ec; } diff --git a/src/io/tcp_session.h b/src/io/tcp_session.h index 9b219a4cae5..ce6e0d19bda 100644 --- a/src/io/tcp_session.h +++ b/src/io/tcp_session.h @@ -186,7 +186,7 @@ class TcpSession { EventObserver observer() { return observer_; } boost::system::error_code SetSocketKeepaliveOptions(int keepalive_time, - int keepalive_intvl, int keepalive_probes); + int keepalive_intvl, int keepalive_probes, int tcp_user_timeout_val = 0); void CloseInternal(bool call_observer, bool notify_server = true);