From 4a7166bd6bbada22b3aef99225b587ff6fb21885 Mon Sep 17 00:00:00 2001 From: Fletcher Dunn Date: Tue, 22 May 2018 17:39:05 -0700 Subject: [PATCH] Adjust convars for log levels. Make message object plain C struct. --- .../isteamnetworkingsockets.h | 9 +- .../steamnetworkingsockets_flat.h | 4 +- .../steamnetworkingtypes.h | 251 +++++++++--------- .../clientlib/csteamnetworkingsockets.cpp | 30 +-- .../clientlib/csteamnetworkingsockets.h | 4 +- .../clientlib/steamnetworkingconfig.h | 16 +- .../steamnetworkingsockets_connections.cpp | 60 +++-- .../steamnetworkingsockets_connections.h | 17 +- .../clientlib/steamnetworkingsockets_flat.cpp | 4 +- .../steamnetworkingsockets_lowlevel.h | 4 +- .../clientlib/steamnetworkingsockets_snp.cpp | 94 ++++--- tests/connection_test.cpp | 13 +- 12 files changed, 248 insertions(+), 258 deletions(-) diff --git a/include/steamnetworkingsockets/isteamnetworkingsockets.h b/include/steamnetworkingsockets/isteamnetworkingsockets.h index 88fc09e..70bef4a 100644 --- a/include/steamnetworkingsockets/isteamnetworkingsockets.h +++ b/include/steamnetworkingsockets/isteamnetworkingsockets.h @@ -221,17 +221,17 @@ public: /// If any messages are returned, you MUST call Release() to each of them free up resources /// after you are done. It is safe to keep the object alive for a little while (put it /// into some queue, etc), and you may call Release() from any thread. - virtual int ReceiveMessagesOnConnection( HSteamNetConnection hConn, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) = 0; + virtual int ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) = 0; /// Same as ReceiveMessagesOnConnection, but will return the next message available - /// on any client socket that was accepted through the specified listen socket. Use - /// ISteamNetworkingMessage::GetConnection to know which client connection. + /// on any client socket that was accepted through the specified listen socket. Examine + /// SteamNetworkingMessage_t::m_conn to know which client connection. /// /// Delivery order of messages among different clients is not defined. They may /// be returned in an order different from what they were actually received. (Delivery /// order of messages from the same client is well defined, and thus the order of the /// messages is relevant!) - virtual int ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) = 0; + virtual int ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) = 0; /// Returns information about the specified connection. virtual bool GetConnectionInfo( HSteamNetConnection hConn, SteamNetConnectionInfo_t *pInfo ) = 0; @@ -459,6 +459,7 @@ enum ESteamNetworkingSocketsDebugOutputType k_ESteamNetworkingSocketsDebugOutputType_Msg, // Recommended amount k_ESteamNetworkingSocketsDebugOutputType_Verbose, // Quite a bit k_ESteamNetworkingSocketsDebugOutputType_Debug, // Practically everything + k_ESteamNetworkingSocketsDebugOutputType_Everything, // Everything }; /// Setup callback for debug output, and the desired verbosity you want. diff --git a/include/steamnetworkingsockets/steamnetworkingsockets_flat.h b/include/steamnetworkingsockets/steamnetworkingsockets_flat.h index 7ddeb9f..78ee2ec 100644 --- a/include/steamnetworkingsockets/steamnetworkingsockets_flat.h +++ b/include/steamnetworkingsockets/steamnetworkingsockets_flat.h @@ -29,8 +29,8 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetConnectionName( STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingSockets_GetConnectionName( HSteamNetConnection hPeer, char *pszName, int nMaxLen ); STEAMNETWORKINGSOCKETS_INTERFACE EResult SteamNetworkingSockets_SendMessageToConnection( HSteamNetConnection hConn, const void *pData, uint32 cbData, ESteamNetworkingSendType eSendType ); STEAMNETWORKINGSOCKETS_INTERFACE EResult SteamNetworkingSockets_FlushMessagesOnConnection( HSteamNetConnection hConn ); -STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnConnection( HSteamNetConnection hConn, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ); -STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ); +STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ); +STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ); STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingSockets_GetConnectionInfo( HSteamNetConnection hConn, SteamNetConnectionInfo_t *pInfo ); STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingSockets_GetQuickConnectionStatus( HSteamNetConnection hConn, SteamNetworkingQuickConnectionStatus *pStats ); STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_GetDetailedConnectionStatus( HSteamNetConnection hConn, char *pszBuf, int cbBuf ); diff --git a/include/steamnetworkingsockets/steamnetworkingtypes.h b/include/steamnetworkingsockets/steamnetworkingtypes.h index 734ffcf..e761b93 100644 --- a/include/steamnetworkingsockets/steamnetworkingtypes.h +++ b/include/steamnetworkingsockets/steamnetworkingtypes.h @@ -17,7 +17,7 @@ #pragma pack( push, 8 ) struct SteamNetworkPingLocation_t; -class ISteamNetworkingMessage; +struct SteamNetworkingMessage_t; /// Handle used to identify a connection to a remote host. typedef uint32 HSteamNetConnection; @@ -237,32 +237,27 @@ typedef int64 SteamNetworkingMicroseconds; /// and our peer might, too. const int k_cbMaxSteamNetworkingSocketsMessageSizeSend = 512 * 1024; -/// A message that has been received. -class ISteamNetworkingMessage +/// Message that has been received +struct SteamNetworkingMessage_t { -public: - /// You MUST call this when you're done with the object, - /// to free up memory, etc. - virtual void Release() = 0; + /// Size of the payload. + uint32 m_cbSize; - /// Get size of the payload. - inline uint32 GetSize() const { return m_cbSize; } + /// Message payload + void *m_pData; - /// Get message payload - inline const void *GetData() const { return m_pData; } + /// SteamID that sent this to us. + CSteamID m_steamIDSender; - /// Return SteamID that sent this to us. - inline CSteamID GetSenderSteamID() const { return m_steamIDSender; } - - /// Return the channel number the message was received on. + /// The channel number the message was received on. /// (Not used for messages received on "connections" - inline int GetChannel() const { return m_nChannel; } + int m_nChannel; - /// The socket this came from. (Not used when using the P2P calls) - inline HSteamNetConnection GetConnection() const { return m_conn; } + /// The connection this came from. (Not used when using the P2P calls) + HSteamNetConnection m_conn; - /// Get the user data associated with the connection. + /// The user data associated with the connection. /// /// This is *usually* the same as calling GetConnection() and then /// fetching the user data associated with that connection, but for @@ -275,27 +270,42 @@ public: /// - This is an inline call, so it's *much* faster. /// - You might have closed the connection, so fetching the user data /// would not be possible. - inline int64 GetConnectionUserData() const { return m_nConnUserData; } + int64 m_nConnUserData; - /// Get the time that it was received - inline SteamNetworkingMicroseconds GetTimeReceived() const { return m_usecTimeReceived; } + /// Local timestamps when it was received + SteamNetworkingMicroseconds m_usecTimeReceived; /// Message number assigned by the sender - inline int64 GetMessageNumber() const { return m_nMessageNumber; } - -protected: - CSteamID m_steamIDSender; - void *m_pData; - uint32 m_cbSize; - int m_nChannel; - HSteamNetConnection m_conn; - int64 m_nConnUserData; - SteamNetworkingMicroseconds m_usecTimeReceived; int64 m_nMessageNumber; - inline ~ISteamNetworkingMessage() {} // Destructor hidden - use Release()! But make it inline and empty, in case you want to derive your own type that satisfies this interface for use in your code. + /// Function used to clean up this object. Normally you won't call + /// this directly, use Release() instead. + void (*m_pfnRelease)( SteamNetworkingMessage_t *msg ); + + #ifdef __cplusplus + + /// You MUST call this when you're done with the object, + /// to free up memory, etc. + inline void Release() + { + m_pfnRelease( this ); + } + + // For code compatibility, some accessors + inline uint32 GetSize() const { return m_cbSize; } + inline const void *GetData() const { return m_pData; } + inline CSteamID GetSenderSteamID() const { return m_steamIDSender; } + inline int GetChannel() const { return m_nChannel; } + inline HSteamNetConnection GetConnection() const { return m_conn; } + inline int64 GetConnectionUserData() const { return m_nConnUserData; } + inline SteamNetworkingMicroseconds GetTimeReceived() const { return m_usecTimeReceived; } + inline int64 GetMessageNumber() const { return m_nMessageNumber; } + #endif }; +// For code compatibility +typedef SteamNetworkingMessage_t ISteamNetworkingMessage; + /// Object that describes a "location" on the Internet with sufficient /// detail that we can reasonably estimate an upper bound on the ping between /// the two hosts, even if a direct route between the hosts is not possible, @@ -617,90 +627,86 @@ struct SteamNetworkingQuickConnectionStatus /// of various subsystems enum ESteamNetworkingConfigurationValue { - // 0-100 Randomly discard N pct of unreliable messages instead of sending - // Defaults to 0 (no loss). - k_ESteamNetworkingConfigurationValue_FakeMessageLoss_Send = 1, + /// 0-100 Randomly discard N pct of unreliable messages instead of sending + /// Defaults to 0 (no loss). + k_ESteamNetworkingConfigurationValue_FakeMessageLoss_Send = 0, - // 0-100 Randomly discard N pct of unreliable messages upon receive - // Defaults to 0 (no loss). - k_ESteamNetworkingConfigurationValue_FakeMessageLoss_Recv = 2, + /// 0-100 Randomly discard N pct of unreliable messages upon receive + /// Defaults to 0 (no loss). + k_ESteamNetworkingConfigurationValue_FakeMessageLoss_Recv = 1, - // 0-100 Randomly discard N pct of packets instead of sending - k_ESteamNetworkingConfigurationValue_FakePacketLoss_Send = 3, + /// 0-100 Randomly discard N pct of packets instead of sending + k_ESteamNetworkingConfigurationValue_FakePacketLoss_Send = 2, - // 0-100 Randomly discard N pct of packets received - k_ESteamNetworkingConfigurationValue_FakePacketLoss_Recv = 4, + /// 0-100 Randomly discard N pct of packets received + k_ESteamNetworkingConfigurationValue_FakePacketLoss_Recv = 3, - // DELETED - //k_ESteamNetworkingConfigurationValue_SNP_DebugWindow = 5, + /// Globally delay all outbound packets by N ms before sending + k_ESteamNetworkingConfigurationValue_FakePacketLag_Send = 4, - // Upper limit of buffered pending bytes to be sent, if this is reached - // SendMessage will return k_EResultLimitExceeded - // Default is 512k (524288 bytes) - k_ESteamNetworkingConfigurationValue_SNP_SendBufferSize = 6, + /// Globally delay all received packets by N ms before processing + k_ESteamNetworkingConfigurationValue_FakePacketLag_Recv = 5, - // Maximum send rate clamp, 0 is no limit - // This value will control the maximum allowed sending rate that congestion - // is allowed to reach. Default is 0 (no-limit) - k_ESteamNetworkingConfigurationValue_SNP_MaxRate = 7, + /// Globally reorder some percentage of packets we send + k_ESteamNetworkingConfigurationValue_FakePacketReorder_Send = 6, - // Minimum send rate clamp, 0 is no limit - // This value will control the minimum allowed sending rate that congestion - // is allowed to reach. Default is 0 (no-limit) - k_ESteamNetworkingConfigurationValue_SNP_MinRate = 8, + /// Globally reorder some percentage of packets we receive + k_ESteamNetworkingConfigurationValue_FakePacketReorder_Recv = 7, - // Set the nagle timer. When SendMessage is called, if the outgoing message - // is less than the size of the MTU, it will be queued for a delay equal to - // the Nagle timer value. This is to ensure that if the application sends - // several small messages rapidly, they are coalesced into a single packet. - // See historical RFC 896. Value is in microseconds. - // Default is 5000us (5ms). - k_ESteamNetworkingConfigurationValue_SNP_Nagle_Time = 9, + /// Amount of delay, in ms, to apply to reordered packets. + k_ESteamNetworkingConfigurationValue_FakePacketReorder_Time = 8, - // Set to true (non-zero) to enable logging of SNP RTT - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_RTT = 10, + /// Upper limit of buffered pending bytes to be sent, if this is reached + /// SendMessage will return k_EResultLimitExceeded + /// Default is 512k (524288 bytes) + k_ESteamNetworkingConfigurationValue_SendBufferSize = 9, - // Set to true (non-zero) to enable logging of SNP Packet - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Packet = 11, + /// Maximum send rate clamp, 0 is no limit + /// This value will control the maximum allowed sending rate that congestion + /// is allowed to reach. Default is 0 (no-limit) + k_ESteamNetworkingConfigurationValue_MaxRate = 10, - // Set to true (non-zero) to enable logging of SNP Segments - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Segments = 12, + /// Minimum send rate clamp, 0 is no limit + /// This value will control the minimum allowed sending rate that congestion + /// is allowed to reach. Default is 0 (no-limit) + k_ESteamNetworkingConfigurationValue_MinRate = 11, - // Set to true (non-zero) to enable logging of SNP Feedback - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Feedback = 13, + /// Set the nagle timer. When SendMessage is called, if the outgoing message + /// is less than the size of the MTU, it will be queued for a delay equal to + /// the Nagle timer value. This is to ensure that if the application sends + /// several small messages rapidly, they are coalesced into a single packet. + /// See historical RFC 896. Value is in microseconds. + /// Default is 5000us (5ms). + k_ESteamNetworkingConfigurationValue_Nagle_Time = 12, - // Set to true (non-zero) to enable logging of SNP Relible - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Reliable = 14, - - // Set to true (non-zero) to enable logging of SNP Messages - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Message = 15, + /// Set to true (non-zero) to enable logging of RTT's based on acks. + /// This doesn't track all sources of RTT, just the inline ones based + /// on acks, but those are the most common + k_ESteamNetworkingConfigurationValue_LogLevel_AckRTT = 13, - // Set to true (non-zero) to enable logging of SNP Loss - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Loss = 16, + /// Log level of SNP packet decoding + k_ESteamNetworkingConfigurationValue_LogLevel_Packet = 14, - // Set to true (non-zero) to enable logging of SNP Throughput - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_X = 17, + /// Log when messages are sent/received + k_ESteamNetworkingConfigurationValue_LogLevel_Message = 15, - // Set to true (non-zero) to enable logging of Nagle timing - // Default is 0 (off) - k_ESteamNetworkingConfigurationValue_SNP_Log_Nagle = 18, + /// Log level when individual packets drop + k_ESteamNetworkingConfigurationValue_LogLevel_PacketGaps = 16, - // If the first N pings to a port all fail, mark that port as unavailable for - // a while, and try a different one. Some ISPs and routers may drop the first - // packet, so setting this to 1 may greatly disrupt communications. + /// Log level for P2P rendezvous. + k_ESteamNetworkingConfigurationValue_LogLevel_P2PRendezvous = 17, + + /// Log level for sending and receiving pings to relays + k_ESteamNetworkingConfigurationValue_LogLevel_RelayPings = 18, + + /// If the first N pings to a port all fail, mark that port as unavailable for + /// a while, and try a different one. Some ISPs and routers may drop the first + /// packet, so setting this to 1 may greatly disrupt communications. k_ESteamNetworkingConfigurationValue_ClientConsecutitivePingTimeoutsFailInitial = 19, - // If N consecutive pings to a port fail, after having received successful - // communication, mark that port as unavailable for a while, and try a - // different one. + /// If N consecutive pings to a port fail, after having received successful + /// communication, mark that port as unavailable for a while, and try a + /// different one. k_ESteamNetworkingConfigurationValue_ClientConsecutitivePingTimeoutsFail = 20, /// Minimum number of lifetime pings we need to send, before we think our estimate @@ -710,43 +716,28 @@ enum ESteamNetworkingConfigurationValue /// many pings. k_ESteamNetworkingConfigurationValue_ClientMinPingsBeforePingAccurate = 21, - // Set all steam datagram traffic to originate from the same local port. - // By default, we open up a new UDP socket (on a different local port) - // for each relay. This is not optimal, but it works around some - // routers that don't implement NAT properly. If you have intermittent - // problems talking to relays that might be NAT related, try toggling - // this flag + /// Set all steam datagram traffic to originate from the same local port. + /// By default, we open up a new UDP socket (on a different local port) + /// for each relay. This is not optimal, but it works around some + /// routers that don't implement NAT properly. If you have intermittent + /// problems talking to relays that might be NAT related, try toggling + /// this flag k_ESteamNetworkingConfigurationValue_ClientSingleSocket = 22, - // Globally delay all outbound packets by N ms before sending - k_ESteamNetworkingConfigurationValue_FakePacketLag_Send = 23, + /// Don't automatically fail IP connections that don't have strong auth. + /// On clients, this means we will attempt the connection even if we don't + /// know our SteamID or can't get a cert. On the server, it means that we won't + /// automatically reject a connection due to a failure to authenticate. + /// (You can examine the incoming connection and decide whether to accept it.) + k_ESteamNetworkingConfigurationValue_IP_Allow_Without_Auth = 23, - // Globally delay all received packets by N ms before processing - k_ESteamNetworkingConfigurationValue_FakePacketLag_Recv = 24, + /// Timeout value (in seconds) to use when first connecting + k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Initial = 24, - // Don't automatically fail IP connections that don't have strong auth. - // On clients, this means we will attempt the connection even if we don't - // know our SteamID or can't get a cert. On the server, it means that we won't - // automatically reject a connection due to a failure to authenticate. - // (You can examine the incoming connection and decide whether to accept it.) - k_ESteamNetworkingConfigurationValue_IP_Allow_Without_Auth = 25, + /// Timeout value (in seconds) to use after connection is established + k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Connected = 25, - // Timeout value (in seconds) to use when first connecting - k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Initial = 26, - - // Timeout value (in seconds) to use after connection is established - k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Connected = 27, - - // Globally reorder some percentage of packets we send - k_ESteamNetworkingConfigurationValue_FakePacketReorder_Send = 28, - - // Globally reorder some percentage of packets we receive - k_ESteamNetworkingConfigurationValue_FakePacketReorder_Recv = 29, - - // Amount of delay, in ms, to apply to reordered packets. - k_ESteamNetworkingConfigurationValue_FakePacketReorder_Time = 30, - - // Number of k_ESteamNetworkingConfigurationValue defines + /// Number of k_ESteamNetworkingConfigurationValue defines k_ESteamNetworkingConfigurationValue_Count, }; diff --git a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp index 386b027..a60baa4 100644 --- a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp +++ b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp @@ -48,19 +48,16 @@ static SConfigurationValueEntry sConfigurationValueEntryList[] = { k_ESteamNetworkingConfigurationValue_FakePacketReorder_Recv, "FakePacketReorder_Recv", &steamdatagram_fakepacketreorder_recv }, { k_ESteamNetworkingConfigurationValue_FakePacketReorder_Time, "FakePacketReorder_Time", &steamdatagram_fakepacketreorder_time }, - { k_ESteamNetworkingConfigurationValue_SNP_SendBufferSize, "SNP_SendBufferSize", &steamdatagram_snp_send_buffer_size }, - { k_ESteamNetworkingConfigurationValue_SNP_MaxRate, "SNP_MaxRate", &steamdatagram_snp_max_rate }, - { k_ESteamNetworkingConfigurationValue_SNP_MinRate, "SNP_MinRate", &steamdatagram_snp_min_rate }, - { k_ESteamNetworkingConfigurationValue_SNP_Nagle_Time, "SNP_Nagle_Time", &steamdatagram_snp_nagle_time }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_RTT, "SNP_Log_RTT", &steamdatagram_snp_log_rtt }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Packet, "SNP_Log_Packet", &steamdatagram_snp_log_packet }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Segments, "SNP_Log_Segments", &steamdatagram_snp_log_segments }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Feedback, "SNP_Log_Feedback", &steamdatagram_snp_log_feedback }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Reliable, "SNP_Log_Reliable", &steamdatagram_snp_log_reliable }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Message, "SNP_Log_Message", &steamdatagram_snp_log_message }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Loss, "SNP_Log_Loss", &steamdatagram_snp_log_loss }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_X, "SNP_Log_X", &steamdatagram_snp_log_x }, - { k_ESteamNetworkingConfigurationValue_SNP_Log_Nagle, "SNP_Log_Nagle", &steamdatagram_snp_log_nagle }, + { k_ESteamNetworkingConfigurationValue_SendBufferSize, "SendBufferSize", &steamdatagram_snp_send_buffer_size }, + { k_ESteamNetworkingConfigurationValue_MaxRate, "MaxRate", &steamdatagram_snp_max_rate }, + { k_ESteamNetworkingConfigurationValue_MinRate, "MinRate", &steamdatagram_snp_min_rate }, + { k_ESteamNetworkingConfigurationValue_Nagle_Time, "Nagle_Time", &steamdatagram_snp_nagle_time }, + { k_ESteamNetworkingConfigurationValue_LogLevel_AckRTT, "Log_AckRTT", &steamdatagram_snp_log_ackrtt }, + { k_ESteamNetworkingConfigurationValue_LogLevel_Packet, "Log_Packet", &steamdatagram_snp_log_packet }, + { k_ESteamNetworkingConfigurationValue_LogLevel_Message, "Log_Message", &steamdatagram_snp_log_message }, + { k_ESteamNetworkingConfigurationValue_LogLevel_PacketGaps, "Log_PacketGaps", &steamdatagram_snp_log_packetgaps }, + { k_ESteamNetworkingConfigurationValue_LogLevel_P2PRendezvous, "Log_p2prendezvous", &steamdatagram_snp_log_p2prendezvous }, + { k_ESteamNetworkingConfigurationValue_LogLevel_RelayPings, "Log_RelayPings", &steamdatagram_snp_log_relaypings }, { k_ESteamNetworkingConfigurationValue_ClientConsecutitivePingTimeoutsFailInitial, "ClientConsecutitivePingTimeoutsFailInitial", &steamdatagram_client_consecutitive_ping_timeouts_fail_initial }, { k_ESteamNetworkingConfigurationValue_ClientConsecutitivePingTimeoutsFail, "ClientConsecutitivePingTimeoutsFail", &steamdatagram_client_consecutitive_ping_timeouts_fail }, { k_ESteamNetworkingConfigurationValue_ClientMinPingsBeforePingAccurate, "ClientMinPingsBeforePingAccurate", &steamdatagram_client_min_pings_before_ping_accurate }, @@ -69,8 +66,7 @@ static SConfigurationValueEntry sConfigurationValueEntryList[] = { k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Initial, "TimeoutSecondsInitial", &steamdatagram_timeout_seconds_initial }, { k_ESteamNetworkingConfigurationValue_Timeout_Seconds_Connected, "TimeoutSecondsConnected", &steamdatagram_timeout_seconds_connected }, }; -const int k_nDeprecated = 2; -COMPILE_TIME_ASSERT( sizeof( sConfigurationValueEntryList ) / sizeof( SConfigurationValueEntry ) == k_ESteamNetworkingConfigurationValue_Count - k_nDeprecated ); +COMPILE_TIME_ASSERT( sizeof( sConfigurationValueEntryList ) / sizeof( SConfigurationValueEntry ) == k_ESteamNetworkingConfigurationValue_Count ); struct SConfigurationStringEntry { @@ -679,7 +675,7 @@ EResult CSteamNetworkingSockets::FlushMessagesOnConnection( HSteamNetConnection return pConn->APIFlushMessageOnConnection(); } -int CSteamNetworkingSockets::ReceiveMessagesOnConnection( HSteamNetConnection hConn, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +int CSteamNetworkingSockets::ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { SteamDatagramTransportLock scopeLock; CSteamNetworkConnectionBase *pConn = GetConnectionByHandle( hConn ); @@ -688,7 +684,7 @@ int CSteamNetworkingSockets::ReceiveMessagesOnConnection( HSteamNetConnection hC return pConn->APIReceiveMessages( ppOutMessages, nMaxMessages ); } -int CSteamNetworkingSockets::ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +int CSteamNetworkingSockets::ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { SteamDatagramTransportLock scopeLock; CSteamNetworkListenSocketBase *pSock = GetListenSockedByHandle( hSocket ); diff --git a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.h b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.h index a72f353..54cc57f 100644 --- a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.h +++ b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.h @@ -176,8 +176,8 @@ public: virtual bool GetConnectionName( HSteamNetConnection hPeer, char *pszName, int nMaxLen ) OVERRIDE; virtual EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, uint32 cbData, ESteamNetworkingSendType eSendType ) OVERRIDE; virtual EResult FlushMessagesOnConnection( HSteamNetConnection hConn ) OVERRIDE; - virtual int ReceiveMessagesOnConnection( HSteamNetConnection hConn, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) OVERRIDE; - virtual int ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) OVERRIDE; + virtual int ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) OVERRIDE; + virtual int ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) OVERRIDE; virtual bool GetConnectionInfo( HSteamNetConnection hConn, SteamNetConnectionInfo_t *pInfo ) OVERRIDE; virtual bool GetQuickConnectionStatus( HSteamNetConnection hConn, SteamNetworkingQuickConnectionStatus *pStats ) OVERRIDE; virtual int GetDetailedConnectionStatus( HSteamNetConnection hConn, char *pszBuf, int cbBuf ) OVERRIDE; diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingconfig.h b/src/steamnetworkingsockets/clientlib/steamnetworkingconfig.h index d1ae633..68f8b02 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingconfig.h +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingconfig.h @@ -65,15 +65,13 @@ SDT_EXTERNAL int32 steamdatagram_fakepacketreorder_time SDT_DEFAULT( 15 ); // Ho SDT_EXTERNAL int32 steamdatagram_snp_send_buffer_size SDT_DEFAULT( 524288 ); // Upper limit of buffered pending bytes to be sent SDT_EXTERNAL int32 steamdatagram_snp_max_rate SDT_DEFAULT( 1000000 ); // Maximum send rate clamp, 0 is no limit SDT_EXTERNAL int32 steamdatagram_snp_min_rate SDT_DEFAULT( 128000 ); // Mininum send rate clamp, 0 is no limit -SDT_EXTERNAL int32 steamdatagram_snp_log_rtt SDT_DEFAULT( 0 ); // Enable logging of SNP RTT -SDT_EXTERNAL int32 steamdatagram_snp_log_packet SDT_DEFAULT( 0 ); // Enable logging of SNP Packet -SDT_EXTERNAL int32 steamdatagram_snp_log_segments SDT_DEFAULT( 0 ); // Enable logging of SNP Segments -SDT_EXTERNAL int32 steamdatagram_snp_log_feedback SDT_DEFAULT( 0 ); // Enable logging of SNP Feedback -SDT_EXTERNAL int32 steamdatagram_snp_log_reliable SDT_DEFAULT( 0 ); // Enable logging of SNP Relible -SDT_EXTERNAL int32 steamdatagram_snp_log_message SDT_DEFAULT( 0 ); // Enable logging of SNP Messages -SDT_EXTERNAL int32 steamdatagram_snp_log_loss SDT_DEFAULT( 0 ); // Enable logging of SNP loss calc -SDT_EXTERNAL int32 steamdatagram_snp_log_x SDT_DEFAULT( 0 ); // Enable logging of SNP X (throughput) calc -SDT_EXTERNAL int32 steamdatagram_snp_log_nagle SDT_DEFAULT( 0 ); // Enable logging of Nagle timer + +SDT_EXTERNAL int32 steamdatagram_snp_log_ackrtt SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Everything ); +SDT_EXTERNAL int32 steamdatagram_snp_log_packet SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Everything ); +SDT_EXTERNAL int32 steamdatagram_snp_log_message SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Everything ); +SDT_EXTERNAL int32 steamdatagram_snp_log_packetgaps SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Debug ); +SDT_EXTERNAL int32 steamdatagram_snp_log_p2prendezvous SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Verbose ); +SDT_EXTERNAL int32 steamdatagram_snp_log_relaypings SDT_DEFAULT( k_ESteamNetworkingSocketsDebugOutputType_Debug ); SDT_EXTERNAL int32 steamdatagram_snp_nagle_time SDT_DEFAULT( 5000 ); // Default Nagle delay diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp index 6b73e8f..0971a16 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp @@ -88,35 +88,42 @@ const TrustedKey s_arTrustedKeys[1] = { // ///////////////////////////////////////////////////////////////////////////// -inline CSteamNetworkingMessage::~CSteamNetworkingMessage() {} - -CSteamNetworkingMessage::CSteamNetworkingMessage( CSteamNetworkConnectionBase *pParent, uint32 cbSize, int64 nMsgNum, SteamNetworkingMicroseconds usecNow ) +CSteamNetworkingMessage *CSteamNetworkingMessage::New( CSteamNetworkConnectionBase *pParent, uint32 cbSize, int64 nMsgNum, SteamNetworkingMicroseconds usecNow ) { - m_steamIDSender = pParent->m_steamIDRemote; - m_pData = malloc( cbSize ); - m_cbSize = cbSize; - m_nChannel = -1; - m_conn = pParent->m_hConnectionSelf; - m_nConnUserData = pParent->GetUserData(); - m_usecTimeReceived = usecNow; - m_nMessageNumber = nMsgNum; + // FIXME Should avoid this dynamic memory call with some sort of pooling + CSteamNetworkingMessage *pMsg = new CSteamNetworkingMessage; + + pMsg->m_steamIDSender = pParent->m_steamIDRemote; + pMsg->m_pData = malloc( cbSize ); + pMsg->m_cbSize = cbSize; + pMsg->m_nChannel = -1; + pMsg->m_conn = pParent->m_hConnectionSelf; + pMsg->m_nConnUserData = pParent->GetUserData(); + pMsg->m_usecTimeReceived = usecNow; + pMsg->m_nMessageNumber = nMsgNum; + pMsg->m_pfnRelease = CSteamNetworkingMessage::Delete; + + return pMsg; } -void CSteamNetworkingMessage::Release() +void CSteamNetworkingMessage::Delete( SteamNetworkingMessage_t *pIMsg ) { - free( m_pData ); + CSteamNetworkingMessage *pMsg = static_cast( pIMsg ); + + free( pMsg->m_pData ); // We must not currently be in any queue. In fact, our parent // might have been destroyed. - Assert( !m_linksSameConnection.m_pQueue ); - Assert( !m_linksSameConnection.m_pPrev ); - Assert( !m_linksSameConnection.m_pNext ); - Assert( !m_linksSecondaryQueue.m_pQueue ); - Assert( !m_linksSecondaryQueue.m_pPrev ); - Assert( !m_linksSecondaryQueue.m_pNext ); + Assert( !pMsg->m_linksSameConnection.m_pQueue ); + Assert( !pMsg->m_linksSameConnection.m_pPrev ); + Assert( !pMsg->m_linksSameConnection.m_pNext ); + Assert( !pMsg->m_linksSecondaryQueue.m_pQueue ); + Assert( !pMsg->m_linksSecondaryQueue.m_pPrev ); + Assert( !pMsg->m_linksSecondaryQueue.m_pNext ); // Self destruct - delete this; + // FIXME Should avoid this dynamic memory call with some sort of pooling + delete pMsg; } void CSteamNetworkingMessage::LinkToQueueTail( Links CSteamNetworkingMessage::*pMbrLinks, SteamNetworkingMessageQueue *pQueue ) @@ -204,7 +211,7 @@ void SteamNetworkingMessageQueue::PurgeMessages() } } -int SteamNetworkingMessageQueue::RemoveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +int SteamNetworkingMessageQueue::RemoveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { int nMessagesReturned = 0; @@ -266,7 +273,7 @@ void CSteamNetworkListenSocketBase::Destroy() delete this; } -int CSteamNetworkListenSocketBase::APIReceiveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +int CSteamNetworkListenSocketBase::APIReceiveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { return m_queueRecvMessages.RemoveMessages( ppOutMessages, nMaxMessages ); } @@ -1237,7 +1244,7 @@ EResult CSteamNetworkConnectionBase::APIFlushMessageOnConnection() return SNP_FlushMessage( usecNow ); } -int CSteamNetworkConnectionBase::APIReceiveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +int CSteamNetworkConnectionBase::APIReceiveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { return m_queueRecvMessages.RemoveMessages( ppOutMessages, nMaxMessages ); } @@ -1417,8 +1424,13 @@ void CSteamNetworkConnectionBase::ReceivedMessage( const void *pData, int cbData // Assert( sizeof(*pTestMsg) - sizeof(pTestMsg->m_data) + pTestMsg->m_cbSize == cbData ); // #endif + SpewType( steamdatagram_snp_log_message, "%s: RecvMessage MsgNum=%lld sz=%d\n", + m_sName.c_str(), + (long long)nMsgNum, + cbData ); + // Create a message - CSteamNetworkingMessage *pMsg = new CSteamNetworkingMessage( this, cbData, nMsgNum, usecNow ); + CSteamNetworkingMessage *pMsg = CSteamNetworkingMessage::New( this, cbData, nMsgNum, usecNow ); // Add to end of my queue. pMsg->LinkToQueueTail( &CSteamNetworkingMessage::m_linksSameConnection, &m_queueRecvMessages ); diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h index a220014..2fe4f6c 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h @@ -63,13 +63,11 @@ public: // ///////////////////////////////////////////////////////////////////////////// -class CSteamNetworkingMessage : public ISteamNetworkingMessage +class CSteamNetworkingMessage : public SteamNetworkingMessage_t { public: - CSteamNetworkingMessage( CSteamNetworkConnectionBase *pParent, uint32 cbSize, int64 nMsgNum, SteamNetworkingMicroseconds usecNow ); - - /// Implements ISteamNetworkingMessage - virtual void Release(); + static CSteamNetworkingMessage *New( CSteamNetworkConnectionBase *pParent, uint32 cbSize, int64 nMsgNum, SteamNetworkingMicroseconds usecNow ); + static void Delete( SteamNetworkingMessage_t *piMsg ); /// Remove it from queues void Unlink(); @@ -104,9 +102,6 @@ public: void LinkToQueueTail( Links CSteamNetworkingMessage::*pMbrLinks, SteamNetworkingMessageQueue *pQueue ); void UnlinkFromQueue( Links CSteamNetworkingMessage::*pMbrLinks ); - -private: - virtual ~CSteamNetworkingMessage(); }; struct SteamNetworkingMessageQueue @@ -126,7 +121,7 @@ struct SteamNetworkingMessageQueue } /// Remove the first messages out of the queue (up to nMaxMessages). Returns the number returned - int RemoveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ); + int RemoveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ); /// Delete all queued messages void PurgeMessages(); @@ -152,7 +147,7 @@ public: /// This gets called on an accepted connection before it gets destroyed virtual void AboutToDestroyChildConnection( CSteamNetworkConnectionBase *pConn ); - int APIReceiveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ); + int APIReceiveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ); struct ChildConnectionKey_t { @@ -216,7 +211,7 @@ public: EResult APIFlushMessageOnConnection(); /// Receive the next message(s) - int APIReceiveMessages( ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ); + int APIReceiveMessages( SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ); /// Accept a connection. This will involve sending a message /// to the client, and calling ConnectionState_Connected on the connection diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_flat.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_flat.cpp index 9dcae68..fa23ff8 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_flat.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_flat.cpp @@ -66,12 +66,12 @@ STEAMNETWORKINGSOCKETS_INTERFACE EResult SteamNetworkingSockets_FlushMessagesOnC return SteamNetworkingSockets()->FlushMessagesOnConnection( hConn ); } -STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnConnection( HSteamNetConnection hConn, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { return SteamNetworkingSockets()->ReceiveMessagesOnConnection( hConn, ppOutMessages, nMaxMessages ); } -STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, ISteamNetworkingMessage **ppOutMessages, int nMaxMessages ) +STEAMNETWORKINGSOCKETS_INTERFACE int SteamNetworkingSockets_ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages ) { return SteamNetworkingSockets()->ReceiveMessagesOnListenSocket( hSocket, ppOutMessages, nMaxMessages ); } diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h index 9ef73d3..91adde4 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h @@ -300,7 +300,7 @@ inline bool BRateLimitSpew( SteamNetworkingMicroseconds usecNow ) extern ESteamNetworkingSocketsDebugOutputType g_eSteamDatagramDebugOutputDetailLevel; extern void ReallySpewType( ESteamNetworkingSocketsDebugOutputType eType, PRINTF_FORMAT_STRING const char *pMsg, ... ) FMTFUNCTION( 2, 3 ); -#define SpewType( eType, ... ) ( ( eType <= g_eSteamDatagramDebugOutputDetailLevel ) ? ReallySpewType( eType, __VA_ARGS__ ) : (void)0 ) +#define SpewType( eType, ... ) ( ( (eType) <= g_eSteamDatagramDebugOutputDetailLevel ) ? ReallySpewType( ESteamNetworkingSocketsDebugOutputType(eType), __VA_ARGS__ ) : (void)0 ) #define SpewMsg( ... ) SpewType( k_ESteamNetworkingSocketsDebugOutputType_Msg, __VA_ARGS__ ) #define SpewVerbose( ... ) SpewType( k_ESteamNetworkingSocketsDebugOutputType_Verbose, __VA_ARGS__ ) #define SpewDebug( ... ) SpewType( k_ESteamNetworkingSocketsDebugOutputType_Debug, __VA_ARGS__ ) @@ -309,7 +309,7 @@ extern void ReallySpewType( ESteamNetworkingSocketsDebugOutputType eType, PRINTF #define SpewError( ... ) SpewType( k_ESteamNetworkingSocketsDebugOutputType_Error, __VA_ARGS__ ) #define SpewBug( ... ) SpewType( k_ESteamNetworkingSocketsDebugOutputType_Bug, __VA_ARGS__ ) -#define SpewTypeRateLimited( usecNow, eType, ... ) ( ( eType <= g_eSteamDatagramDebugOutputDetailLevel && BRateLimitSpew( usecNow ) ) ? ReallySpewType( eType, __VA_ARGS__ ) : (void)0 ) +#define SpewTypeRateLimited( usecNow, eType, ... ) ( ( (eType) <= g_eSteamDatagramDebugOutputDetailLevel && BRateLimitSpew( usecNow ) ) ? ReallySpewType( (eType), __VA_ARGS__ ) : (void)0 ) #define SpewMsgRateLimited( usecNow, ... ) SpewTypeRateLimited( usecNow, k_ESteamNetworkingSocketsDebugOutputType_Msg, __VA_ARGS__ ) #define SpewWarningRateLimited( usecNow, ... ) SpewTypeRateLimited( usecNow, k_ESteamNetworkingSocketsDebugOutputType_Warning, __VA_ARGS__ ) #define SpewErrorRateLimited( usecNow, ... ) SpewTypeRateLimited( usecNow, k_ESteamNetworkingSocketsDebugOutputType_Error, __VA_ARGS__ ) diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_snp.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_snp.cpp index 1cef35c..cc7c967 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_snp.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_snp.cpp @@ -212,13 +212,13 @@ void CSteamNetworkConnectionBase::SNP_InitializeConnection( SteamNetworkingMicro SteamNetworkingMicroseconds usecPing = GetUsecPingWithFallback( this ); m_senderState.m_n_x = GetInitialRate( usecPing ); - if ( steamdatagram_snp_log_x ) - SpewMsg( "%12llu %s: INITIAL X=%d rtt=%dms tx_s=%d\n", - usecNow, - m_sName.c_str(), - m_senderState.m_n_x, - m_statsEndToEnd.m_ping.m_nSmoothedPing, - m_senderState.m_n_tx_s ); +// if ( steamdatagram_snp_log_x ) +// SpewMsg( "%12llu %s: INITIAL X=%d rtt=%dms tx_s=%d\n", +// usecNow, +// m_sName.c_str(), +// m_senderState.m_n_x, +// m_statsEndToEnd.m_ping.m_nSmoothedPing, +// m_senderState.m_n_tx_s ); m_receiverState.m_usec_tstamp_last_feedback = usecNow; @@ -313,10 +313,7 @@ EResult CSteamNetworkConnectionBase::SNP_SendMessage( SteamNetworkingMicrosecond // Add to pending list m_senderState.m_messagesQueued.push_back( pSendMessage ); - - if ( steamdatagram_snp_log_message ) - SpewMsg( "%12llu %s: SendMessage %s: MsgNum=%lld sz=%d\n", - usecNow, + SpewType( steamdatagram_snp_log_message, "%s: SendMessage %s: MsgNum=%lld sz=%d\n", m_sName.c_str(), ( eSendType & k_nSteamNetworkingSendFlags_Reliable ) ? "RELIABLE" : "UNRELIABLE", (long long)pSendMessage->m_nMsgNum, @@ -382,12 +379,7 @@ EResult CSteamNetworkConnectionBase::SNP_FlushMessage( SteamNetworkingMicrosecon // send so we want to do this first.) m_senderState.TokenBucket_Accumulate( usecNow ); - // Clear all nagle timers - if ( steamdatagram_snp_log_nagle ) - SpewMsg( "%12llu %s: NAGLE FlushMessasge\n", - usecNow, - m_sName.c_str() ); - + // Clear all Nagle timers m_senderState.ClearNagleTimers(); // Schedule wakeup at the appropriate time. (E.g. right now, if we're ready to send.) @@ -461,7 +453,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * const uint8 *pSegmentData = pDecode; \ pDecode += cbSegmentSize; - SpewDebug( "%s decode pkt %lld\n", + SpewType( steamdatagram_snp_log_packet, "%s decode pkt %lld\n", m_sName.c_str(), (long long)nPktNum ); const byte *pDecode = (const byte *)pChunk; @@ -662,7 +654,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * } continue; } - SpewDebug( " %s decode pkt %lld stop waiting: %lld (was %lld)", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld stop waiting: %lld (was %lld)", m_sName.c_str(), (long long)nPktNum, (long long)nMinPktNumToSendAcks, (long long)m_receiverState.m_nMinPktNumToSendAcks ); @@ -734,7 +726,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * } } - SpewDebug( " %s decode pkt %lld latest recv %lld\n", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld latest recv %lld\n", m_sName.c_str(), (long long)nPktNum, (long long)nLatestRecvSeqNum ); @@ -771,7 +763,13 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * { // Either they are lying or some weird timer stuff is happening. // Either way, discard it. - // FIXME Should we spew here? + + SpewType( steamdatagram_snp_log_ackrtt, "%s decode pkt %lld latest recv %lld delay %lluusec INVALID ping %lldusec\n", + m_sName.c_str(), + (long long)nPktNum, (long long)nLatestRecvSeqNum, + (unsigned long long)usecDelay, + (long long)usecElapsed + ); } else { @@ -779,6 +777,14 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * if ( msPing < 0 ) msPing = 0; m_statsEndToEnd.m_ping.ReceivedPing( msPing, usecNow ); + + // Spew + SpewType( steamdatagram_snp_log_ackrtt, "%s decode pkt %lld latest recv %lld delay %.1fms ping %.1fms\n", + m_sName.c_str(), + (long long)nPktNum, (long long)nLatestRecvSeqNum, + (float)(usecDelay * 1e-3 ), + (float)(usecElapsed * 1e-3 ) + ); } } } @@ -820,7 +826,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * nPktNumAckBegin = m_senderState.m_nMinPktWaitingOnAck; nPktNumNackBegin = nPktNumAckBegin; - SpewDebug( " %s decode pkt %lld ack last block ack begin %lld\n", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld ack last block ack begin %lld\n", m_sName.c_str(), (long long)nPktNum, (long long)nPktNumAckBegin ); } @@ -857,7 +863,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * if ( nPktNumNackBegin < 0 ) DECODE_ERROR( "Nack range underflow, end=%lld, num=%lld", (long long)nPktNumAckBegin, (long long)numAcks ); - SpewDebug( " %s decode pkt %lld nack [%lld,%lld) ack [%lld,%lld)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld nack [%lld,%lld) ack [%lld,%lld)\n", m_sName.c_str(), (long long)nPktNum, (long long)nPktNumNackBegin, (long long)( nPktNumNackBegin + numNacks ), @@ -936,7 +942,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * if ( !m_senderState.m_listReadyRetryReliableRange.empty() ) nPeerReliablePos = std::min( nPeerReliablePos, m_senderState.m_listReadyRetryReliableRange.begin()->first.m_nBegin ); - SpewDebug( " %s decode pkt %lld peer reliable pos = %lld\n", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld peer reliable pos = %lld\n", m_sName.c_str(), (long long)nPktNum, (long long)nPeerReliablePos ); } @@ -945,7 +951,7 @@ bool CSteamNetworkConnectionBase::SNP_RecvDataChunk( int64 nPktNum, const void * // Check if any of this was new info, then advance our stop_waiting value. if ( nLatestRecvSeqNum > m_senderState.m_nMinPktWaitingOnAck ) { - SpewDebug( " %s updating min_waiting_on_ack %lld -> %lld\n", + SpewType( steamdatagram_snp_log_packet, " %s updating min_waiting_on_ack %lld -> %lld\n", m_sName.c_str(), (long long)m_senderState.m_nMinPktWaitingOnAck, (long long)nLatestRecvSeqNum ); m_senderState.m_nMinPktWaitingOnAck = nLatestRecvSeqNum; @@ -992,7 +998,7 @@ void CSteamNetworkConnectionBase::SNP_SenderProcessPacketNack( int64 nPktNum, SN if ( inFlightRange == m_senderState.m_listInFlightReliableRange.end() ) continue; - SpewVerbose( "%s pkt %lld %s, queueing retry of reliable range [%lld,%lld)\n", + SpewType( steamdatagram_snp_log_packet, "%s pkt %lld %s, queueing retry of reliable range [%lld,%lld)\n", m_sName.c_str(), nPktNum, pszDebug, @@ -1248,7 +1254,7 @@ int CSteamNetworkConnectionBase::SNP_SendPacket( SteamNetworkingMicroseconds use uint8 *pPayloadEnd = payload + cbMaxPlaintextPayload; uint8 *pPayloadPtr = payload; - SpewDebug( "%s encode pkt %lld", + SpewType( steamdatagram_snp_log_packet, "%s encode pkt %lld", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber ); @@ -1277,11 +1283,11 @@ int CSteamNetworkConnectionBase::SNP_SendPacket( SteamNetworkingMicroseconds use pPayloadPtr = pAfterAck; if ( m_receiverState.m_usecWhenFlushAck == INT64_MAX ) { - SpewVerbose( "%s flushed %d acks (%d bytes)\n", m_sName.c_str(), ackHelper.m_nBlocks, cbFlushedAcks ); + SpewType( steamdatagram_snp_log_packet, "%s flushed %d acks (%d bytes)\n", m_sName.c_str(), ackHelper.m_nBlocks, cbFlushedAcks ); } else { - SpewVerbose( "%s flush didn't fit; rescheduling\n", m_sName.c_str() ); + SpewType( steamdatagram_snp_log_packet, "%s flush didn't fit; rescheduling\n", m_sName.c_str() ); // If we are artificially limited, then the connection // type specific code initiated this packet, and so @@ -1613,7 +1619,7 @@ int CSteamNetworkConnectionBase::SNP_SendPacket( SteamNetworkingMicroseconds use Assert( !HasOverlappingRange( range, m_senderState.m_listReadyRetryReliableRange ) ); // Spew - SpewDebug( " %s encode pkt %lld reliable msg %lld offset %d+%d=%d range [%lld,%lld)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld reliable msg %lld offset %d+%d=%d range [%lld,%lld)\n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)seg.m_pMsg->m_nMsgNum, seg.m_nOffset, seg.m_cbSize, seg.m_nOffset+seg.m_cbSize, (long long)range.m_nBegin, (long long)range.m_nEnd ); @@ -1640,7 +1646,7 @@ int CSteamNetworkConnectionBase::SNP_SendPacket( SteamNetworkingMicroseconds use Assert( seg.m_pMsg->m_pPrev == nullptr ); // We should either be at the head of the queue, or detached // Spew - SpewDebug( " %s encode pkt %lld unreliable msg %lld offset %d+%d=%d\n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld unreliable msg %lld offset %d+%d=%d\n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)seg.m_pMsg->m_nMsgNum, seg.m_nOffset, seg.m_cbSize, seg.m_nOffset+seg.m_cbSize ); @@ -1800,7 +1806,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeAckBlocks( const SNPAckSerializ *pLatestPktNum = uint16( nLastRecvPktNum ); *pTimeSinceLatestPktNum = SNPAckSerializerHelper::EncodeTimeSince( usecNow, m_statsEndToEnd.m_usecTimeLastRecvSeq ); - SpewDebug( " %s encode pkt %lld last recv %lld (no loss)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld last recv %lld (no loss)\n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)nLastRecvPktNum ); @@ -1825,7 +1831,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeAckBlocks( const SNPAckSerializ *pLatestPktNum = uint16( nLastRecvPktNum ); *pTimeSinceLatestPktNum = SNPAckSerializerHelper::EncodeTimeSince( usecNow, itOldestGap->second.m_usecWhenReceivedPktBefore ); - SpewDebug( " %s encode pkt %lld last recv %lld (no blocks, actual last recv=%lld)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld last recv %lld (no blocks, actual last recv=%lld)\n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)nLastRecvPktNum, (long long)m_statsEndToEnd.m_nLastRecvSequenceNumber ); @@ -1867,7 +1873,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeAckBlocks( const SNPAckSerializ int64 nAckEnd = ( m_statsEndToEnd.m_nLastRecvSequenceNumber & ~(int64)(~(uint32)0) ) | pBlock->m_nLatestPktNum; ++nAckEnd; - SpewDebug( " %s encode pkt %lld last recv %lld (%d blocks, actual last recv=%lld)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld last recv %lld (%d blocks, actual last recv=%lld)\n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)(nAckEnd-1), nBlocks, (long long)m_statsEndToEnd.m_nLastRecvSequenceNumber ); @@ -1926,7 +1932,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeAckBlocks( const SNPAckSerializ // Debug int64 nAckBegin = nAckEnd - pBlock->m_nAck; int64 nNackBegin = nAckBegin - pBlock->m_nNack; - SpewDebug( " %s encode pkt %lld nack [%lld,%lld) ack [%lld,%lld) \n", + SpewType( steamdatagram_snp_log_packet+1, " %s encode pkt %lld nack [%lld,%lld) ack [%lld,%lld) \n", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)nNackBegin, (long long)nAckBegin, @@ -1961,7 +1967,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeStopWaitingFrame( uint8 *pOut, // Calculate offset from the current sequence number int64 nOffset = m_statsEndToEnd.m_nNextSendSequenceNumber - m_senderState.m_nMinPktWaitingOnAck; AssertMsg2( nOffset > 0, "Told peer to stop acking up to %lld, but latest packet we have sent is %lld", (long long)m_senderState.m_nMinPktWaitingOnAck, (long long)m_statsEndToEnd.m_nNextSendSequenceNumber ); - SpewDebug( " %s encode pkt %lld stop_waiting offset %lld = %lld", + SpewType( steamdatagram_snp_log_packet, " %s encode pkt %lld stop_waiting offset %lld = %lld", m_sName.c_str(), (long long)m_statsEndToEnd.m_nNextSendSequenceNumber, (long long)nOffset, (long long)m_senderState.m_nMinPktWaitingOnAck ); @@ -2015,7 +2021,7 @@ uint8 *CSteamNetworkConnectionBase::SNP_SerializeStopWaitingFrame( uint8 *pOut, void CSteamNetworkConnectionBase::SNP_ReceiveUnreliableSegment( int64 nMsgNum, int nOffset, const void *pSegmentData, int cbSegmentSize, bool bLastSegmentInMessage, SteamNetworkingMicroseconds usecNow ) { - SpewDebug( "%s RX msg %lld offset %d+%d=%d %02x ... %02x\n", m_sName.c_str(), nMsgNum, nOffset, cbSegmentSize, nOffset+cbSegmentSize, ((byte*)pSegmentData)[0], ((byte*)pSegmentData)[cbSegmentSize-1] ); + SpewType( steamdatagram_snp_log_packet+1, "%s RX msg %lld offset %d+%d=%d %02x ... %02x\n", m_sName.c_str(), nMsgNum, nOffset, cbSegmentSize, nOffset+cbSegmentSize, ((byte*)pSegmentData)[0], ((byte*)pSegmentData)[cbSegmentSize-1] ); // Check for a common special case: non-fragmented message. if ( nOffset == 0 && bLastSegmentInMessage ) @@ -2146,7 +2152,7 @@ bool CSteamNetworkConnectionBase::SNP_ReceiveReliableSegment( int64 nPktNum, int int64 nSegEnd = nSegBegin + cbSegmentSize; // Spew - SpewDebug( " %s decode pkt %lld reliable range [%lld,%lld)\n", + SpewType( steamdatagram_snp_log_packet, " %s decode pkt %lld reliable range [%lld,%lld)\n", m_sName.c_str(), (long long)nPktNum, (long long)nSegBegin, (long long)nSegEnd ); @@ -2388,7 +2394,7 @@ bool CSteamNetworkConnectionBase::SNP_ReceiveReliableSegment( int64 nPktNum, int uint8 *pReliableEnd = pReliableDecode + nNumReliableBytes; // Spew - SpewDebug( " %s decode pkt %lld valid reliable bytes = %d [%lld,%lld)\n", + SpewType( steamdatagram_snp_log_packet+1, " %s decode pkt %lld valid reliable bytes = %d [%lld,%lld)\n", m_sName.c_str(), (long long)nPktNum, nNumReliableBytes, (long long)m_receiverState.m_nReliableStreamPos, @@ -2526,7 +2532,7 @@ bool CSteamNetworkConnectionBase::SNP_RecordReceivedPktNum( int64 nPktNum, Steam gap.m_usecWhenReceivedPktBefore = m_statsEndToEnd.m_usecTimeLastRecvSeq; gap.m_nEnd = nPktNum; - SpewVerbose( " %s drop %d pkts [%lld-%lld)", + SpewType( steamdatagram_snp_log_packetgaps, "%s drop %d pkts [%lld-%lld)", m_sName.c_str(), (int)( nPktNum - nBegin ), (long long)nBegin, (long long)nPktNum ); @@ -2560,7 +2566,7 @@ bool CSteamNetworkConnectionBase::SNP_RecordReceivedPktNum( int64 nPktNum, Steam // Gap is totally filed m_receiverState.m_mapPacketGaps.erase( itGap ); - SpewVerbose( " %s decode pkt %lld, single pkt gap filled", m_sName.c_str(), (long long)nPktNum ); + SpewType( steamdatagram_snp_log_packetgaps, "%s decode pkt %lld, single pkt gap filled", m_sName.c_str(), (long long)nPktNum ); } else { @@ -2568,7 +2574,7 @@ bool CSteamNetworkConnectionBase::SNP_RecordReceivedPktNum( int64 nPktNum, Steam --itGap->second.m_nEnd; Assert( itGap->first < itGap->second.m_nEnd ); - SpewVerbose( " %s decode pkt %lld, last packet in gap, reduced to [%lld,%lld)", m_sName.c_str(), + SpewType( steamdatagram_snp_log_packetgaps, "%s decode pkt %lld, last packet in gap, reduced to [%lld,%lld)", m_sName.c_str(), (long long)nPktNum, (long long)itGap->first, (long long)itGap->second.m_nEnd ); } } @@ -2582,7 +2588,7 @@ bool CSteamNetworkConnectionBase::SNP_RecordReceivedPktNum( int64 nPktNum, Steam Assert( itGap->first < itGap->second.m_nEnd ); itGap->second.m_usecWhenReceivedPktBefore = usecNow; - SpewVerbose( " %s decode pkt %lld, first packet in gap, reduced to [%lld,%lld)", m_sName.c_str(), + SpewType( steamdatagram_snp_log_packetgaps, "%s decode pkt %lld, first packet in gap, reduced to [%lld,%lld)", m_sName.c_str(), (long long)nPktNum, (long long)itGap->first, (long long)itGap->second.m_nEnd ); } else @@ -2601,7 +2607,7 @@ bool CSteamNetworkConnectionBase::SNP_RecordReceivedPktNum( int64 nPktNum, Steam int64 nUpperBegin = nPktNum+1; - SpewVerbose( " %s decode pkt %lld, gap split [%lld,%lld) and [%lld,%lld)", m_sName.c_str(), + SpewType( steamdatagram_snp_log_packetgaps, "%s decode pkt %lld, gap split [%lld,%lld) and [%lld,%lld)", m_sName.c_str(), (long long)nPktNum, (long long)itGap->first, (long long)itGap->second.m_nEnd, nUpperBegin, nEnd ); // Insert a new gap to account for the upper end diff --git a/tests/connection_test.cpp b/tests/connection_test.cpp index 8037abf..6f39740 100644 --- a/tests/connection_test.cpp +++ b/tests/connection_test.cpp @@ -387,8 +387,8 @@ static void TestNetworkConditions( int rate, int loss, int lag, int reorderPct, Printf( "Act like game. . : %d\n", (int)bActLikeGame ); Printf( "---------------------------------------------------\n" ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_MinRate, rate ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_MaxRate, rate ); + pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_MinRate, rate ); + pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_MaxRate, rate ); pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_FakePacketLoss_Send, loss ); pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_FakePacketLoss_Recv, 0 ); @@ -497,15 +497,6 @@ static void RunSteamDatagramConnectionTest() { ISteamNetworkingSockets *pSteamSocketNetworking = SteamNetworkingSockets(); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_RTT, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Packet, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Segments, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Feedback, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Reliable, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Message, 0 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_Loss, 1 ); - pSteamSocketNetworking->SetConfigurationValue( k_ESteamNetworkingConfigurationValue_SNP_Log_X, 0 ); - // Command line options: // -connect:ip -- don't create a server, just try to connect to the given ip