Skip to content

Conversation

@MungoG
Copy link
Collaborator

@MungoG MungoG commented Dec 12, 2025

No description provided.

@MungoG MungoG requested review from ashtum and vinniefalco December 12, 2025 18:58
@cppalliance-bot
Copy link

cppalliance-bot commented Dec 12, 2025

An automated preview of the documentation is available at https://119.beast2.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-01-05 16:58:49 UTC

@MungoG MungoG force-pushed the issue-55-async-body-write-stream branch from 1823aa8 to e14d19e Compare December 19, 2025 18:26
private:
AsyncWriteStream& stream_;
http_proto::serializer& sr_;
http_proto::serializer::stream& srs_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right, the user should not have to create serializer::stream and pass it in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is left as is for the time being per the slack discussion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, however, body_write_stream should take ownership of serializer::stream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ownership changed.

@MungoG MungoG force-pushed the issue-55-async-body-write-stream branch from 283da17 to 32e2162 Compare January 5, 2026 16:27
@MungoG MungoG marked this pull request as ready for review January 5, 2026 17:47
@MungoG MungoG changed the title Create body_write_stream (initial work in progress) Create body_write_stream Jan 5, 2026
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.11%. Comparing base (a456c0f) to head (6d83768).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #119      +/-   ##
===========================================
+ Coverage    48.59%   51.11%   +2.51%     
===========================================
  Files           36       37       +1     
  Lines         1457     1528      +71     
===========================================
+ Hits           708      781      +73     
+ Misses         749      747       -2     
Files with missing lines Coverage Δ
include/boost/beast2/impl/body_write_stream.hpp 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a456c0f...6d83768. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

namespace detail {

template<class AsyncWriteStream>
class body_write_stream_close_op : public asio::coroutine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't composed operations simply point back to body_write_stream?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - they now hold a reference to body_write_stream

Comment on lines 70 to 75
AsyncWriteStream& stream_;
ConstBufferSequence cb_;
http_proto::serializer& sr_;
http_proto::serializer::stream& srs_;
system::error_code& saved_ec_;
std::size_t bytes_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't composed operations simply point back to body_write_stream?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - they now hold a reference to body_write_stream

Comment on lines 149 to 151
if(sr_.is_done() ||
!srs_.is_open())
ec = asio::error::not_connected;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for sr_.is_done() and !srs_.is_open() seems unnecessary. Could you please explain the logic behind it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are preconditions, so changed to asserts.

{
self.reset_cancellation_state(asio::enable_total_cancellation());

bytes_ = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary (already initialized in the ctor).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

BOOST_ASIO_HANDLER_LOCATION(
(__FILE__, __LINE__, "async_write_some"));
beast2::async_write_some(stream_, sr_, std::move(self));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the loop could be simplified in a way that the second call to async_write_some won't be needed. like:

for(;;)
{
    bytes_ = asio::buffer_copy(srs_.prepare(), cb_);
    srs_.commit(bytes_);

    BOOST_ASIO_CORO_YIELD
    {
        BOOST_ASIO_HANDLER_LOCATION(
            (__FILE__, __LINE__, "async_write_some"));
        async_write_some(stream_, sr_, std::move(self));
    }

    if(ec.failed())
    {
        if(bytes_ != 0)
        {
            saved_ec_ = ec;
            ec = {};
        }
        break;
    }

    if(bytes_ != 0)
        break;

    if(!!self.cancelled())
    {
        ec = asio::error::operation_aborted;
        break;
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated per this suggestion.

http::serializer::stream srs,
std::string const& body,
std::string const& expected_msg)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure mixing coroutine tests here is very useful, because we code against the Asio interface and expect it to work with any kind of completion token. This feels more like a capy test.

Comment on lines +656 to +660
coro_close(body_write_stream<Stream>& bws)
{
return capy::make_async_op<system::error_code>(
bws.async_close(asio::deferred));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should eventually be able to write:

co_await bws.async_close(capy::op);

without defining any any coroutine function.

@MungoG MungoG force-pushed the issue-55-async-body-write-stream branch from f1a92b8 to 6d83768 Compare January 7, 2026 20:12
@MungoG MungoG merged commit 6d83768 into cppalliance:develop Jan 7, 2026
97 of 99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants