Skip to content

Commit 5cec036

Browse files
committed
Pipe connection send size limits
Previous change here (7d59e79) was dumb. If the app lowers the recv limit significantly on one side of the pipe only (e.g. server doesn't expect large messages from the client, but client expects large messages from server) the previous change would apply the wrong limit on the sending side. P4:10624249 (cherry picked from commit 9ca39d8)
1 parent 8e9c05e commit 5cec036

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,9 @@ CSteamNetworkConnectionPipe *CSteamNetworkConnectionPipe::CreateLoopbackConnecti
39853985
// All pipe connections share the same lock!
39863986
static ConnectionLock s_sharedPipeLock;
39873987

3988+
// We allow "infinity" data to be buffered in the pipe or sent in a single message
3989+
constexpr int k_cbPipeHugeSize = 0x10000000;
3990+
39883991
CSteamNetworkConnectionPipe::CSteamNetworkConnectionPipe( CSteamNetworkingSockets *pSteamNetworkingSocketsInterface, const SteamNetworkingIdentity &identity, ConnectionScopeLock &scopeLock, bool bUseFastPath )
39893992
: CSteamNetworkConnectionBase( pSteamNetworkingSocketsInterface, scopeLock )
39903993
, CConnectionTransport( *static_cast<CSteamNetworkConnectionBase*>( this ) ) // connection and transport object are the same
@@ -4010,15 +4013,15 @@ CSteamNetworkConnectionPipe::CSteamNetworkConnectionPipe( CSteamNetworkingSocket
40104013
m_connectionConfig.Unencrypted.Set( 3 );
40114014

40124015
// Slam in a really large SNP rate so that we are never rate limited
4013-
int nRate = 0x10000000;
4016+
int nRate = k_cbPipeHugeSize;
40144017
m_connectionConfig.SendRateMin.Set( nRate );
40154018
m_connectionConfig.SendRateMax.Set( nRate );
40164019

40174020
// Don't limit the recv buffer. (Send buffer doesn't
40184021
// matter since we immediately transfer.)
4019-
m_connectionConfig.RecvBufferSize.Set( 0x10000000 );
4020-
m_connectionConfig.RecvBufferMessages.Set( 0x10000000 );
4021-
m_connectionConfig.RecvMaxMessageSize.Set( 0x10000000 );
4022+
m_connectionConfig.RecvBufferSize.Set( k_cbPipeHugeSize );
4023+
m_connectionConfig.RecvBufferMessages.Set( k_cbPipeHugeSize );
4024+
m_connectionConfig.RecvMaxMessageSize.Set( k_cbPipeHugeSize );
40224025

40234026
// Diagnostics usually not useful on these types of connections.
40244027
// (App can enable it or clear this override if it wants to.)
@@ -4055,6 +4058,23 @@ EUnsignedCert CSteamNetworkConnectionPipe::AllowLocalUnsignedCert()
40554058
return k_EUnsignedCert_Allow;
40564059
}
40574060

4061+
int CSteamNetworkConnectionPipe::GetMaxMessageSizeSend() const
4062+
{
4063+
// If app lowers the max message size on the other side, let's
4064+
// go ahead and apply their limit here. This means the pipe
4065+
// behaves a little bit different from the network-based socket
4066+
// pair, which doesn't have this "prescience", but that's OK.
4067+
if ( m_pPartner )
4068+
return m_pPartner->GetEffectiveRecvMaxMessageSize();
4069+
4070+
// Just return a huge number, there is little value
4071+
// in limiting stuff going through the in-memory pipe,
4072+
// since we are just swapping pointers around. If you really
4073+
// want to test realistic network conditions, use the network
4074+
// mode.
4075+
return k_cbPipeHugeSize;
4076+
}
4077+
40584078
int64 CSteamNetworkConnectionPipe::_APISendMessageToConnection( CSteamNetworkingMessage *pMsg, SteamNetworkingMicroseconds usecNow, bool *pbThinkImmediately )
40594079
{
40604080
m_pLock->AssertHeldByCurrentThread();

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ class CSteamNetworkConnectionPipe final : public CSteamNetworkConnectionBase, pu
10781078
CSteamNetworkConnectionPipe *m_pPartner;
10791079

10801080
// CSteamNetworkConnectionBase overrides
1081-
virtual int GetMaxMessageSizeSend() const override { return m_connectionConfig.RecvMaxMessageSize.Get(); } //!KLUDGE! Techcnially, we should use the value from our partner. Really this convar should just stay a huge value and people should not change it.
1081+
virtual int GetMaxMessageSizeSend() const override;
10821082
virtual int64 _APISendMessageToConnection( CSteamNetworkingMessage *pMsg, SteamNetworkingMicroseconds usecNow, bool *pbThinkImmediately ) override;
10831083
virtual EResult AcceptConnection( SteamNetworkingMicroseconds usecNow ) override;
10841084
virtual void InitConnectionCrypto( SteamNetworkingMicroseconds usecNow ) override;

0 commit comments

Comments
 (0)