diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2014-08-11 09:15:34 -0700 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2014-08-11 09:15:34 -0700 |
commit | 3664fe8db6a88e2aed5bc9425dfae92828851a42 (patch) | |
tree | 5ad0a3bfccd50cff693cac411350bd1932bb9c77 | |
parent | 29a901f599ca16cec7c77a9789a41822e29d1494 (diff) |
Better TaskMan destroy; let's proprely stop all events before closing the libev loop.
-rw-r--r-- | includes/TaskMan.h | 1 | ||||
-rw-r--r-- | src/TaskMan.cc | 22 |
2 files changed, 22 insertions, 1 deletions
diff --git a/includes/TaskMan.h b/includes/TaskMan.h index acfa2c9..ba6d76f 100644 --- a/includes/TaskMan.h +++ b/includes/TaskMan.h @@ -124,6 +124,7 @@ class TaskMan { void curlMultiTimerEventCallback(ev::timer & w, int revents); void registerCurlHandle(CurlTask * curlTask); void unregisterCurlHandle(CurlTask * curlTask); + taskHash_t m_curlTasks; struct ares_channeldata * m_aresChannel = NULL; static const int ARES_MAX_SOCKETS = 2; diff --git a/src/TaskMan.cc b/src/TaskMan.cc index ba9bd60..6192cf0 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -467,9 +467,27 @@ Balau::TaskMan::~TaskMan() { s_scheduler.unregisterTaskMan(this); // probably way more work to do here in order to clean up tasks from that thread m_evt.stop(); - ev_loop_destroy(m_loop); + taskHash_t tasks = std::move(m_curlTasks); + m_curlTasks.clear(); + for (Task * t : tasks) { + CurlTask * c = dynamic_cast<CurlTask *>(t); + if (!c) + continue; + unregisterCurlHandle(c); + } + tasks.clear(); curl_multi_cleanup(m_curlMulti); ares_destroy(m_aresChannel); + m_curlTimer.stop(); + m_aresTimer.stop(); + if (m_aresSocketEvents[0]) + m_aresSocketEvents[0]->stop(); + m_aresSocketEvents[0] = NULL; + if (m_aresSocketEvents[1]) + m_aresSocketEvents[1]->stop(); + m_aresSocketEvents[1] = NULL; + + ev_loop_destroy(m_loop); } void * Balau::TaskMan::getStack() { @@ -650,6 +668,7 @@ void Balau::TaskMan::registerCurlHandle(Balau::CurlTask * curlTask) { curl_easy_setopt(curlTask->m_curlHandle, CURLOPT_PRIVATE, curlTask); curl_easy_setopt(curlTask->m_curlHandle, CURLOPT_NOSIGNAL, 1L); curl_multi_add_handle(m_curlMulti, curlTask->m_curlHandle); + m_curlTasks.insert(curlTask); } void Balau::TaskMan::unregisterCurlHandle(Balau::CurlTask * curlTask) { @@ -659,6 +678,7 @@ void Balau::TaskMan::unregisterCurlHandle(Balau::CurlTask * curlTask) { return; curl_easy_setopt(curlTask->m_curlHandle, CURLOPT_PRIVATE, static_cast<void *>(0)); curl_multi_remove_handle(m_curlMulti, curlTask->m_curlHandle); + m_curlTasks.erase(curlTask); } void Balau::TaskMan::getHostByName(const Balau::String & name, int family, AresHostCallback callback) { |