41 template <
typename Pipeline = wangle::DefaultPipeline>
65 std::shared_ptr<ServerSocketFactory> factory) {
104 std::shared_ptr<folly::IOThreadPoolExecutor> io_group) {
105 return group(
nullptr, io_group);
118 std::shared_ptr<folly::IOThreadPoolExecutor> accept_group,
119 std::shared_ptr<folly::IOThreadPoolExecutor> io_group) {
121 accept_group = std::make_shared<folly::IOThreadPoolExecutor>(
122 1, std::make_shared<folly::NamedThreadFactory>(
"Acceptor Thread"));
125 auto threads = std::thread::hardware_concurrency();
130 io_group = std::make_shared<folly::IOThreadPoolExecutor>(
131 threads, std::make_shared<folly::NamedThreadFactory>(
"IO Thread"));
143 std::make_shared<ServerAcceptorFactory<Pipeline>>(
172 std::shared_ptr<folly::AsyncServerSocket>
socket(
174 socket->setMaxNumMessagesInQueue(
185 socket->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait(
219 std::vector<std::shared_ptr<folly::AsyncSocketBase>> new_sockets;
222 std::exception_ptr exn;
224 auto startupFunc = [&](std::shared_ptr<folly::Baton<>> barrier) {
230 new_sockets.push_back(
socket);
232 socket->getAddress(&address);
236 exn = std::current_exception();
244 auto wait0 = std::make_shared<folly::Baton<>>();
249 auto barrier = std::make_shared<folly::Baton<>>();
255 std::rethrow_exception(exn);
258 for (
auto&
socket : new_sockets) {
261 socket->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait(
307 const std::vector<std::shared_ptr<folly::AsyncSocketBase>>&
312 std::shared_ptr<folly::IOThreadPoolExecutor>
getIOGroup()
const {
316 template <
typename F>
336 std::shared_ptr<std::vector<std::shared_ptr<folly::AsyncSocketBase>>>
sockets_{
337 std::make_shared<std::vector<std::shared_ptr<folly::AsyncSocketBase>>>()};
342 std::make_shared<DefaultAcceptPipelineFactory>()};
344 std::make_shared<AsyncServerSocketFactory>()};
351 std::make_unique<folly::Baton<>>()};
ServerBootstrap * group(std::shared_ptr< folly::IOThreadPoolExecutor > accept_group, std::shared_ptr< folly::IOThreadPoolExecutor > io_group)
ServerBootstrap * channelFactory(std::shared_ptr< ServerSocketFactory > factory)
ServerBootstrap * setReusePort(bool reusePort)
void setFromLocalPort(uint16_t port)
void bind(folly::AsyncServerSocket::UniquePtr s)
ServerSocketConfig accConfig_
std::shared_ptr< ServerWorkerPool > workerFactory_
EventBase * getEventBase()
std::shared_ptr< PipelineFactory< Pipeline > > childPipelineFactory_
ServerSocketConfig socketConfig
void bind(folly::SocketAddress &address)
static EventBaseManager * get()
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
std::shared_ptr< AcceptorFactory > acceptorFactory_
std::shared_ptr< AcceptPipelineFactory > acceptPipelineFactory_
std::vector< std::thread::id > threads
ServerBootstrap()=default
std::unique_ptr< folly::Baton<> > stopBaton_
ServerBootstrap * pipeline(std::shared_ptr< AcceptPipelineFactory > factory)
ServerBootstrap * group(std::shared_ptr< folly::IOThreadPoolExecutor > io_group)
void bindImpl(folly::SocketAddress &address)
NetworkSocket socket(int af, int type, int protocol)
uint32_t maxNumPendingConnectionsPerWorker
std::shared_ptr< std::vector< std::shared_ptr< folly::AsyncSocketBase > > > sockets_
const std::vector< std::shared_ptr< folly::AsyncSocketBase > > & getSockets() const
void forEachWorker(F &&f) const
std::unique_ptr< AsyncServerSocket, Destructor > UniquePtr
std::shared_ptr< folly::IOThreadPoolExecutor > io_group_
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
ServerBootstrap * childHandler(std::shared_ptr< AcceptorFactory > h)
std::shared_ptr< folly::IOThreadPoolExecutor > acceptor_group_
std::shared_ptr< ServerSocketFactory > socketFactory_
std::shared_ptr< folly::IOThreadPoolExecutor > getIOGroup() const
ServerBootstrap * acceptorConfig(const ServerSocketConfig &accConfig)
virtual folly::EventBase * getEventBase() const