explicit ServerWorkerPool(
std::shared_ptr<AcceptorFactory> acceptorFactory,
folly::wangle::IOThreadPoolExecutor* exec,
- std::vector<std::shared_ptr<folly::AsyncSocketBase>>* sockets,
+ std::shared_ptr<std::vector<std::shared_ptr<folly::AsyncSocketBase>>> sockets,
std::shared_ptr<ServerSocketFactory> socketFactory)
: acceptorFactory_(acceptorFactory)
, exec_(exec)
std::shared_ptr<Acceptor>> workers_;
std::shared_ptr<AcceptorFactory> acceptorFactory_;
folly::wangle::IOThreadPoolExecutor* exec_{nullptr};
- std::vector<std::shared_ptr<folly::AsyncSocketBase>>* sockets_;
+ std::shared_ptr<std::vector<std::shared_ptr<folly::AsyncSocketBase>>> sockets_;
std::shared_ptr<ServerSocketFactory> socketFactory_;
};
if (acceptorFactory_) {
workerFactory_ = std::make_shared<ServerWorkerPool>(
- acceptorFactory_, io_group.get(), &sockets_, socketFactory_);
+ acceptorFactory_, io_group.get(), sockets_, socketFactory_);
} else {
workerFactory_ = std::make_shared<ServerWorkerPool>(
std::make_shared<ServerAcceptorFactory<Pipeline>>(
childPipelineFactory_,
pipeline_),
- io_group.get(), &sockets_, socketFactory_);
+ io_group.get(), sockets_, socketFactory_);
}
io_group->addObserver(workerFactory_);
});
});
- sockets_.push_back(socket);
+ sockets_->push_back(socket);
}
void bind(folly::SocketAddress& address) {
});
});
- sockets_.push_back(socket);
+ sockets_->push_back(socket);
}
}
* Stop listening on all sockets.
*/
void stop() {
- for (auto socket : sockets_) {
- socket->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait(
- [&]() mutable {
- socketFactory_->stopSocket(socket);
- });
+ // sockets_ may be null if ServerBootstrap has been std::move'd
+ if (sockets_) {
+ for (auto socket : *sockets_) {
+ socket->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait(
+ [&]() mutable {
+ socketFactory_->stopSocket(socket);
+ });
+ }
+ sockets_->clear();
}
- sockets_.clear();
}
void join() {
*/
const std::vector<std::shared_ptr<folly::AsyncSocketBase>>&
getSockets() const {
- return sockets_;
+ return *sockets_;
}
std::shared_ptr<wangle::IOThreadPoolExecutor> getIOGroup() const {
std::shared_ptr<wangle::IOThreadPoolExecutor> io_group_;
std::shared_ptr<ServerWorkerPool> workerFactory_;
- std::vector<std::shared_ptr<folly::AsyncSocketBase>> sockets_;
+ std::shared_ptr<std::vector<std::shared_ptr<folly::AsyncSocketBase>>> sockets_{
+ std::make_shared<std::vector<std::shared_ptr<folly::AsyncSocketBase>>>()};
std::shared_ptr<AcceptorFactory> acceptorFactory_;
std::shared_ptr<PipelineFactory<Pipeline>> childPipelineFactory_;