diff --git a/include/ircd/server/request.h b/include/ircd/server/request.h index 94c1f1021..8502d37cb 100644 --- a/include/ircd/server/request.h +++ b/include/ircd/server/request.h @@ -42,6 +42,13 @@ struct ircd::server::out { const_buffer head; const_buffer content; + + /// The progress closure is an optional callback invoked every time more + /// content is written to the socket. The first argument is a view of the + /// data most recently written. The second argument is a view of all data + /// written so far. This is only invoked for content. At the first + /// invocation, the head has been fully written. + std::function progress; }; /// Request data and options related to the receive side of the request. diff --git a/ircd/server.cc b/ircd/server.cc index b47b5009a..8806b6f23 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -1655,6 +1655,11 @@ ircd::server::tag::wrote_buffer(const const_buffer &buffer) { assert(data(buffer) == data(req.out.content)); assert(written <= write_total()); + + // Invoke the user's optional progress callback; this function + // should be marked noexcept and has no reason to throw yet. + if(req.out.progress) + req.out.progress(buffer, const_buffer{data(req.out.content), written}); } else {