From 0a18d64fccb9f42a6dd6efcfb1634d541b09af81 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 20 Oct 2016 18:03:24 -0700 Subject: [PATCH] Address the comments --- .../GRPCClient/private/GRPCConnectivityMonitor.m | 11 +++-------- src/objective-c/GRPCClient/private/GRPCHost.m | 3 +++ .../private/GRPCReachabilityFlagNames.xmacro.h | 3 +-- src/objective-c/tests/Connectivity/Podfile | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m index afd773c70c4..b2a10db432a 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m @@ -130,13 +130,7 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, if ((self = [super init])) { _reachabilityRef = CFRetain(reachability); _queue = dispatch_get_main_queue(); - SCNetworkReachabilityFlags flags; - if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) { - _previousReachabilityFlags = - [[GRPCReachabilityFlags alloc] initWithFlags:flags]; - } else { - _previousReachabilityFlags = 0; - } + _previousReachabilityFlags = nil; } return self; } @@ -162,7 +156,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, [self startListeningWithHandler:^(GRPCReachabilityFlags *flags) { if (!flags.reachable) { handler(); - } else if (flags.isWWAN ^ _previousReachabilityFlags.isWWAN) { + } else if (!_previousReachabilityFlags || + (flags.isWWAN ^ _previousReachabilityFlags.isWAAN)) { wifiStatusChangeHandler(); } _previousReachabilityFlags = flags; diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index ee6045653e9..256278bd49b 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -101,6 +101,9 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil; _secure = YES; kHostCache[address] = self; + // When there is host in the cache, keep a single monitor to the network + // to + // flush the cache if the connectivity status changed if (!connectivityMonitor) { connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:hostURL.host]; diff --git a/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h b/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h index 1c907877a0e..f5b9e7e64c2 100644 --- a/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h +++ b/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h @@ -55,7 +55,7 @@ #endif #if TARGET_OS_IPHONE -GRPC_XMACRO_ITEM(isCell, IsWWAN) +GRPC_XMACRO_ITEM(isWWAN, IsWWAN) #endif GRPC_XMACRO_ITEM(reachable, Reachable) GRPC_XMACRO_ITEM(transientConnection, TransientConnection) @@ -65,4 +65,3 @@ GRPC_XMACRO_ITEM(interventionRequired, InterventionRequired) GRPC_XMACRO_ITEM(connectionOnDemand, ConnectionOnDemand) GRPC_XMACRO_ITEM(isLocalAddress, IsLocalAddress) GRPC_XMACRO_ITEM(isDirect, IsDirect) -GRPC_XMACRO_ITEM(isWWAN, IsWWAN) diff --git a/src/objective-c/tests/Connectivity/Podfile b/src/objective-c/tests/Connectivity/Podfile index 547a38b1ca2..27ff935c544 100644 --- a/src/objective-c/tests/Connectivity/Podfile +++ b/src/objective-c/tests/Connectivity/Podfile @@ -8,6 +8,7 @@ target 'ConnectivityTestingApp' do pod 'gRPC', :path => GRPC_LOCAL_SRC pod 'gRPC-Core', :path => GRPC_LOCAL_SRC pod 'gRPC-ProtoRPC', :path => GRPC_LOCAL_SRC + pod 'gRPC-RxLibrary', :path => GRPC_LOCAL_SRC pod 'Protobuf', :path => "#{GRPC_LOCAL_SRC}/third_party/protobuf" pod 'BoringSSL', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" end