0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 21:38:18 +02:00

modules/client/sync: Reuse scratch buffer on longpoll handles.

This commit is contained in:
Jason Volk 2019-03-27 23:37:30 -07:00
parent 5d06042140
commit 0e6e556d50
2 changed files with 11 additions and 11 deletions

View file

@ -611,6 +611,11 @@ ircd::m::sync::longpoll::poll(data &data,
const args &args)
try
{
const unique_buffer<mutable_buffer> scratch
{
96_KiB
};
const scope_count polling{longpoll::polling}; do
{
if(!dock.wait_until(args.timesout))
@ -636,7 +641,7 @@ try
if(polylog_only)
return false;
if(handle(data, args, accepted))
if(handle(data, args, accepted, scratch))
return true;
}
while(1);
@ -669,7 +674,8 @@ catch(const std::exception &e)
bool
ircd::m::sync::longpoll::handle(data &data,
const args &args,
const accepted &event)
const accepted &event,
const mutable_buffer &scratch)
{
const scope_restore their_event
{
@ -686,15 +692,9 @@ ircd::m::sync::longpoll::handle(data &data,
data.client_txnid, event.client_txnid
};
const unique_buffer<mutable_buffer> buf
{
// must be at least worst-case size of m::event plus some.
std::max(size_t(linear_buffer_size), size_t(96_KiB))
};
const size_t consumed
{
linear_proffer_event(data, buf)
linear_proffer_event(data, scratch)
};
if(!consumed)
@ -704,7 +704,7 @@ ircd::m::sync::longpoll::handle(data &data,
{
string_view
{
buffer::data(buf), consumed
buffer::data(scratch), consumed
}
};

View file

@ -41,7 +41,7 @@ namespace ircd::m::sync::longpoll
std::deque<accepted> queue;
ctx::dock dock;
static bool handle(data &, const args &, const accepted &);
static bool handle(data &, const args &, const accepted &, const mutable_buffer &scratch);
static bool poll(data &, const args &);
static void handle_notify(const m::event &, m::vm::eval &);
extern m::hookfn<m::vm::eval &> notified;