Skip to content

Allow retransmit packets on ratelimit #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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