0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd: Rename the stream_buffer to window_buffer.

This commit is contained in:
Jason Volk 2018-02-07 21:30:20 -08:00
parent 703cab45e9
commit f04ba38b42
7 changed files with 37 additions and 28 deletions

View file

@ -36,7 +36,7 @@ namespace ircd::buffer
template<class it> struct buffer;
struct const_buffer;
struct mutable_buffer;
struct stream_buffer;
struct window_buffer;
template<class buffer, size_t SIZE> struct fixed_buffer;
template<class buffer, uint align = 16> struct unique_buffer;
@ -89,7 +89,7 @@ namespace ircd
using buffer::fixed_buffer;
using buffer::unique_buffer;
using buffer::null_buffer;
using buffer::stream_buffer;
using buffer::window_buffer;
using buffer::fixed_const_buffer;
using buffer::fixed_mutable_buffer;
@ -279,7 +279,17 @@ static_assert
"ircd::buffer::fixed_buffer must be standard layout"
);
struct ircd::buffer::stream_buffer
/// The window_buffer is just two mutable_buffers. One of the two buffers
/// just spans an underlying space and the other buffer is a window of the
/// remaining space which shrinks toward the end as the space is consumed.
/// The window_buffer object inherits from the latter, so it always has the
/// appearance of a mutable_buffer windowing on the the next place to write.
///
/// The recommended usage of this device is actually through the operator()
/// closure, which will automatically resize the window based on the return
/// value in the closure.
///
struct ircd::buffer::window_buffer
:mutable_buffer
{
mutable_buffer base;
@ -331,7 +341,7 @@ struct ircd::buffer::stream_buffer
consume(*this, closure(*this));
}
stream_buffer(const mutable_buffer &base)
window_buffer(const mutable_buffer &base)
:mutable_buffer{base}
,base{base}
{}
@ -339,7 +349,6 @@ struct ircd::buffer::stream_buffer
/// Like unique_ptr, this template holds ownership of an allocated buffer
///
///
template<class buffer,
uint alignment>
struct ircd::buffer::unique_buffer

View file

@ -27,11 +27,11 @@ namespace ircd::http
string_view status(const enum code &);
enum code status(const string_view &);
void writeline(stream_buffer &);
void writeline(stream_buffer &, const stream_buffer::closure &);
void writeline(window_buffer &);
void writeline(window_buffer &, const window_buffer::closure &);
void write(stream_buffer &out, const header &);
void write(stream_buffer &out, const vector_view<const header> &);
void write(window_buffer &out, const header &);
void write(window_buffer &out, const vector_view<const header> &);
size_t serialized(const vector_view<const header> &);
std::string strung(const vector_view<const header> &);
}
@ -249,7 +249,7 @@ struct ircd::http::request
using proffer = std::function<void (const head &)>;
// compose a request into buffer
request(stream_buffer &,
request(window_buffer &,
const string_view &host,
const string_view &method = "GET",
const string_view &uri = "/",
@ -306,7 +306,7 @@ struct ircd::http::response
using proffer = std::function<void (const head &)>;
// compose a response into buffer
response(stream_buffer &,
response(window_buffer &,
const code & = code::OK,
const size_t &content_length = 0,
const string_view &content_type = {},

View file

@ -232,7 +232,7 @@ const ircd::http::parser;
///
/// If termination is false, no extra CRLF is printed to the buffer allowing
/// additional headers not specified to be appended later.
ircd::http::request::request(stream_buffer &out,
ircd::http::request::request(window_buffer &out,
const string_view &host,
const string_view &method,
const string_view &uri,
@ -320,7 +320,7 @@ ircd::http::request::head::head(parse::capstan &pc,
{
}
ircd::http::response::response(stream_buffer &out,
ircd::http::response::response(window_buffer &out,
const code &code,
const size_t &content_length,
const string_view &content_type,
@ -745,7 +745,7 @@ std::string
ircd::http::strung(const vector_view<const header> &headers)
{
std::string ret(serialized(headers), char{});
stream_buffer out{ret};
window_buffer out{ret};
write(out, headers);
assert(out.consumed() <= ret.size());
ret.resize(out.consumed());
@ -773,7 +773,7 @@ ircd::http::serialized(const vector_view<const header> &headers)
}
void
ircd::http::write(stream_buffer &out,
ircd::http::write(window_buffer &out,
const vector_view<const header> &headers)
{
for(const auto &header : headers)
@ -781,7 +781,7 @@ ircd::http::write(stream_buffer &out,
}
void
ircd::http::write(stream_buffer &out,
ircd::http::write(window_buffer &out,
const header &header)
{
if(header.second.empty())
@ -802,12 +802,12 @@ ircd::http::write(stream_buffer &out,
/// Close over the user's closure to append a newline.
void
ircd::http::writeline(stream_buffer &write,
const stream_buffer::closure &closure)
ircd::http::writeline(window_buffer &write,
const window_buffer::closure &closure)
{
// A new stream_buffer is implicit constructed out of the mutable_buffer
// A new window_buffer is implicit constructed out of the mutable_buffer
// otherwise presented to this closure as its write window.
write([&closure](stream_buffer write)
write([&closure](window_buffer write)
{
const auto newline{[](const mutable_buffer &out)
{
@ -821,7 +821,7 @@ ircd::http::writeline(stream_buffer &write,
}
void
ircd::http::writeline(stream_buffer &write)
ircd::http::writeline(window_buffer &write)
{
writeline(write, [](const mutable_buffer &out)
{

View file

@ -212,7 +212,7 @@ ircd::log::mark(const facility &fac,
namespace ircd::log
{
static void check(std::ostream &) noexcept;
static void slog(const facility &fac, const string_view &name, const stream_buffer::closure &) noexcept;
static void slog(const facility &fac, const string_view &name, const window_buffer::closure &) noexcept;
}
/// ircd::log is not thread-safe. This internal function is called when the
@ -277,7 +277,7 @@ namespace ircd::log
void
ircd::log::slog(const facility &fac,
const string_view &name,
const stream_buffer::closure &closure)
const window_buffer::closure &closure)
noexcept
{
if(!file[fac].is_open() && !console_out[fac] && !console_err[fac])
@ -326,7 +326,7 @@ noexcept
// Compose the user message after prefix
const size_t pos(s.tellp());
const mutable_buffer userspace{buf + pos, max - pos};
stream_buffer sb{userspace};
window_buffer sb{userspace};
sb(closure);
// Compose the newline after user message.

View file

@ -54,7 +54,7 @@ const
string_view(json::get<"content"_>(*this)).size()
};
stream_buffer sb{out};
window_buffer sb{out};
http::request
{
sb,

View file

@ -613,7 +613,7 @@ ircd::resource::response::response(client &client,
// contents of this buffer get copied again when further passed to
// response{}; we can get this off the stack if that remains true.
thread_local char buffer[2_KiB];
stream_buffer sb{buffer};
window_buffer sb{buffer};
{
const critical_assertion ca;
http::write(sb, headers);
@ -653,7 +653,7 @@ ircd::resource::response::response(client &client,
// This buffer will be passed to the socket and sent out;
// cannot be static/tls.
char head_buf[2_KiB];
stream_buffer head{head_buf};
window_buffer head{head_buf};
http::response
{
head,

View file

@ -35,7 +35,7 @@ ircd::rfc1035::make_query(const mutable_buffer &out,
const vector_view<const question> &questions)
{
assert(bswap(header.qdcount) == questions.size());
stream_buffer sb{out};
window_buffer sb{out};
sb([&header](const mutable_buffer &buf)
{