Skip to content
Snippets Groups Projects
Commit 6f5cfedf authored by Muxi Yan's avatar Muxi Yan
Browse files

Add comments for GRPCHost

parent 4f6a19b2
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN
#define GRPC_OBJC_VERSION_STRING @"1.0.0" #define GRPC_OBJC_VERSION_STRING @"1.0.0"
static NSMutableDictionary *kHostCache; static NSMutableDictionary *kHostCache;
// This connectivity monitor flushes the host cache when connectivity status
// changes. Otherwise, a new call might still use the cached channel which is
// no longer available and will call gRPC to hang
static GRPCConnectivityMonitor *connectivityMonitor = nil; static GRPCConnectivityMonitor *connectivityMonitor = nil;
@implementation GRPCHost { @implementation GRPCHost {
...@@ -94,6 +98,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil; ...@@ -94,6 +98,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
dispatch_once(&cacheInitialization, ^{ dispatch_once(&cacheInitialization, ^{
kHostCache = [NSMutableDictionary dictionary]; kHostCache = [NSMutableDictionary dictionary];
}); });
@synchronized(kHostCache) { @synchronized(kHostCache) {
GRPCHost *cachedHost = kHostCache[address]; GRPCHost *cachedHost = kHostCache[address];
if (cachedHost) { if (cachedHost) {
...@@ -106,6 +111,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil; ...@@ -106,6 +111,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
kHostCache[address] = self; kHostCache[address] = self;
} }
// Keep a single monitor to flush the cache if the connectivity status changed // Keep a single monitor to flush the cache if the connectivity status changed
// Thread safety guarded by @synchronized(kHostCache)
if (!connectivityMonitor) { if (!connectivityMonitor) {
connectivityMonitor = connectivityMonitor =
[GRPCConnectivityMonitor monitorWithHost:hostURL.host]; [GRPCConnectivityMonitor monitorWithHost:hostURL.host];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment