Skip to content

Commit

Permalink
BACKEND-200: Allow retransmit packets on ratelimit (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
chernikovdmitry authored Apr 29, 2024
1 parent e0d3338 commit b7e8149
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/steam/isteamnetworkingsockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ class ISteamNetworkingSockets
/// -k_EResultInvalidState if the connection was in an invalid state.
/// See ISteamNetworkingSockets::SendMessageToConnection for possible
/// failure codes.
/// NOTE: @LowKick
/// Fixed, don't skip any messages.
/// if it get k_EResultLimitExceeded for some message it will stop sending to this overloaded
/// connection and mark all subsequent messages to this connection as k_EResultLimitExceeded
/// allowing caller to retransmit it later
virtual void SendMessages( int nMessages, SteamNetworkingMessage_t *const *pMessages, int64 *pOutMessageNumberOrResult ) = 0;

/// Flush any messages waiting on the Nagle timer and send them
Expand Down
22 changes: 22 additions & 0 deletions src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,28 @@ void CSteamNetworkingSockets::SendMessages( int nMessages, SteamNetworkingMessag
// Return result for this message if they asked for it
if ( pOutMessageNumberOrResult )
pOutMessageNumberOrResult[pSort->m_idx] = result;

// Have too many pending bytes on this connection
if ( result == -k_EResultLimitExceeded )
{
// If caller wants to know - mark all next messages as k_EResultLimitExceeded so caller could
// attempt to resend them later
if ( pOutMessageNumberOrResult ) {
++pSort; // Already done
for ( ; pSort < pSortEnd ; ++pSort )
{
if ( pSort->m_hConn != hConn )
break;

pOutMessageNumberOrResult[pSort->m_idx] = -k_EResultLimitExceeded;
}
}
else
{
// Caller doesn't care - just skip this one
pMsg->Release();
}
}
}

// Flush out last connection, if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ int64 CSteamNetworkConnectionBase::SNP_SendMessage( CSteamNetworkingMessage *pSe
if ( m_senderState.PendingBytesTotal() + cbData > m_connectionConfig.m_SendBufferSize.Get() )
{
SpewWarningRateLimited( usecNow, "Connection already has %u bytes pending, cannot queue any more messages\n", m_senderState.PendingBytesTotal() );
pSendMessage->Release();
// NOTE: @LowKick: we should keep the message around, but not send it, so caller can retry later
// pSendMessage->Release();
return -k_EResultLimitExceeded;
}

Expand Down
1 change: 1 addition & 0 deletions tests/test_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ void Test_netloopback_throughput()
SteamNetworkingSockets()->SendMessages( 1, &pSendMsg, &nMsgNumberOrResult );
if ( nMsgNumberOrResult == -k_EResultLimitExceeded )
{
pSendMsg->Release();
TEST_Printf( "SendMessage returned limit exceeded trying to queue %d + %d = %d\n", serverStatus.m_cbPendingReliable, cbSendMsg, serverStatus.m_cbPendingReliable + cbSendMsg );
break;
}
Expand Down

0 comments on commit b7e8149

Please sign in to comment.