mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd::server: Reuse the read_content() function when reading partial.
This commit is contained in:
parent
a360c6f28f
commit
ceed6d5d44
1 changed files with 19 additions and 18 deletions
|
@ -1827,11 +1827,24 @@ ircd::server::tag::read_head(const const_buffer &buffer,
|
||||||
std::min(head.content_length, beyond_head_len)
|
std::min(head.content_length, beyond_head_len)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Now we know how much bleed into the next message was also received
|
||||||
|
assert(beyond_head_len >= content_read);
|
||||||
|
const size_t beyond_content_len
|
||||||
|
{
|
||||||
|
beyond_head_len - content_read
|
||||||
|
};
|
||||||
|
|
||||||
const const_buffer partial_content
|
const const_buffer partial_content
|
||||||
{
|
{
|
||||||
data(req.in.head) + head_read, content_read
|
data(req.in.head) + head_read, content_read
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Anything remaining is not our response and must be given back.
|
||||||
|
const const_buffer overrun
|
||||||
|
{
|
||||||
|
data(beyond_head) + size(partial_content), beyond_content_len
|
||||||
|
};
|
||||||
|
|
||||||
// Reduce the user's content buffer to the content-length. This is sort of
|
// Reduce the user's content buffer to the content-length. This is sort of
|
||||||
// how we convey the content-length back to the user. The buffer size will
|
// how we convey the content-length back to the user. The buffer size will
|
||||||
// eventually reflect how much content was actually received; the user can
|
// eventually reflect how much content was actually received; the user can
|
||||||
|
@ -1847,25 +1860,13 @@ ircd::server::tag::read_head(const const_buffer &buffer,
|
||||||
content_over = head.content_length - size(req.in.content);
|
content_over = head.content_length - size(req.in.content);
|
||||||
|
|
||||||
// Any partial content was written to the head buffer by accident,
|
// Any partial content was written to the head buffer by accident,
|
||||||
// that has to be copied over to the content buffer.
|
// that may have to be copied over to the content buffer.
|
||||||
if(!contiguous)
|
if(!empty(partial_content) && !contiguous)
|
||||||
this->content_read += copy(req.in.content, partial_content);
|
copy(req.in.content, partial_content);
|
||||||
else
|
|
||||||
this->content_read += size(partial_content);
|
|
||||||
|
|
||||||
// Anything remaining is not our response and must be given back
|
// Invoke the read_content() routine which will increment this->content_read
|
||||||
assert(beyond_head_len >= content_read);
|
read_content(partial_content, done);
|
||||||
const const_buffer overrun
|
assert(this->content_read == size(partial_content));
|
||||||
{
|
|
||||||
data(beyond_head) + size(partial_content), beyond_head_len - content_read
|
|
||||||
};
|
|
||||||
|
|
||||||
assert(this->content_read + content_over <= head.content_length);
|
|
||||||
if(this->content_read + content_over == head.content_length)
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
set_value(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
return overrun;
|
return overrun;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue