diff --git a/server/main_server/src/agent_main.cpp b/server/main_server/src/agent_main.cpp index 1672bf5bbc..99be61386a 100644 --- a/server/main_server/src/agent_main.cpp +++ b/server/main_server/src/agent_main.cpp @@ -832,14 +832,15 @@ namespace while (bytes_to_send) { const int bytes_sent = send(net_obj->socket_handle(), &(heartbeat[heartbeat_length - bytes_to_send]), bytes_to_send, 0); - const int errsav = errno; - if (errsav != EINTR) { - log_agent::error("{}: Socket error encountered during heartbeat; socket returned {}", - __func__, strerror(errsav)); - break; + if (bytes_sent == -1) { + const int errsav = errno; + if (errsav != EINTR) { + log_agent::error("{}: Socket error encountered during heartbeat; socket returned {}", + __func__, strerror(errsav)); + break; + } } - - if (bytes_sent > 0) { + else if (bytes_sent > 0) { bytes_to_send -= bytes_sent; } }