MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / threadWorkerLoop

Method threadWorkerLoop

src/core/net/NetworkManagerImpl.cpp:553–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

551}
552
553Future<> NetworkManagerImpl::threadWorkerLoop() {
554 using enum qn::ConnectionState;
555
556 // might happen when exiting, just wait and return (to not busy loop)
557 if (!m_centralConn) {
558 co_await arc::sleep(Duration::fromMillis(100));
559 co_return;
560 }
561
562 // Worker task has the following duties:
563 // - Watch the connection state
564 // - When connected, periodically ping game servers and decide to resend own data
565 auto connState = m_centralConn->state();
566 auto prevState = m_workerState.prevCentralState;
567 m_workerState.prevCentralState = connState;
568
569 // reset connection info on disconnect, and create it when needed
570 if (connState == Disconnected) {
571 m_connInfo.lock()->reset();
572 } else if (connState == Connected && connState != prevState) {
573 auto info = m_connInfo.lock();
574 if (!*info) info->emplace();
575
576 auto& i = **info;
577 i.m_centralUrl = m_connectingCentralUrl;
578 i.m_icons = m_connectingIcons;
579 }
580
581 switch (connState) {
582 case Connected: {
583 // if we weren't connected before, do some initial setup
584 if (prevState != qn::ConnectionState::Connected) {
585 m_workerState.nextGSPing = Instant::now();
586 m_workerState.pingResultRx.drain();
587 globed::setValue<bool>("core.was-connected", true);
588
589 co_await this->threadSetupLogger(true);
590 }
591
592 {
593 auto info = this->connInfo();
594
595 // if we aren't authenticated yet, try to do auth
596 if (!info->m_established && !info->m_authenticating) {
597 info.unlock();
598 co_await this->threadTryAuth();
599 co_return;
600 }
601
602 // check if icons or friend list need to be resent
603 this->threadMaybeResendOwnData(info);
604
605 // reset the timer to ping game servers if the server list was updated
606 if (info->m_gameServersUpdated) {
607 log::debug("Pinging servers again soon");
608 info->m_gameServersUpdated = false;
609 m_workerState.nextGSPing = Instant::now();
610 }

Callers 1

asyncInitMethod · 0.95

Calls 11

threadSetupLoggerMethod · 0.95
connInfoMethod · 0.95
threadTryAuthMethod · 0.95
threadPingGameServersMethod · 0.95
threadFlushLoggerMethod · 0.95
showDisconnectCauseMethod · 0.95
stateMethod · 0.80
updateLatencyMethod · 0.80
schedulePingMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected