//----------------------------------------------------------------------------- /// ShouldResponseBeSent /// /// indicates whether a response should be sent to the specified request based /// on whether or not the request is streaming and is rate limited. If the /// request is rate limited, but a response can be sent, the "last sent time" /// will be updated if bUpdateTime is true /// /// \param requestID id of the request that may or may not be rate limited /// \param bUpdateTime indicates whether or not the "last sent time" will be /// updated if the response is rate limited, but allowed to be sent /// /// \return true if a response should NOT be sent; false otherwise //----------------------------------------------------------------------------- bool ShouldResponseBeSent(CommunicationID requestID, bool bUpdateTime) { // protect the maps from being changed by other threads using the mutex ScopeLock lock(s_mutex); ResponseMap::iterator iterResponse = g_streamingResponseMap.find(requestID); if (iterResponse == g_streamingResponseMap.end()) { // don't limit the send because we don't even know it is streaming return false; } Response* pResponse = iterResponse->second; PsAssert(pResponse != NULL); // if this is a streaming request, only send if rate allows if (pResponse->m_bStreamingEnabled == true) { if (pResponse->m_dwMaxStreamsPerSecond == COMM_MAX_STREAM_RATE || pResponse->m_dwMaxStreamsPerSecond == 0) { return false; } DWORD dwCurrTime = g_streamTimer.GetAbsolute(); if (dwCurrTime - pResponse->m_dwLastSent >= 1000 / pResponse->m_dwMaxStreamsPerSecond) { if (bUpdateTime) { pResponse->m_dwLastSent = dwCurrTime; } return false; } else { return true; } } return false; }