Commit feff1cde authored by Subodh Iyengar's avatar Subodh Iyengar Committed by Facebook Github Bot

Add a method to AsyncSSLSocket to supply connect timeouts

Summary:
The current method to supply connect timeouts to AsyncSSLSocket
is to supply only the max connect + ssl connect time.

However in some cases when connect time is known, it is desirable
to supply it so that if connect does not succeed in connect time
we can error out quicker and retry.

This adds a new method for connect time in addition to the total
Connect time.

An alternative to this would be to create a AsyncSocket, connect it
and then pass it's fd to AsyncSSLSocket, however that approach does
not work well when TFO is being used, because TFO State is a part of
the AsyncSocket's state and that is not encapsulated with the fd transfer.

We could move the state around, but that is error prone, and this is much
simpler and isolated to AsyncSSLSocket.

Reviewed By: knekritz

Differential Revision: D4626924

fbshipit-source-id: d802d035efbced68873ab59314d9f0e661e5509b
parent e473e0f9
......@@ -645,19 +645,31 @@ void AsyncSSLSocket::cacheLocalPeerAddr() {
}
}
void AsyncSSLSocket::connect(ConnectCallback* callback,
const folly::SocketAddress& address,
int timeout,
const OptionMap &options,
const folly::SocketAddress& bindAddr)
noexcept {
void AsyncSSLSocket::connect(
ConnectCallback* callback,
const folly::SocketAddress& address,
int timeout,
const OptionMap& options,
const folly::SocketAddress& bindAddr) noexcept {
auto timeoutChrono = std::chrono::milliseconds(timeout);
connect(callback, address, timeoutChrono, timeoutChrono, options, bindAddr);
}
void AsyncSSLSocket::connect(
ConnectCallback* callback,
const folly::SocketAddress& address,
std::chrono::milliseconds connectTimeout,
std::chrono::milliseconds totalConnectTimeout,
const OptionMap& options,
const folly::SocketAddress& bindAddr) noexcept {
assert(!server_);
assert(state_ == StateEnum::UNINIT);
assert(sslState_ == STATE_UNINIT);
noTransparentTls_ = true;
AsyncSSLSocketConnector *connector =
new AsyncSSLSocketConnector(this, callback, timeout);
AsyncSocket::connect(connector, address, timeout, options, bindAddr);
AsyncSSLSocketConnector* connector =
new AsyncSSLSocketConnector(this, callback, totalConnectTimeout.count());
AsyncSocket::connect(
connector, address, connectTimeout.count(), options, bindAddr);
}
bool AsyncSSLSocket::needsPeerVerification() const {
......
......@@ -316,6 +316,29 @@ class AsyncSSLSocket : public virtual AsyncSocket {
const folly::SocketAddress& bindAddr = anyAddress())
noexcept override;
/**
* A variant of connect that allows the caller to specify
* the timeout for the regular connect and the ssl connect
* separately.
* connectTimeout is specified as the time to establish a TCP
* connection.
* totalConnectTimeout defines the
* time it takes from starting the TCP connection to the time
* the ssl connection is established. The reason the timeout is
* defined this way is because user's rarely need to specify the SSL
* timeout independently of the connect timeout. It allows us to
* bound the time for a connect and SSL connection in
* a finer grained manner than if timeout was just defined
* independently for SSL.
*/
virtual void connect(
ConnectCallback* callback,
const folly::SocketAddress& address,
std::chrono::milliseconds connectTimeout,
std::chrono::milliseconds totalConnectTimeout,
const OptionMap& options = emptyOptionMap,
const folly::SocketAddress& bindAddr = anyAddress()) noexcept;
using AsyncSocket::connect;
/**
......
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