CCHttpClient priority?


#1

(Apologies if something like this has been addressed in 3.0)

CCHttpClient works fine for most things, however, sometimes when there are a lot of requests, like when the user first opens the app and levels need to update, it would be nice to be able to prioritize some requests over others.

I’ve implemented the following in CCHttpRequest. Does anyone see any issue with this? Is this something that could be useful for everyone?

void CCHttpClient::send(CCHttpRequest* request)
{
    this->send(request, false);
}
void CCHttpClient::send(CCHttpRequest* request, bool prioritize)
{    
    if (false == lazyInitThreadSemphore()) 
    {
        return;
    }
    
    if (!request)
    {
        return;
    }
        
    ++s_asyncRequestCount;
    
    request->retain();
        
    pthread_mutex_lock(&s_requestQueueMutex);
    if (prioritize)
        s_requestQueue->insertObject(request, 0);
    else
        s_requestQueue->addObject(request);
    pthread_mutex_unlock(&s_requestQueueMutex);
    
    // Notify thread start to work
    pthread_cond_signal(&s_SleepCondition);
}