ServerBootstrap(const ServerBootstrap& that) = delete;
ServerBootstrap(ServerBootstrap&& that) = default;
- ServerBootstrap() {}
+ ServerBootstrap() = default;
~ServerBootstrap() {
stop();
1, std::make_shared<wangle::NamedThreadFactory>("Acceptor Thread"));
}
if (!io_group) {
+ auto threads = std::thread::hardware_concurrency();
+ if (threads <= 0) {
+ // Reasonable mid-point for concurrency when actual value unknown
+ threads = 8;
+ }
io_group = std::make_shared<folly::wangle::IOThreadPoolExecutor>(
- 32, std::make_shared<wangle::NamedThreadFactory>("IO Thread"));
+ threads, std::make_shared<wangle::NamedThreadFactory>("IO Thread"));
}
// TODO better config checking
}
sockets_->clear();
}
+ if (!stopped_) {
+ stopped_ = true;
+ // stopBaton_ may be null if ServerBootstrap has been std::move'd
+ if (stopBaton_) {
+ stopBaton_->post();
+ }
+ }
}
void join() {
}
}
+ void waitForStop() {
+ if (!stopped_) {
+ CHECK(stopBaton_);
+ stopBaton_->wait();
+ }
+ }
+
/*
* Get the list of listening sockets
*/
std::make_shared<DefaultAcceptPipelineFactory>()};
std::shared_ptr<ServerSocketFactory> socketFactory_{
std::make_shared<AsyncServerSocketFactory>()};
+
+ std::unique_ptr<folly::Baton<>> stopBaton_{
+ folly::make_unique<folly::Baton<>>()};
+ bool stopped_{false};
};
} // namespace