aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-10-18 16:05:18 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-10-18 16:05:18 -0700
commit4201ad1681064d591f6a47fa5b3c6f824cb7cecb (patch)
tree47d76c1e76e0571719182f527518cb626758eb1a
parentb9e522420741024e05f8ef3ccde7fbeeaaea2234 (diff)
add callOptionsForHost: to GRPCHost
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m8
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.h4
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m22
3 files changed, 17 insertions, 17 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 3f77aaafb3..399206a346 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -749,12 +749,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
if (_callOptions == nil) {
GRPCMutableCallOptions *callOptions;
- if ([GRPCHost isHostConfigured:_host]) {
- GRPCHost *hostConfig = [GRPCHost hostWithAddress:_host];
- callOptions = [hostConfig.callOptions mutableCopy];
- } else {
- callOptions = [[GRPCMutableCallOptions alloc] init];
- }
+
+ callOptions = [[GRPCHost callOptionsForHost:_host] mutableCopy];
if (_serverName.length != 0) {
callOptions.serverAuthority = _serverName;
}
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h
index e321363bcb..f1d5719642 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.h
+++ b/src/objective-c/GRPCClient/private/GRPCHost.h
@@ -66,9 +66,7 @@ struct grpc_channel_credentials;
@property(atomic, readwrite) GRPCTransportType transportType;
-@property(readonly) GRPCCallOptions *callOptions;
-
-+ (BOOL)isHostConfigured:(NSString *)address;
++ (GRPCCallOptions *)callOptionsForHost:(NSString *)host;
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 032b274ffc..5fe022a1ba 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -133,17 +133,23 @@ static NSMutableDictionary *gHostCache;
return options;
}
-+ (BOOL)isHostConfigured:(NSString *)address {
++ (GRPCCallOptions *)callOptionsForHost:(NSString *)host {
// TODO (mxyan): Remove when old API is deprecated
- NSURL *hostURL = [NSURL URLWithString:[@"https://" stringByAppendingString:address]];
- if (hostURL.host && !hostURL.port) {
- address = [hostURL.host stringByAppendingString:@":443"];
+ NSURL *hostURL = [NSURL URLWithString:[@"https://" stringByAppendingString:host]];
+ if (hostURL.host && hostURL.port == nil) {
+ host = [hostURL.host stringByAppendingString:@":443"];
+ }
+
+ __block GRPCCallOptions *callOptions = nil;
+ @synchronized(gHostCache) {
+ if ([gHostCache objectForKey:host]) {
+ callOptions = [gHostCache[host] callOptions];
+ }
}
- __block GRPCHost *cachedHost;
- @synchronized (gHostCache) {
- cachedHost = gHostCache[address];
+ if (callOptions == nil) {
+ callOptions = [[GRPCCallOptions alloc] init];
}
- return (cachedHost != nil);
+ return callOptions;
}
@end