From 130a86e27c556f8663195f2915cae8e5dcd41fa5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 17 Jul 2019 15:30:57 -0700 Subject: [PATCH] modules/m_fetch: Use cancel interface; minor cleanup. --- modules/m_fetch.cc | 16 ++++++++++++++-- modules/m_fetch.h | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/m_fetch.cc b/modules/m_fetch.cc index 0cd938e40..11c3bdf97 100644 --- a/modules/m_fetch.cc +++ b/modules/m_fetch.cc @@ -604,7 +604,18 @@ bool IRCD_MODULE_EXPORT ircd::m::fetch::cancel(request &request) { - return false; + bool ret{false}; + if(request.finished == -1) + return ret; + + if(request.finished == 0) + { + assert(request.started); + ret |= server::cancel(request); + } + + request.finished = -1; + return ret; } size_t @@ -661,6 +672,7 @@ try } catch(const std::exception &e) { + fetch::cancel(request); throw; } @@ -694,7 +706,7 @@ try return std::any_of(begin(requests), end(requests), [] (const request &r) { - return r.finished <= 0; + return r.finished == -1 || r.finished == 0; }); }); diff --git a/modules/m_fetch.h b/modules/m_fetch.h index 3d0c37a4b..33df2d54a 100644 --- a/modules/m_fetch.h +++ b/modules/m_fetch.h @@ -14,10 +14,6 @@ namespace ircd::m::fetch struct request; // m/fetch.h struct evaltab; - static bool operator<(const request &a, const request &b) noexcept; - static bool operator<(const request &a, const string_view &b) noexcept; - static bool operator<(const string_view &a, const request &b) noexcept; - extern ctx::dock dock; extern std::set> requests; extern std::multimap rooms; @@ -30,6 +26,10 @@ namespace ircd::m::fetch extern conf::item timeout; extern conf::item enable; + static bool operator<(const request &a, const request &b) noexcept; + static bool operator<(const request &a, const string_view &b) noexcept; + static bool operator<(const string_view &a, const request &b) noexcept; + static bool timedout(const request &, const time_t &now); static string_view select_origin(request &, const string_view &); static string_view select_random_origin(request &);