From 5fb96117d12b849774e149d8dfb6098b644e14e2 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 5 May 2026 04:48:40 -0400 Subject: [PATCH 1/3] Comments. --- src/net/socket.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/socket.cpp b/src/net/socket.cpp index 1c0da390f..81a305689 100644 --- a/src/net/socket.cpp +++ b/src/net/socket.cpp @@ -265,7 +265,7 @@ asio::ssl::socket& socket::get_ssl() NOEXCEPT // ---------------------------------------------------------------------------- // protected -// write framed (ws) or unframed (tcp) fixed size (const buffer size). +// write message in a single frame (ws) or unframed fixed size bytes (tcp). void socket::async_write(const asio::const_buffer& buffer, bool binary, const count_handler& handler) NOEXCEPT { @@ -294,7 +294,7 @@ void socket::async_write(const asio::const_buffer& buffer, bool binary, } } -// read some (up to mutable buffer capacity). +// read ws frames or unframed tcp bytes (up to mutable buffer capacity). void socket::async_read_some(const asio::mutable_buffer& buffer, const count_handler& handler) NOEXCEPT { @@ -320,7 +320,7 @@ void socket::async_read_some(const asio::mutable_buffer& buffer, } } -// read framed/ws (fails if beyond flat buffer capacity). +// read ws message in any number of frames (fails if beyond buffer capacity). void socket::async_read(http::flat_buffer& buffer, const count_handler& handler) NOEXCEPT { @@ -346,7 +346,7 @@ void socket::async_read(http::flat_buffer& buffer, } } -// read fixed/p2p (waits until mutable buffer is filled). +// read tcp fixed count of bytes (waits until mutable buffer is filled). void socket::async_read(const asio::mutable_buffer& buffer, const count_handler& handler) NOEXCEPT { From 8d89c0622aad77ef870789b96ade5945cf8305ec Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 5 May 2026 10:58:42 -0400 Subject: [PATCH 2/3] Allow socket body to support native body readers (ws). --- src/net/socket.cpp | 12 ++++++++---- src/net/socket_body.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/net/socket.cpp b/src/net/socket.cpp index 81a305689..9d0492942 100644 --- a/src/net/socket.cpp +++ b/src/net/socket.cpp @@ -294,7 +294,7 @@ void socket::async_write(const asio::const_buffer& buffer, bool binary, } } -// read ws frames or unframed tcp bytes (up to mutable buffer capacity). +// read ws frame or arbitrary tcp bytes, iterate (up to buffer capacity). void socket::async_read_some(const asio::mutable_buffer& buffer, const count_handler& handler) NOEXCEPT { @@ -320,7 +320,8 @@ void socket::async_read_some(const asio::mutable_buffer& buffer, } } -// read ws message in any number of frames (fails if beyond buffer capacity). +// read arbitrary tcp bytes, iterate (up to buffer capacity). +// read whole ws message in any number of frames (up to buffer capacity). void socket::async_read(http::flat_buffer& buffer, const count_handler& handler) NOEXCEPT { @@ -335,8 +336,11 @@ void socket::async_read(http::flat_buffer& buffer, } else { - // Use async_read_some() or async_read(mutable_buffer). - handler(error::operation_failed, {}); + constexpr auto size = rpc::writer::default_buffer; + VARIANT_DISPATCH_METHOD(get_tcp(), + async_read_some(buffer.prepare(size), + std::bind(&socket::handle_async, shared_from_this(), + _1, _2, handler, "async_read_some"))); } } catch (const std::exception& e) diff --git a/src/net/socket_body.cpp b/src/net/socket_body.cpp index 46f50c903..1ed4f850f 100644 --- a/src/net/socket_body.cpp +++ b/src/net/socket_body.cpp @@ -73,7 +73,13 @@ void socket::do_body_read(boost_code ec, size_t total, return; } - async_read_some(in->buffer.prepare(size), + // This reader is designed to accept native beast bodies, which require the + // buffer size to be known so that finish() is called only after all data + // is passed. For websockets this reads a full logical message into the + // flat buffer. For tcp the reader will iterate over the buffer using + // async_read_some here, and calls reader.finish() after each. So the body + // reader is usable on tcp only for bodies that allow finish() iteration. + async_read(in->buffer, std::bind(&socket::handle_body_read, shared_from_this(), _1, _2, total, in, handler)); } From 021efbcfcd97e4dcec6acc33bf2a01defa75b939 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 5 May 2026 11:02:15 -0400 Subject: [PATCH 3/3] Remove dead code. --- src/net/socket_body.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/net/socket_body.cpp b/src/net/socket_body.cpp index 1ed4f850f..583b6d134 100644 --- a/src/net/socket_body.cpp +++ b/src/net/socket_body.cpp @@ -63,7 +63,6 @@ void socket::do_body_read(boost_code ec, size_t total, const read_state::ptr& in, const count_handler& handler) NOEXCEPT { BC_ASSERT(stranded()); - constexpr auto size = rpc::writer::default_buffer; if (ec) {