2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <folly/wangle/bootstrap/ServerBootstrap.h>
17 #include <folly/wangle/concurrent/NamedThreadFactory.h>
18 #include <folly/wangle/channel/ChannelHandler.h>
19 #include <folly/io/async/EventBaseManager.h>
23 void ServerWorkerPool::threadStarted(
24 folly::wangle::ThreadPoolExecutor::ThreadHandle* h) {
25 auto worker = acceptorFactory_->newAcceptor(exec_->getEventBase(h));
26 workers_.insert({h, worker});
28 for(auto socket : *sockets_) {
29 socket->getEventBase()->runInEventBaseThreadAndWait([this, worker, socket](){
30 socketFactory_->addAcceptCB(
31 socket, worker.get(), worker->getEventBase());
36 void ServerWorkerPool::threadStopped(
37 folly::wangle::ThreadPoolExecutor::ThreadHandle* h) {
38 auto worker = workers_.find(h);
39 CHECK(worker != workers_.end());
41 for (auto& socket : *sockets_) {
42 folly::Baton<> barrier;
43 socket->getEventBase()->runInEventBaseThreadAndWait([&]() {
44 socketFactory_->removeAcceptCB(
45 socket, worker->second.get(), nullptr);
51 if (!worker->second->getEventBase()->isInEventBaseThread()) {
52 worker->second->getEventBase()->runInEventBaseThreadAndWait([=]() {
53 worker->second->dropAllConnections();
56 worker->second->dropAllConnections();
59 workers_.erase(worker);