0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

modules/s_fetch: Fix submit error handling; move definition to unit.

This commit is contained in:
Jason Volk 2019-05-17 08:18:31 -07:00
parent 18354901dc
commit 9f2b887a22
2 changed files with 45 additions and 44 deletions

View file

@ -564,6 +564,49 @@ ircd::m::fetch::for_each(const std::function<bool (request &)> &closure)
// s_fetch.h
//
template<class... args>
bool
ircd::m::fetch::submit(const m::event::id &event_id,
const m::room::id &room_id,
const size_t &bufsz,
args&&... a)
try
{
assert(room_id && event_id);
auto it(requests.lower_bound(string_view(event_id)));
if(it != end(requests) && it->event_id == event_id)
{
assert(it->room_id == room_id);
return false;
}
it = requests.emplace_hint(it, room_id, event_id, bufsz, std::forward<args>(a)...);
auto &request(const_cast<fetch::request &>(*it)); try
{
while(!start(request))
request.origin = {};
}
catch(const std::exception &e)
{
requests.erase(it);
throw;
}
return true;
}
catch(const std::exception &e)
{
log::error
{
m::log, "Failed to start any fetch for %s in %s :%s",
string_view{event_id},
string_view{room_id},
e.what(),
};
return false;
}
//
// request worker
//

View file

@ -38,7 +38,6 @@ namespace ircd::m::fetch
static bool start(request &);
static bool handle(request &);
template<class... args> static bool submit(const event::id &, const room::id &, const size_t &bufsz = 8_KiB, args&&...);
static void eval_handle(const decltype(requests)::iterator &);
static void eval_handle();
static void eval_worker();
@ -47,6 +46,8 @@ namespace ircd::m::fetch
static size_t request_cleanup();
static void request_worker();
template<class... args> static bool submit(const event::id &, const room::id &, const size_t &bufsz = 8_KiB, args&&...);
static void hook_handle_prev(const event &, vm::eval &, evaltab &, const room &);
static void hook_handle_auth(const event &, vm::eval &, evaltab &, const room &);
static void hook_handle(const event &, vm::eval &);
@ -64,46 +65,3 @@ struct ircd::m::fetch::evaltab
size_t prev_fetching {0};
size_t prev_fetched {0};
};
template<class... args>
bool
ircd::m::fetch::submit(const m::event::id &event_id,
const m::room::id &room_id,
const size_t &bufsz,
args&&... a)
{
auto it
{
requests.lower_bound(string_view(event_id))
};
assert(room_id && event_id);
if(it != end(requests) && it->event_id == event_id)
{
assert(it->room_id == room_id);
return false;
}
else try
{
it = requests.emplace_hint(it, room_id, event_id, bufsz, std::forward<args>(a)...);
auto &request(const_cast<fetch::request &>(*it));
while(!start(request)) request.origin = {};
return true;
}
catch(const std::exception &e)
{
log::error
{
m::log, "Failed to start any fetch for %s in %s :%s",
string_view{event_id},
string_view{room_id},
e.what(),
};
auto &request(const_cast<fetch::request &>(*it));
assert(request.event_id == event_id);
assert(request.room_id == room_id);
request.eptr = std::current_exception();
return false;
};
}