Skip to content

Commit

Permalink
Use error_code instead of exception and don't display error message o…
Browse files Browse the repository at this point in the history
…n disconnection
  • Loading branch information
Jacquwes committed Sep 28, 2023
1 parent 5163984 commit 7b19d03
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions shared/src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ namespace pine
if (!bufferSize)
co_return buffer;

try
{
size_t n = socket.receive(asio::buffer(buffer));
buffer.resize(n);
}
catch (std::exception& e)
asio::error_code ec;
auto flags = asio::socket_base::message_peek;
size_t n = socket.receive(asio::buffer(buffer), flags, ec);

if (ec && ec != asio::error::connection_reset)
{
std::cout << "Failed to receive message: " << e.what() << std::endl;
std::cout << "Failed to receive message: " << std::dec << ec.value() << " -> " << ec.message() << std::endl;
co_return buffer;
}

buffer.resize(n);

co_return buffer;
}

Expand Down

0 comments on commit 7b19d03

Please sign in to comment.