void SocketWire::Base::ping()

in src/cpp/RiderLink/Source/RD/src/rd_framework_cpp/src/main/wire/SocketWire.cpp [374:412]


void SocketWire::Base::ping() const
{
	if (!connection_established(current_timestamp, counterpart_acknowledge_timestamp))
	{
		if (heartbeatAlive.get())
		{	 // only on change
			logger->trace(
				"Disconnect detected while sending PING {}: "
				"current_timestamp: {}, "
				"counterpart_timestamp: {}, "
				"counterpart_acknowledge_timestamp: {}",
				this->id, current_timestamp, counterpart_timestamp, counterpart_acknowledge_timestamp);
		}
		heartbeatAlive.set(false);
	}
	try
	{
		ping_pkg_header.set_position(sizeof(PING_MESSAGE_LENGTH));
		ping_pkg_header.write_integral(current_timestamp);
		ping_pkg_header.write_integral(counterpart_timestamp);
		{
			std::lock_guard<decltype(socket_send_lock)> guard(socket_send_lock);
			int32_t sent = socket_provider->Send(ping_pkg_header.data(), ping_pkg_header.get_position());
			if (sent == 0 && !socket_provider->IsSocketValid())
			{
				logger->debug("{}: failed to send ping over the network, reason: socket was shut down for sending", this->id);
				return;
			}
			RD_ASSERT_THROW_MSG(sent == PACKAGE_HEADER_LENGTH,
				fmt::format("{}: failed to send ping over the network, reason: {}", this->id, socket_provider->DescribeError()))
		}

		++current_timestamp;
	}
	catch (std::exception const& e)
	{
		logger->debug("{}: exception raised during PING | {}", this->id, e.what());
	}
}