NetClient: don't LOGERROR when flushing messages while disconnected.

The NetClient code is now threaded, and this means it can try to flush
messages while 'knowingly' being disconnected.
This can be avoided by storing some state in NetClientSession

Improves 2d40068cd1, refs #3700

Differential Revision: https://code.wildfiregames.com/D3352
This was SVN commit r24616.
This commit is contained in:
wraitii 2021-01-15 07:54:55 +00:00
parent 03fa2f4728
commit 292d2c5d19
2 changed files with 12 additions and 1 deletions

View File

@ -139,6 +139,7 @@ void CNetClientSession::Poll()
char hostname[256] = "(error)";
enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname));
LOGMESSAGE("Net client: Connected to %s:%u", hostname, (unsigned int)event.peer->address.port);
m_Connected = true;
m_IncomingMessages.push(event);
}
@ -148,6 +149,7 @@ void CNetClientSession::Poll()
// Report immediately.
LOGMESSAGE("Net client: Disconnected");
m_Connected = false;
m_IncomingMessages.push(event);
}
@ -160,7 +162,13 @@ void CNetClientSession::Flush()
ENetPacket* packet;
while (m_OutgoingMessages.pop(packet))
if (enet_peer_send(m_Server, CNetHost::DEFAULT_CHANNEL, packet) < 0)
LOGERROR("NetClient: Failed to send packet to server");
{
// Report the error, but do so silently if we know we are disconnected.
if (m_Connected)
LOGERROR("NetClient: Failed to send packet to server");
else
LOGMESSAGE("NetClient: Failed to send packet to server");
}
enet_host_flush(m_Host);
}

View File

@ -126,6 +126,9 @@ private:
// Net messages to send on the next flush() call.
boost::lockfree::queue<ENetPacket*> m_OutgoingMessages;
// Last know state. If false, flushing errors are silenced.
bool m_Connected = false;
// Wrapper around enet stats - those are atomic as the code is lock-free.
std::atomic<u32> m_LastReceivedTime;
std::atomic<u32> m_MeanRTT;