From b495246f34b05603266ae7981c72787b9083674c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 11 Nov 2015 18:14:04 -0800 Subject: [PATCH] Only mark a PC offline if server info failed after 3 straight tries --- Limelight/Network/DiscoveryWorker.m | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Limelight/Network/DiscoveryWorker.m b/Limelight/Network/DiscoveryWorker.m index ba6a411..d86d58a 100644 --- a/Limelight/Network/DiscoveryWorker.m +++ b/Limelight/Network/DiscoveryWorker.m @@ -87,20 +87,32 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds Log(LOG_D, @"%@ has %d unique addresses", _host.name, [addresses count]); - for (NSString *address in addresses) { - if (self.cancelled) { - // Get out without updating the status because - // it might not have finished checking the various - // addresses - return; + // Give the PC 3 tries to respond before declaring it offline + for (int i = 0; i < 3; i++) { + for (NSString *address in addresses) { + if (self.cancelled) { + // Get out without updating the status because + // it might not have finished checking the various + // addresses + return; + } + + ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:address]; + receivedResponse = [self checkResponse:serverInfoResp]; + if (receivedResponse) { + _host.activeAddress = address; + break; + } } - ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:address]; - receivedResponse = [self checkResponse:serverInfoResp]; if (receivedResponse) { - _host.activeAddress = address; + Log(LOG_I, @"Received serverinfo response on try %d", i); break; } + else { + // Wait for one second then retry + [NSThread sleepForTimeInterval:1]; + } } _host.online = receivedResponse;