From 02e09728a50cd5784f6e635a53d3814e86273a2c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 17 Apr 2023 21:36:09 -0700 Subject: [PATCH] ircd::rest: Add option to supply temporary/headers buffer in lieu of allocating. --- include/ircd/rest.h | 4 ++++ ircd/rest.cc | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/ircd/rest.h b/include/ircd/rest.h index 313c74108..94152c42e 100644 --- a/include/ircd/rest.h +++ b/include/ircd/rest.h @@ -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}; diff --git a/ircd/rest.cc b/ircd/rest.cc index eb5c90fa1..6abf15433 100644 --- a/ircd/rest.cc +++ b/ircd/rest.cc @@ -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);