Skip to content

Commit

Permalink
+ auto to_read = static_cast<std::uint64_t>(buffer_.size());
Browse files Browse the repository at this point in the history
~ if (remaining_length_ < to_read)
~   to_read = remaining_length_;
+ adaptor_.socket().async_read_some(boost::asio::buffer(buffer_, static_cast<std::size_t>(to_read))
- size_t to_read = buffer_.size();
~ if (remaining_length_ < to_read)
~   to_read = remaining_length_;
- adaptor_.socket().async_read_some( boost::asio::buffer(buffer_, to_read)

~ Changed 'to_read' from [std::size_t] to [std::uint64_t],
  hence when 'remaining_length_' [std::uint64_t] is assigned in 'to_read' no data is lossed.
  When boost::asio::buffer is created 'to_read' is casted back to [std::size_t] explicitly truncating data.
  It seems to be the correct behavior to choose fixed 'network side' types.
  • Loading branch information
Lucas David committed Jul 27, 2021
1 parent 6aa5dba commit 1bb5e0a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/crow/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ namespace crow
break;
case WebSocketReadState::Payload:
{
size_t to_read = buffer_.size();
auto to_read = static_cast<std::uint64_t>(buffer_.size());
if (remaining_length_ < to_read)
to_read = remaining_length_;
adaptor_.socket().async_read_some( boost::asio::buffer(buffer_, to_read),
adaptor_.socket().async_read_some(boost::asio::buffer(buffer_, static_cast<std::size_t>(to_read)),
[this](const boost::system::error_code& ec, std::size_t bytes_transferred)
{
is_reading = false;
Expand Down

0 comments on commit 1bb5e0a

Please sign in to comment.