Only mark a PC offline if server info failed after 3 straight tries

This commit is contained in:
Cameron Gutman 2015-11-11 18:14:04 -08:00
parent 814470f4bf
commit b495246f34

View File

@ -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]); Log(LOG_D, @"%@ has %d unique addresses", _host.name, [addresses count]);
for (NSString *address in addresses) { // Give the PC 3 tries to respond before declaring it offline
if (self.cancelled) { for (int i = 0; i < 3; i++) {
// Get out without updating the status because for (NSString *address in addresses) {
// it might not have finished checking the various if (self.cancelled) {
// addresses // Get out without updating the status because
return; // 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) { if (receivedResponse) {
_host.activeAddress = address; Log(LOG_I, @"Received serverinfo response on try %d", i);
break; break;
} }
else {
// Wait for one second then retry
[NSThread sleepForTimeInterval:1];
}
} }
_host.online = receivedResponse; _host.online = receivedResponse;