diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index dd0f045..c5da2c8 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -668,8 +668,9 @@ - (BOOL) domianCache:(NSDictionary *)cache hit:(NSString *)domain { # pragma mark - servers - (NSString *)currentDnsServer { - if (self.serverIndex < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { - return [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] objectAtIndex:self.serverIndex]; + int index = self.serverIndex; + if (index < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { + return [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] objectAtIndex:index]; } return [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsIp]; } @@ -680,7 +681,7 @@ - (void)switchDnsServer { } self.waitToSwitch = YES; dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - if (self.serverIndex < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { + if (self.serverIndex < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count] - 1) { self.serverIndex += 1; if (!self.firstFailTime) { self.firstFailTime = [NSDate date];