Modify the quit() method (#276)

This commit is contained in:
An Tao 2019-10-11 17:24:28 +08:00 committed by GitHub
parent df82728a45
commit 8f5c757ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View File

@ -756,4 +756,12 @@ HttpAppFramework &HttpAppFrameworkImpl::createDbClient(
name,
isFast);
return *this;
}
void HttpAppFrameworkImpl::quit()
{
if (getLoop()->isRunning())
{
getLoop()->queueInLoop([this]() { getLoop()->quit(); });
}
}

View File

@ -317,11 +317,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework
virtual trantor::EventLoop *getLoop() const override;
virtual void quit() override
{
if (getLoop()->isRunning())
getLoop()->quit();
}
virtual void quit() override;
virtual HttpAppFramework &setServerHeaderField(
const std::string &server) override

View File

@ -191,3 +191,17 @@ void ListenerManager::startListening()
loopThread->run();
}
}
ListenerManager::~ListenerManager()
{
for (size_t i = 0; i < _servers.size(); ++i)
{
std::promise<int> pro;
auto f = pro.get_future();
_servers[i]->getLoop()->runInLoop([&pro, this, i] {
_servers[i].reset();
pro.set_value(1);
});
(void)f.get();
}
}

View File

@ -44,6 +44,7 @@ class ListenerManager : public trantor::NonCopyable
std::function<HttpResponsePtr(const HttpRequestPtr &)>>
&syncAdvices);
void startListening();
~ListenerManager();
private:
struct ListenerInfo