mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd::server: Add an optional download progress callback.
This commit is contained in:
parent
ceed6d5d44
commit
9da18261a6
2 changed files with 13 additions and 0 deletions
|
@ -56,6 +56,13 @@ struct ircd::server::in
|
|||
{
|
||||
mutable_buffer head;
|
||||
mutable_buffer content {head};
|
||||
|
||||
/// The progress closure is an optional callback invoked every time more
|
||||
/// content is read from the socket. The first argument is a view of the
|
||||
/// data most recently received. The second argument is a view of all data
|
||||
/// received so far. This is only invoked for content, not for the head;
|
||||
/// however the first time it is invoked it is safe to view the in.head
|
||||
std::function<void (const_buffer, const_buffer) noexcept> progress;
|
||||
};
|
||||
|
||||
/// This is a handle for being a client to another server. This handle will
|
||||
|
|
|
@ -1895,6 +1895,12 @@ ircd::server::tag::read_content(const const_buffer &buffer,
|
|||
content_read += addl_content_read;
|
||||
assert(size(buffer) - addl_content_read == 0);
|
||||
assert(content_read <= size(content) + content_over);
|
||||
|
||||
// Invoke the user's optional progress callback; this function
|
||||
// should be marked noexcept for the time being.
|
||||
if(req.in.progress)
|
||||
req.in.progress(buffer, const_buffer{data(content), content_read});
|
||||
|
||||
if(content_read == size(content) + content_over)
|
||||
{
|
||||
done = true;
|
||||
|
|
Loading…
Reference in a new issue