ircd::rest: Add option to supply temporary/headers buffer in lieu of allocating.

This commit is contained in:
Jason Volk 2023-04-17 21:36:09 -07:00
parent dc13381822
commit 02e09728a5
2 changed files with 36 additions and 8 deletions

View File

@ -100,6 +100,10 @@ struct ircd::rest::opts
/// receiving dynamic content. Supply an empty unique_buffer instance.
unique_const_buffer *out {nullptr};
/// Optionally supply the temporary buffer for headers in/out in lieu of
/// any internally allocated.
mutable_buffer buf;
/// Timeout for the yielding/synchronous calls of this interface.
seconds timeout {20s};

View File

@ -14,13 +14,25 @@ ircd::rest::request::request(const rfc3986::uri &uri,
if(!opts.remote)
opts.remote = net::hostport{uri};
const unique_mutable_buffer buf
const bool need_alloc
{
empty(opts.sout.head) || empty(opts.sin.head)?
16_KiB: 0_KiB
empty(opts.buf)
&& (empty(opts.sout.head) || empty(opts.sin.head))
};
const unique_mutable_buffer _buf
{
need_alloc? 16_KiB: 0_KiB
};
if(!empty(_buf))
opts.buf = _buf;
window_buffer window
{
opts.buf
};
window_buffer window{buf};
if(empty(opts.sout.head))
{
assert(opts.remote);
@ -80,13 +92,25 @@ ircd::rest::request::request(const mutable_buffer &out,
if(!opts.remote)
opts.remote = net::hostport{uri};
const unique_mutable_buffer buf
const bool need_alloc
{
empty(opts.sout.head) || empty(opts.sin.head)?
16_KiB: 0_KiB
empty(opts.buf)
&& (empty(opts.sout.head) || empty(opts.sin.head))
};
const unique_mutable_buffer _buf
{
need_alloc? 16_KiB: 0_KiB
};
if(!empty(_buf))
opts.buf = _buf;
window_buffer window
{
opts.buf
};
window_buffer window{buf};
if(empty(opts.sout.head))
{
assert(opts.remote);