From 789d24aa1c9cc7e51f8a235ed888cae5f9bc69d9 Mon Sep 17 00:00:00 2001 From: phosit Date: Sat, 7 Mar 2026 14:57:49 +0100 Subject: [PATCH] Initialize members net-sessions in the class With this members of `CNetClientSession` and `CNetServerSession` get initialized within the class instead of the constructor. --- source/network/NetSession.cpp | 6 ++---- source/network/NetSession.h | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/source/network/NetSession.cpp b/source/network/NetSession.cpp index 67aff2654e..f94a3da097 100644 --- a/source/network/NetSession.cpp +++ b/source/network/NetSession.cpp @@ -36,9 +36,7 @@ constexpr int NETCLIENT_POLL_TIMEOUT = 50; constexpr int CHANNEL_COUNT = 1; CNetClientSession::CNetClientSession(CNetClient& client) : - m_Client(client), m_FileTransferer(*this), m_Host(nullptr), m_Server(nullptr), - m_Stats(nullptr), m_IncomingMessages(16), m_OutgoingMessages(16), - m_LoopRunning(false), m_ShouldShutdown(false), m_MeanRTT(0), m_LastReceivedTime(0) + m_Client(client), m_FileTransferer(*this) { } @@ -239,7 +237,7 @@ u32 CNetClientSession::GetMeanRTT() const } CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) : - m_Server(server), m_FileTransferer(*this), m_Peer(peer), m_HostID(0), m_GUID(), m_UserName() + m_Server(server), m_FileTransferer(*this), m_Peer(peer) { } diff --git a/source/network/NetSession.h b/source/network/NetSession.h index f5adaecffd..30fcf269a8 100644 --- a/source/network/NetSession.h +++ b/source/network/NetSession.h @@ -113,9 +113,9 @@ private: CNetFileTransferer m_FileTransferer; // Net messages received and waiting for fetching. - boost::lockfree::queue m_IncomingMessages; + boost::lockfree::queue m_IncomingMessages{16}; // Net messages to send on the next flush() call. - boost::lockfree::queue m_OutgoingMessages; + boost::lockfree::queue m_OutgoingMessages{16}; // Last known state. If false, flushing errors are silenced. bool m_Connected = false; @@ -124,16 +124,16 @@ private: bool m_WasConnected = false; // Wrapper around enet stats - those are atomic as the code is lock-free. - std::atomic m_LastReceivedTime; - std::atomic m_MeanRTT; + std::atomic m_LastReceivedTime{0}; + std::atomic m_MeanRTT{0}; // If this is true, calling Connect() or deleting the session is an error. - std::atomic m_LoopRunning; - std::atomic m_ShouldShutdown; + std::atomic m_LoopRunning{false}; + std::atomic m_ShouldShutdown{false}; - ENetHost* m_Host; - ENetPeer* m_Server; - CNetStatsTable* m_Stats; + ENetHost* m_Host{nullptr}; + ENetPeer* m_Server{nullptr}; + CNetStatsTable* m_Stats{nullptr}; }; @@ -206,7 +206,7 @@ private: CStr m_GUID; CStrW m_UserName; - u32 m_HostID; + u32 m_HostID{0}; CStr m_Password; };