MCPcopy Create free account
hub / github.com/cocos/cocos-engine / networkThread

Method networkThread

native/cocos/network/HttpClient-java.cpp:716–763  ·  view source on GitHub ↗

Worker thread

Source from the content-addressed store, hash-verified

714
715// Worker thread
716void HttpClient::networkThread() {
717 increaseThreadCount();
718
719 while (true) {
720 HttpRequest *request;
721
722 // step 1: send http request if the requestQueue isn't empty
723 {
724 std::lock_guard<std::mutex> lock(_requestQueueMutex);
725 while (_requestQueue.empty()) {
726 _sleepCondition.wait(_requestQueueMutex);
727 }
728 request = _requestQueue.at(0);
729 _requestQueue.erase(0);
730 }
731
732 if (request == _requestSentinel) {
733 break;
734 }
735
736 // Create a HttpResponse object, the default setting is http access failed
737 auto *response = ccnew HttpResponse(request);
738 response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew.
739 processResponse(response, _responseMessage);
740
741 // add response packet into queue
742 _responseQueueMutex.lock();
743 _responseQueue.pushBack(response);
744 _responseQueueMutex.unlock();
745
746 _schedulerMutex.lock();
747 if (auto sche = _scheduler.lock()) {
748 sche->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this)); // NOLINT
749 }
750 _schedulerMutex.unlock();
751 }
752
753 // cleanup: if worker thread received quit signal, clean up un-completed request queue
754 _requestQueueMutex.lock();
755 _requestQueue.clear();
756 _requestQueueMutex.unlock();
757
758 _responseQueueMutex.lock();
759 _responseQueue.clear();
760 _responseQueueMutex.unlock();
761
762 decreaseThreadCountAndMayDeleteThis();
763}
764
765// Worker thread
766void HttpClient::networkThreadAlone(HttpRequest *request, HttpResponse *response) {

Callers

nothing calls this directly

Calls 8

HttpResponseClass · 0.85
lockMethod · 0.80
clearMethod · 0.65
emptyMethod · 0.45
waitMethod · 0.45
eraseMethod · 0.45
addRefMethod · 0.45

Tested by

no test coverage detected