MCPcopy Create free account
hub / github.com/ddnet/ddnet / RunLoop

Method RunLoop

src/engine/shared/http.cpp:612–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612void CHttp::RunLoop()
613{
614 std::unique_lock Lock(m_Lock);
615 if(curl_global_init(CURL_GLOBAL_DEFAULT))
616 {
617 log_error("http", "curl_global_init failed");
618 m_State = CHttp::ERROR;
619 m_Cv.notify_all();
620 return;
621 }
622
623 m_pMultiH = curl_multi_init();
624 if(!m_pMultiH)
625 {
626 log_error("http", "curl_multi_init failed");
627 m_State = CHttp::ERROR;
628 m_Cv.notify_all();
629 return;
630 }
631
632 // print curl version
633 {
634 curl_version_info_data *pVersion = curl_version_info(CURLVERSION_NOW);
635 log_info("http", "libcurl version %s (compiled = " LIBCURL_VERSION ")", pVersion->version);
636 }
637
638 m_State = CHttp::RUNNING;
639 m_Cv.notify_all();
640 Lock.unlock();
641
642 while(m_State == CHttp::RUNNING)
643 {
644 static int s_NextTimeout = std::numeric_limits<int>::max();
645 int Events = 0;
646 const CURLMcode PollCode = curl_multi_poll(m_pMultiH, nullptr, 0, s_NextTimeout, &Events);
647
648 // We may have been woken up for a shutdown
649 if(m_Shutdown)
650 {
651 if(m_RunningRequests.empty() && m_PendingRequests.empty())
652 break;
653
654 auto Now = std::chrono::steady_clock::now();
655 if(!m_ShutdownTime.has_value())
656 {
657 m_ShutdownTime = Now + m_ShutdownDelay;
658 s_NextTimeout = m_ShutdownDelay.count();
659 }
660 else if(m_ShutdownTime < Now)
661 {
662 break;
663 }
664 }
665
666 if(PollCode != CURLM_OK)
667 {
668 Lock.lock();
669 log_error("http", "curl_multi_poll failed: %s", curl_multi_strerror(PollCode));

Callers 1

ThreadMainMethod · 0.45

Calls 7

endMethod · 0.80
OnCompletionInternalMethod · 0.80
ShouldSkipRequestMethod · 0.80
ConfigureHandleMethod · 0.80
beginMethod · 0.80
str_copyFunction · 0.50
OnCompletionMethod · 0.45

Tested by

no test coverage detected