| 782 | } |
| 783 | |
| 784 | void ServerDiscovery::OnClientThread(void* param) |
| 785 | { |
| 786 | ServerDiscovery* _this = static_cast<ServerDiscovery*>(param); |
| 787 | IServerObserver* observer = _this->_observer; |
| 788 | |
| 789 | NetworkManagerBase::InitializeBackend(); |
| 790 | |
| 791 | ENetSocket socket = TryCreateLocalSocket("ff02::1", _this->_localMulticastAddress); |
| 792 | _this->_socket = socket; |
| 793 | |
| 794 | while (_this->_observer != nullptr) { |
| 795 | if (_this->_lastLocalRequestTime.secondsSince() > 10) { |
| 796 | _this->_lastLocalRequestTime = TimeStamp::now(); |
| 797 | _this->SendLocalDiscoveryRequest(socket, _this->_localMulticastAddress); |
| 798 | } |
| 799 | |
| 800 | if (_this->_lastOnlineRequestTime.secondsSince() > 60) { |
| 801 | _this->_lastOnlineRequestTime = TimeStamp::now(); |
| 802 | _this->DownloadPublicServerList(observer); |
| 803 | } |
| 804 | |
| 805 | ServerDescription discoveredServer; |
| 806 | if (_this->ProcessLocalDiscoveryResponses(socket, discoveredServer, 0)) { |
| 807 | observer->OnServerFound(std::move(discoveredServer)); |
| 808 | } else { |
| 809 | // No responses, sleep for a while |
| 810 | Thread::Sleep(500); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | if (_this->_socket != ENET_SOCKET_NULL) { |
| 815 | enet_socket_destroy(_this->_socket); |
| 816 | _this->_socket = ENET_SOCKET_NULL; |
| 817 | } |
| 818 | |
| 819 | LOGD("[MP] Server discovery thread exited"); |
| 820 | } |
| 821 | |
| 822 | void ServerDiscovery::OnServerThread(void* param) |
| 823 | { |
nothing calls this directly
no test coverage detected