Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/net/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -294,7 +294,7 @@ void socket::async_write(const asio::const_buffer& buffer, bool binary,
}
}

// read some (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
{
Expand All @@ -320,7 +320,8 @@ void socket::async_read_some(const asio::mutable_buffer& buffer,
}
}

// read framed/ws (fails if beyond flat 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
{
Expand All @@ -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)
Expand All @@ -346,7 +350,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
{
Expand Down
9 changes: 7 additions & 2 deletions src/net/socket_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -73,7 +72,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));
}
Expand Down
Loading