GameNetworkingSockets icon indicating copy to clipboard operation
GameNetworkingSockets copied to clipboard

Inaccuracy in the message sending function

Open angelskieglazki opened this issue 1 year ago • 0 comments

Hello, if we got error in this line: result = pConn->APISendMessageToConnection( pMsg, usecNow, &bThinkImmediately ); for example APISendMessageToConnection return k_EResultLimitExceeded we marked message as error in this line: pOutMessageNumberOrResult[pSort->m_idx] = result; and we continue sending messages and some messages will be skipped. Perhaps we should stop sending, return an error, wait in the user code and only then continue sending the rest of the messages...

void CSteamNetworkingSockets::SendMessages( int nMessages, SteamNetworkingMessage_t *const *pMessages, int64 *pOutMessageNumberOrResult )
{

	// Get list of messages, grouped by connection.
	// But within the connection, it is important that we
	// keep them in the same order!
	
	....
	
	// OK, we are ready to begin

	// SteamNetworkingGlobalLock scopeLock( "SendMessages" ); // NO, not necessary!
	SteamNetworkingMicroseconds usecNow = SteamNetworkingSockets_GetLocalTimestamp();

	CSteamNetworkConnectionBase *pConn = nullptr;
	HSteamNetConnection hConn = k_HSteamNetConnection_Invalid;
	ConnectionScopeLock connectionLock;
	bool bConnectionThinkImmediately = false;
	for ( SortMsg_t *pSort = pSortMessages ; pSort < pSortEnd ; ++pSort )
	{

		// Switched to a different connection?
		if ( hConn != pSort->m_hConn )
		{

			// Flush out previous connection, if any
			if ( pConn )
			{
				if ( bConnectionThinkImmediately )
					pConn->CheckConnectionStateOrScheduleWakeUp( usecNow );
				connectionLock.Unlock();
				bConnectionThinkImmediately = false;
			}

			// Locate the connection
			hConn = pSort->m_hConn;
			pConn = GetConnectionByHandleForAPI( hConn, connectionLock, "SendMessages" );
		}

		CSteamNetworkingMessage *pMsg = static_cast<CSteamNetworkingMessage*>( pMessages[pSort->m_idx] );

		// Current connection is valid?
		int64 result;
		if ( pConn )
		{

			// Attempt to send
			bool bThinkImmediately = false;
			result = pConn->APISendMessageToConnection( pMsg, usecNow, &bThinkImmediately );
			if ( bThinkImmediately )
				bConnectionThinkImmediately = true;
		}
		else
		{
			pMsg->Release();
			result = -k_EResultInvalidParam;
		}

		// Return result for this message if they asked for it
		if ( pOutMessageNumberOrResult )
			pOutMessageNumberOrResult[pSort->m_idx] = result;
		**if (result == -k_EResultLimitExceeded) { // THIS MY CODE
			break;                             // THIS MY CODE
		}**                                           // THIS MY CODE
	}

	// Flush out last connection, if any
	if ( bConnectionThinkImmediately )
		pConn->CheckConnectionStateOrScheduleWakeUp( usecNow );
}

angelskieglazki avatar Apr 28 '24 08:04 angelskieglazki