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

ircd: Improve+rename client/resource head_buffer/content_buffer related.

This commit is contained in:
Jason Volk 2018-02-17 14:28:06 -08:00
parent 39d2196336
commit 3709bd5612
3 changed files with 25 additions and 11 deletions

View file

@ -45,11 +45,12 @@ struct ircd::client
static ctx::pool context;
struct conf *conf {&default_conf};
unique_buffer<mutable_buffer> headbuf;
unique_buffer<mutable_buffer> head_buffer;
std::shared_ptr<socket> sock;
ircd::timer timer;
http::request::head head;
size_t head_length {0};
unique_buffer<mutable_buffer> content_buffer;
size_t content_consumed {0};
bool longpoll {false};

View file

@ -434,7 +434,7 @@ ircd::client::client()
}
ircd::client::client(std::shared_ptr<socket> sock)
:headbuf{HEAD_MAX}
:head_buffer{HEAD_MAX}
,sock{std::move(sock)}
{
}
@ -479,7 +479,7 @@ bool
ircd::client::main()
noexcept try
{
parse::buffer pb{headbuf};
parse::buffer pb{head_buffer};
parse::capstan pc{pb, read_closure(*this)}; do
{
if(!handle_request(pc))
@ -604,7 +604,7 @@ try
// the tape is advanced.
timer = ircd::timer{};
head = http::request::head{pc};
head_length = pc.parsed - data(headbuf);
head_length = pc.parsed - data(head_buffer);
content_consumed = std::min(pc.unparsed(), head.content_length);
pc.parsed += content_consumed;
assert(pc.parsed <= pc.read);
@ -662,7 +662,7 @@ try
{
const string_view content_partial
{
data(headbuf) + head_length, content_consumed
data(head_buffer) + head_length, content_consumed
};
auto &resource

View file

@ -243,23 +243,36 @@ ircd::resource::operator()(client &client,
http::PAYLOAD_TOO_LARGE
};
// Content that hasn't yet arrived is remaining
const size_t content_remain
{
head.content_length - client.content_consumed
};
unique_buffer<mutable_buffer> content_buffer;
string_view content{content_partial};
// View of the content that will be passed to the resource handler. Starts
// with the content received so far which is actually in the head's buffer.
// One of three things can happen now:
//
// - There is no more content so we pass this as-is right to the resource.
// - There is more content, so we allocate a content buffer, copy what we
// have to it, read the rest off the socket, and then reassign this view.
// - There is more content, but the resource wants to read it off the
// socket on its own terms, so we pass this as-is.
string_view content
{
content_partial
};
if(content_remain)
{
// Copy any partial content to the final contiguous allocated buffer;
content_buffer = unique_buffer<mutable_buffer>{head.content_length};
memcpy(data(content_buffer), data(content_partial), size(content_partial));
client.content_buffer = unique_buffer<mutable_buffer>{head.content_length};
memcpy(data(client.content_buffer), data(content_partial), size(content_partial));
// Setup a window inside the buffer for the remaining socket read.
const mutable_buffer content_remain_buffer
{
data(content_buffer) + size(content_partial), content_remain
data(client.content_buffer) + size(content_partial), content_remain
};
//TODO: more discretion from the method.
@ -268,7 +281,7 @@ ircd::resource::operator()(client &client,
assert(client.content_consumed == head.content_length);
content = string_view
{
data(content_buffer), head.content_length
data(client.content_buffer), head.content_length
};
}