diff --git a/lib/src/HttpAppFrameworkImpl.cc b/lib/src/HttpAppFrameworkImpl.cc index 8d1528ff..c5bba86e 100644 --- a/lib/src/HttpAppFrameworkImpl.cc +++ b/lib/src/HttpAppFrameworkImpl.cc @@ -756,4 +756,12 @@ HttpAppFramework &HttpAppFrameworkImpl::createDbClient( name, isFast); return *this; +} + +void HttpAppFrameworkImpl::quit() +{ + if (getLoop()->isRunning()) + { + getLoop()->queueInLoop([this]() { getLoop()->quit(); }); + } } \ No newline at end of file diff --git a/lib/src/HttpAppFrameworkImpl.h b/lib/src/HttpAppFrameworkImpl.h index 48ca938b..e1ba4430 100644 --- a/lib/src/HttpAppFrameworkImpl.h +++ b/lib/src/HttpAppFrameworkImpl.h @@ -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 diff --git a/lib/src/ListenerManager.cc b/lib/src/ListenerManager.cc index d0217c19..de0d4c18 100644 --- a/lib/src/ListenerManager.cc +++ b/lib/src/ListenerManager.cc @@ -191,3 +191,17 @@ void ListenerManager::startListening() loopThread->run(); } } + +ListenerManager::~ListenerManager() +{ + for (size_t i = 0; i < _servers.size(); ++i) + { + std::promise pro; + auto f = pro.get_future(); + _servers[i]->getLoop()->runInLoop([&pro, this, i] { + _servers[i].reset(); + pro.set_value(1); + }); + (void)f.get(); + } +} diff --git a/lib/src/ListenerManager.h b/lib/src/ListenerManager.h index fc0b645a..f7f7981a 100644 --- a/lib/src/ListenerManager.h +++ b/lib/src/ListenerManager.h @@ -44,6 +44,7 @@ class ListenerManager : public trantor::NonCopyable std::function> &syncAdvices); void startListening(); + ~ListenerManager(); private: struct ListenerInfo