const char* kTestKey = "folly/io/async/test/certs/tests-key.pem";
const char* kTestCA = "folly/io/async/test/certs/ca-cert.pem";
+TestSSLServer::~TestSSLServer() {
+ if (thread_.joinable()) {
+ evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
+ LOG(INFO) << "Waiting for server thread to exit";
+ thread_.join();
+ }
+}
+
TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO)
- : ctx_(new SSLContext),
- acb_(acb),
- socket_(AsyncServerSocket::newSocket(&evb_)) {
- // Set up the SSL context
+ : acb_(acb) {
+ // Set up a default SSL context
+ ctx_ = std::make_shared<SSLContext>();
ctx_->loadCertificate(kTestCert);
ctx_->loadPrivateKey(kTestKey);
ctx_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
+ init(enableTFO);
+}
+
+TestSSLServer::TestSSLServer(
+ SSLServerAcceptCallbackBase* acb,
+ std::shared_ptr<SSLContext> ctx,
+ bool enableTFO)
+ : ctx_(ctx), acb_(acb) {
+ init(enableTFO);
+}
+
+void TestSSLServer::init(bool enableTFO) {
+ socket_ = AsyncServerSocket::newSocket(&evb_);
+
acb_->ctx_ = ctx_;
acb_->base_ = &evb_;
socket_->addAcceptCallback(acb_, &evb_);
socket_->startAccepting();
- thread_ = std::thread([&] { Main(); });
+ thread_ = std::thread([&] {
+ evb_.loop();
+ acb_->detach();
+ LOG(INFO) << "Server thread exited event loop";
+ });
LOG(INFO) << "Accepting connections on " << address_;
}
-
-TestSSLServer::~TestSSLServer() {
- if (thread_.joinable()) {
- evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
- LOG(INFO) << "Waiting for server thread to exit";
- thread_.join();
- }
-}
}
explicit TestSSLServer(
SSLServerAcceptCallbackBase* acb,
bool enableTFO = false);
+ explicit TestSSLServer(
+ SSLServerAcceptCallbackBase* acb,
+ std::shared_ptr<SSLContext> ctx,
+ bool enableTFO = false);
// Kills the thread.
virtual ~TestSSLServer();
}
protected:
- void Main() {
- evb_.loop();
- acb_->detach();
- LOG(INFO) << "Server thread exited event loop";
- }
-
EventBase evb_;
std::shared_ptr<SSLContext> ctx_;
SSLServerAcceptCallbackBase* acb_;
std::shared_ptr<AsyncServerSocket> socket_;
SocketAddress address_;
std::thread thread_;
+
+ private:
+ void init(bool);
};
}