Skip to content

Commit

Permalink
Only update stats and socket events if operation is successful
Browse files Browse the repository at this point in the history
We were not checking the result of the connect, send, recv operations.
We assumed that they were successful and treated them as successful, which
gave at least wrong stats and possibly other minor problems too.
  • Loading branch information
dsiganos committed Jan 31, 2022
1 parent f308f40 commit 44df506
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions nano/node/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ void nano::socket::async_connect (nano::tcp_endpoint const & endpoint_a, std::fu
this_l->tcp_socket.async_connect (endpoint_a,
boost::asio::bind_executor (this_l->strand,
[this_l, callback = std::move (callback_a), endpoint_a] (boost::system::error_code const & ec) {
this_l->stop_timer ();
if (!ec)
{
this_l->stop_timer ();
}
this_l->remote = endpoint_a;
callback (ec);
}));
Expand All @@ -80,9 +83,12 @@ void nano::socket::async_read (std::shared_ptr<std::vector<uint8_t>> const & buf
boost::asio::async_read (this_l->tcp_socket, boost::asio::buffer (buffer_a->data (), size_a),
boost::asio::bind_executor (this_l->strand,
[this_l, buffer_a, cbk = std::move (callback)] (boost::system::error_code const & ec, std::size_t size_a) {
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::in, size_a);
this_l->stop_timer ();
this_l->update_last_receive_time ();
if (!ec)
{
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::in, size_a);
this_l->stop_timer ();
this_l->update_last_receive_time ();
}
cbk (ec, size_a);
}));
}));
Expand All @@ -109,8 +115,11 @@ void nano::socket::async_write (nano::shared_const_buffer const & buffer_a, std:
boost::asio::bind_executor (this_l->strand,
[buffer_a, cbk = std::move (callback), this_l] (boost::system::error_code ec, std::size_t size_a) {
--this_l->queue_size;
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::out, size_a);
this_l->stop_timer ();
if (!ec)
{
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::out, size_a);
this_l->stop_timer ();
}
if (cbk)
{
cbk (ec, size_a);
Expand Down

0 comments on commit 44df506

Please sign in to comment.