mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 15:04:10 +01:00
ircd::resource::response::chunked: Further elaborate the class.
This commit is contained in:
parent
35f9810dbd
commit
8ec205b4b5
3 changed files with 37 additions and 13 deletions
|
@ -88,6 +88,10 @@ struct ircd::resource::response::chunked
|
|||
|
||||
client *c {nullptr};
|
||||
unique_buffer<mutable_buffer> buf;
|
||||
size_t flushed {0};
|
||||
size_t wrote {0};
|
||||
uint count {0};
|
||||
bool finished {false};
|
||||
|
||||
size_t write(const const_buffer &chunk, const bool &ignore_empty = true);
|
||||
const_buffer flush(const const_buffer &);
|
||||
|
@ -99,8 +103,10 @@ struct ircd::resource::response::chunked
|
|||
chunked(client &, const http::code &, const string_view &content_type, const vector_view<const http::header> &, const size_t &buffer_size = default_buffer_size);
|
||||
chunked(client &, const http::code &, const vector_view<const http::header> &, const size_t &buffer_size = default_buffer_size);
|
||||
chunked(client &, const http::code &, const size_t &buffer_size = default_buffer_size);
|
||||
chunked(const chunked &) = delete;
|
||||
chunked(chunked &&) = delete;
|
||||
chunked() = default;
|
||||
chunked(chunked &&) = delete;
|
||||
chunked(const chunked &) = delete;
|
||||
chunked &operator=(chunked &&) = delete;
|
||||
chunked &operator=(const chunked &&) = delete;
|
||||
~chunked() noexcept;
|
||||
};
|
||||
|
|
|
@ -933,7 +933,8 @@ void
|
|||
ircd::http::writechunk(window_buffer &buf,
|
||||
const uint32_t &chunk_size)
|
||||
{
|
||||
writeline(buf, [&chunk_size](const mutable_buffer &out) -> size_t
|
||||
writeline(buf, [&chunk_size]
|
||||
(const mutable_buffer &out) -> size_t
|
||||
{
|
||||
return ::snprintf(data(out), size(out), "%08x", chunk_size);
|
||||
});
|
||||
|
|
|
@ -970,6 +970,7 @@ ircd::resource::response::chunked::finish()
|
|||
return false;
|
||||
|
||||
write(const_buffer{}, false);
|
||||
assert(finished);
|
||||
c = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
@ -990,6 +991,8 @@ ircd::resource::response::chunked::flush(const const_buffer &buf)
|
|||
};
|
||||
|
||||
assert(flushed <= size(buf));
|
||||
this->flushed += flushed;
|
||||
assert(this->flushed <= this->wrote);
|
||||
return const_buffer
|
||||
{
|
||||
data(buf), flushed
|
||||
|
@ -1002,20 +1005,34 @@ ircd::resource::response::chunked::write(const const_buffer &chunk,
|
|||
try
|
||||
{
|
||||
assert(size(chunk) <= size(this->buf) || empty(this->buf));
|
||||
size_t ret{0};
|
||||
|
||||
assert(!finished);
|
||||
if(!c)
|
||||
return ret;
|
||||
return 0UL;
|
||||
|
||||
if(ignore_empty && empty(chunk))
|
||||
return ret;
|
||||
if(empty(chunk) && ignore_empty)
|
||||
return 0UL;
|
||||
|
||||
char headbuf[32];
|
||||
const size_t wrote
|
||||
{
|
||||
this->wrote
|
||||
};
|
||||
|
||||
//TODO: bring iov from net::socket -> net::write_() -> client::write_()
|
||||
char headbuf[32];
|
||||
ret += c->write_all(http::writechunk(headbuf, size(chunk)));
|
||||
ret += size(chunk)? c->write_all(chunk) : 0UL;
|
||||
ret += c->write_all("\r\n"_sv);
|
||||
return ret;
|
||||
const auto head
|
||||
{
|
||||
http::writechunk(headbuf, size(chunk))
|
||||
};
|
||||
|
||||
this->wrote += c->write_all(head);
|
||||
this->wrote += !empty(chunk)? c->write_all(chunk) : 0UL;
|
||||
this->wrote += c->write_all("\r\n"_sv);
|
||||
finished |= empty(chunk);
|
||||
count++;
|
||||
|
||||
assert(this->wrote >= wrote);
|
||||
assert(this->wrote >= 2 || !finished);
|
||||
return this->wrote - wrote;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue