mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +01:00
ircd::server: Additional assertions; minor cleanup.
This commit is contained in:
parent
b1974871c8
commit
6379813950
1 changed files with 37 additions and 14 deletions
|
@ -3221,18 +3221,27 @@ ircd::server::chunk_content_completed(tag &tag,
|
||||||
assert(tag.request);
|
assert(tag.request);
|
||||||
auto &req{*tag.request};
|
auto &req{*tag.request};
|
||||||
auto &state{tag.state};
|
auto &state{tag.state};
|
||||||
|
|
||||||
static const string_view terminator{"\r\n"};
|
static const string_view terminator{"\r\n"};
|
||||||
|
|
||||||
|
// Remove the terminator from the total length state.
|
||||||
assert(state.content_length >= size(terminator));
|
assert(state.content_length >= size(terminator));
|
||||||
state.content_length -= size(terminator);
|
state.content_length -= size(terminator);
|
||||||
state.content_read -= size(terminator);
|
state.content_read -= size(terminator);
|
||||||
|
|
||||||
|
// Remove the terminator from the chunk length state.
|
||||||
assert(state.chunk_length >= 2);
|
assert(state.chunk_length >= 2);
|
||||||
assert(state.chunk_read == state.chunk_length);
|
assert(state.chunk_read == state.chunk_length);
|
||||||
state.chunk_length -= size(terminator);
|
state.chunk_length -= size(terminator);
|
||||||
state.chunk_read -= size(terminator);
|
state.chunk_read -= size(terminator);
|
||||||
|
|
||||||
if(state.chunk_length != 0)
|
// State sanity tests
|
||||||
|
assert(state.content_length >= state.content_read);
|
||||||
|
assert(state.content_length >= state.chunk_length);
|
||||||
|
assert(state.content_length >= state.chunk_read);
|
||||||
|
assert(state.content_read >= state.chunk_length);
|
||||||
|
assert(state.content_read >= state.chunk_read);
|
||||||
|
assert(state.chunk_length >= state.chunk_read);
|
||||||
|
if(state.chunk_length > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(state.chunk_read == 0);
|
assert(state.chunk_read == 0);
|
||||||
|
@ -3399,7 +3408,7 @@ ircd::server::tag::read_chunk_dynamic_content(const const_buffer &buffer,
|
||||||
state.chunk_read += addl_content_read;
|
state.chunk_read += addl_content_read;
|
||||||
state.content_read += addl_content_read;
|
state.content_read += addl_content_read;
|
||||||
assert(state.chunk_read <= state.content_read);
|
assert(state.chunk_read <= state.content_read);
|
||||||
|
assert(state.chunk_read <= state.chunk_length);
|
||||||
if(state.chunk_read == state.chunk_length)
|
if(state.chunk_read == state.chunk_length)
|
||||||
chunk_dynamic_content_completed(*this, done);
|
chunk_dynamic_content_completed(*this, done);
|
||||||
|
|
||||||
|
@ -3408,14 +3417,13 @@ ircd::server::tag::read_chunk_dynamic_content(const const_buffer &buffer,
|
||||||
if(req.in.progress && !done)
|
if(req.in.progress && !done)
|
||||||
req.in.progress(buffer, const_buffer{data(chunk), state.chunk_read});
|
req.in.progress(buffer, const_buffer{data(chunk), state.chunk_read});
|
||||||
|
|
||||||
if(state.chunk_read == state.chunk_length)
|
assert(state.chunk_read <= state.chunk_length);
|
||||||
{
|
if(likely(state.chunk_read != state.chunk_length))
|
||||||
assert(state.chunk_read == state.chunk_length);
|
return {};
|
||||||
assert(state.chunk_read <= state.content_read);
|
|
||||||
state.chunk_length = size_t(-1);
|
|
||||||
state.chunk_read = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
assert(state.chunk_read <= state.content_read);
|
||||||
|
state.chunk_length = size_t(-1);
|
||||||
|
state.chunk_read = 0;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3426,21 +3434,36 @@ ircd::server::chunk_dynamic_content_completed(tag &tag,
|
||||||
assert(tag.request);
|
assert(tag.request);
|
||||||
auto &req{*tag.request};
|
auto &req{*tag.request};
|
||||||
auto &state{tag.state};
|
auto &state{tag.state};
|
||||||
|
assert(!req.in.chunks.empty());
|
||||||
|
auto &chunk{req.in.chunks.back()};
|
||||||
static const string_view terminator{"\r\n"};
|
static const string_view terminator{"\r\n"};
|
||||||
|
|
||||||
|
// Remove the terminator from the total length state.
|
||||||
|
assert(state.content_length >= size(terminator));
|
||||||
|
assert(state.content_read >= size(terminator));
|
||||||
state.content_length -= size(terminator);
|
state.content_length -= size(terminator);
|
||||||
state.content_read -= size(terminator);
|
state.content_read -= size(terminator);
|
||||||
|
|
||||||
assert(state.chunk_length >= 2);
|
// Remove the terminator from the chunk length state.
|
||||||
|
assert(state.chunk_length >= size(terminator));
|
||||||
|
assert(state.chunk_read >= size(terminator));
|
||||||
assert(state.chunk_read == state.chunk_length);
|
assert(state.chunk_read == state.chunk_length);
|
||||||
state.chunk_length -= size(terminator);
|
state.chunk_length -= size(terminator);
|
||||||
state.chunk_read -= size(terminator);
|
state.chunk_read -= size(terminator);
|
||||||
|
|
||||||
auto &chunk{req.in.chunks.back()};
|
// Remove the terminator from the end of the chunk
|
||||||
std::get<1>(chunk) -= size(terminator);
|
std::get<1>(chunk) -= size(terminator);
|
||||||
assert(size(chunk) == state.chunk_length);
|
assert(size(chunk) == state.chunk_length);
|
||||||
assert(std::get<0>(chunk) <= std::get<1>(chunk));
|
assert(std::get<0>(chunk) <= std::get<1>(chunk));
|
||||||
if(state.chunk_length != 0)
|
|
||||||
|
// State sanity tests
|
||||||
|
assert(state.content_length >= state.content_read);
|
||||||
|
assert(state.content_length >= state.chunk_length);
|
||||||
|
assert(state.content_length >= state.chunk_read);
|
||||||
|
assert(state.content_read >= state.chunk_length);
|
||||||
|
assert(state.content_read >= state.chunk_read);
|
||||||
|
assert(state.chunk_length >= state.chunk_read);
|
||||||
|
if(state.chunk_length > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(state.chunk_read == 0);
|
assert(state.chunk_read == 0);
|
||||||
|
|
Loading…
Reference in a new issue