Skip to content

Commit 1812563

Browse files
committed
Tweak the meaning of the ECN convar.
Now, -1 means "auto" and 0 means "don't set anything". Add g_nSendECNAuto Add ResolveECNSendGlobal P4:9166210,9168032 (cherry picked from commit fcc19e1)
1 parent fa6fae5 commit 1812563

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

include/steam/steamnetworkingtypes.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,12 +1693,20 @@ enum ESteamNetworkingConfigValue
16931693
k_ESteamNetworkingConfig_LogLevel_P2PRendezvous = 17, // [connection int32] P2P rendezvous messages
16941694
k_ESteamNetworkingConfig_LogLevel_SDRRelayPings = 18, // [global int32] Ping relays
16951695

1696-
// Experimental. Set the ECN header field on all outbound UDP packets
1697-
// -1 = the default, and means "don't set anything".
1698-
// 0..3 = set that value. (Even though 0 is the default UDP ECN value, a 0 here means "explicitly set a 0".)
1696+
//
1697+
// Experimental values. These are subject to be deleted or change at any time,
1698+
// do not set them, except as a result of an explicit and advanced user opt-in,
1699+
// and do not write anything that depends on them existing, or have any particular
1700+
// behaviour.
1701+
//
1702+
// [global int32] ECN value to send in every packet.
1703+
// -1 = The default, and means "auto". We will set ECN=1, if it appears that the local internet connection appears to understand it and there may be some benefit.
1704+
// 0..2 = use that value.
16991705
k_ESteamNetworkingConfig_ECN = 999,
17001706

1701-
// Deleted, do not use
1707+
//
1708+
// Deleted, do not use
1709+
//
17021710
k_ESteamNetworkingConfig_DELETED_EnumerateDevVars = 35,
17031711

17041712
k_ESteamNetworkingConfigValue__Force32Bit = 0x7fffffff

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ static void FlushSystemSpew();
9696

9797
int g_cbUDPSocketBufferSize = 256*1024;
9898

99+
#if PlatformCanSendECN()
100+
int g_nSendECNAuto = -1;
101+
#endif
102+
99103
/// Global lock for all local data structures
100104
static Lock<RecursiveTimedMutexImpl> s_mutexGlobalLock( "global", 0, LockDebugInfo::k_nOrder_Global );
101105

@@ -1098,8 +1102,8 @@ class CRawUDPSocketImpl final : public IRawUDPSocket
10981102

10991103
// Check if we need to send ECN
11001104
if ( ecn < 0 )
1101-
ecn = GlobalConfig::ECN.Get();
1102-
if ( ecn >= 0 )
1105+
ecn = ResolveECNSendGlobal();
1106+
if ( ecn > 0 ) // We assume that if we don't explicit specify an ECN, that zero will be used
11031107
{
11041108
wsaMsg.Control.len = sizeof(control);
11051109
wsaMsg.Control.buf = control;

src/steamnetworkingsockets/steamnetworkingsockets_internal.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,19 @@ inline uint8 IPv4_TOS_make( uint8 dscp, uint8 ecn )
11021102
{
11031103
Assert( dscp < 0x40 );
11041104
Assert( ecn < 0x4 );
1105-
return ( (dscp<<2) | ecn );
1105+
return ( (dscp<<2U) | ecn );
1106+
}
1107+
1108+
// Extract ECN from TOS
1109+
inline uint8 IPv4_TOS_ECN( uint8 tos )
1110+
{
1111+
return tos & IPv4_TOS_ECN_bits;
1112+
}
1113+
1114+
// Extract DSCP from TOS
1115+
inline uint8 IPv4_TOS_DSCP( uint8 tos )
1116+
{
1117+
return tos>>2U;
11061118
}
11071119

11081120
// FIXME POSIX supports this! Need to check console support and implement all supported platforms,
@@ -1113,6 +1125,23 @@ inline uint8 IPv4_TOS_make( uint8 dscp, uint8 ecn )
11131125
#define PlatformCanSendECN() false
11141126
#endif
11151127

1128+
#if PlatformCanSendECN()
1129+
// ECN value to send, if "auto" option is specified.
1130+
// -1 means that we have not completed detection, and so 0 will be used
1131+
extern int g_nSendECNAuto;
1132+
1133+
// Get the ECN value we will actually use for sending
1134+
inline uint8 ResolveECNSendGlobal()
1135+
{
1136+
int ecn = GlobalConfig::ECN.Get();
1137+
if ( ecn < 0 )
1138+
ecn = std::max( 0, g_nSendECNAuto );
1139+
return (uint8)ecn;
1140+
}
1141+
#else
1142+
inline uint8 ResolveECNSendGlobal() { return 0; }
1143+
#endif
1144+
11161145
} // namespace SteamNetworkingSocketsLib
11171146

11181147
#include <tier0/memdbgon.h>

0 commit comments

Comments
 (0)