Summary:
AsyncSSLSocket can be connected using connect with
total timeouts.
This adds a method to get the total timeout that
was set.
Reviewed By: ngoyal, yfeldblum
Differential Revision:
D4656331
fbshipit-source-id:
a55ad9f081449d358b8133e9598a2063f625a2e6
assert(state_ == StateEnum::UNINIT);
assert(sslState_ == STATE_UNINIT);
noTransparentTls_ = true;
+ totalConnectTimeout_ = totalConnectTimeout;
AsyncSSLSocketConnector* connector =
new AsyncSSLSocketConnector(this, callback, totalConnectTimeout.count());
AsyncSocket::connect(
return sessionResumptionAttempted_;
}
+ /**
+ * If the SSL socket was used to connect as well
+ * as establish an SSL connection, this gives the total
+ * timeout for the connect + SSL connection that was
+ * set.
+ */
+ std::chrono::milliseconds getTotalConnectTimeout() const {
+ return totalConnectTimeout_;
+ }
+
private:
void init();
std::chrono::steady_clock::time_point handshakeEndTime_;
std::chrono::milliseconds handshakeConnectTimeout_{0};
bool sessionResumptionAttempted_{false};
+ std::chrono::milliseconds totalConnectTimeout_{0};
std::unique_ptr<IOBuf> preReceivedData_;
};
// connect
auto socket = std::make_shared<BlockingSocket>(server.getAddress(),
sslContext);
- socket->open();
+ socket->open(std::chrono::milliseconds(10000));
// write()
uint8_t buf[128];
socket->close();
cerr << "ConnectWriteReadClose test completed" << endl;
+ EXPECT_EQ(socket->getSSLSocket()->getTotalConnectTimeout().count(), 10000);
}
/**
throw err_.value();
}
}
+
void close() {
sock_->close();
}
return sock_->getFd();
}
+ folly::AsyncSocket* getSocket() {
+ return sock_.get();
+ }
+
+ folly::AsyncSSLSocket* getSSLSocket() {
+ return dynamic_cast<folly::AsyncSSLSocket*>(sock_.get());
+ }
+
private:
folly::EventBase eventBase_;
folly::AsyncSocket::UniquePtr sock_;