aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2015-08-01 02:56:04 -0700
committerGravatar Jorge Canizales <jcanizales@google.com>2015-08-01 18:02:31 -0700
commit148403af988522e61f4e71dc1bbd00b9f0d51a42 (patch)
tree382a158c41c8b0ee6748f4cbfa0b825321c3a199 /src/objective-c/GRPCClient
parentbd993df3f6eeaea7b032b272703c5fc41beeebef (diff)
Remove GRPCChannel-initWithHost to simplify implementation
Diffstat (limited to 'src/objective-c/GRPCClient')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.h1
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.m22
-rw-r--r--src/objective-c/GRPCClient/private/GRPCSecureChannel.h2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h2
4 files changed, 11 insertions, 16 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h
index 49f5bfcc18..49f8b712b9 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.h
@@ -43,7 +43,6 @@
// Convenience constructor to allow for reuse of connections.
+ (instancetype)channelToHost:(NSString *)host;
-- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel
hostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER;
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m
index 44f64e704a..90973cd83d 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.m
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.m
@@ -54,17 +54,13 @@
});
GRPCChannel *channel = channelCache[host];
if (!channel) {
- channel = [[self alloc] initWithHost:host];
+ channel = [self uncachedChannelToHost:host];
channelCache[host] = channel;
}
return channel;
}
-- (instancetype)init {
- return [self initWithHost:nil];
-}
-
-- (instancetype)initWithHost:(NSString *)host {
++ (instancetype)uncachedChannelToHost:(NSString *)host {
if (![host rangeOfString:@"://"].length) {
// No scheme provided; assume https.
host = [@"https://" stringByAppendingString:host];
@@ -86,6 +82,10 @@
return nil; // silence warning.
}
+- (instancetype)init {
+ return [self initWithChannel:NULL hostName:nil];
+}
+
- (instancetype)initWithChannel:(struct grpc_channel *)unmanagedChannel
hostName:(NSString *)hostName {
if (!unmanagedChannel || !hostName) {
@@ -113,12 +113,8 @@
}
- (void)dealloc {
- // _unmanagedChannel is NULL when deallocating an object of the base class (because the
- // initializer returns a different object).
- if (_unmanagedChannel) {
- // TODO(jcanizales): Be sure to add a test with a server that closes the connection prematurely,
- // as in the past that made this call to crash.
- grpc_channel_destroy(_unmanagedChannel);
- }
+ // TODO(jcanizales): Be sure to add a test with a server that closes the connection prematurely,
+ // as in the past that made this call to crash.
+ grpc_channel_destroy(_unmanagedChannel);
}
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h b/src/objective-c/GRPCClient/private/GRPCSecureChannel.h
index d34ceaea0c..8c5fe33d61 100644
--- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCSecureChannel.h
@@ -34,5 +34,5 @@
#import "GRPCChannel.h"
@interface GRPCSecureChannel : GRPCChannel
-
+- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h
index 9d89cfb541..8528be44c0 100644
--- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h
@@ -34,5 +34,5 @@
#import "GRPCChannel.h"
@interface GRPCUnsecuredChannel : GRPCChannel
-
+- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end