Skip to content
Snippets Groups Projects
Commit 148403af authored by Jorge Canizales's avatar Jorge Canizales
Browse files

Remove GRPCChannel-initWithHost to simplify implementation

parent bd993df3
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
// Convenience constructor to allow for reuse of connections. // Convenience constructor to allow for reuse of connections.
+ (instancetype)channelToHost:(NSString *)host; + (instancetype)channelToHost:(NSString *)host;
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel - (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel
hostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER; hostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER;
......
...@@ -54,17 +54,13 @@ ...@@ -54,17 +54,13 @@
}); });
GRPCChannel *channel = channelCache[host]; GRPCChannel *channel = channelCache[host];
if (!channel) { if (!channel) {
channel = [[self alloc] initWithHost:host]; channel = [self uncachedChannelToHost:host];
channelCache[host] = channel; channelCache[host] = channel;
} }
return channel; return channel;
} }
- (instancetype)init { + (instancetype)uncachedChannelToHost:(NSString *)host {
return [self initWithHost:nil];
}
- (instancetype)initWithHost:(NSString *)host {
if (![host rangeOfString:@"://"].length) { if (![host rangeOfString:@"://"].length) {
// No scheme provided; assume https. // No scheme provided; assume https.
host = [@"https://" stringByAppendingString:host]; host = [@"https://" stringByAppendingString:host];
...@@ -86,6 +82,10 @@ ...@@ -86,6 +82,10 @@
return nil; // silence warning. return nil; // silence warning.
} }
- (instancetype)init {
return [self initWithChannel:NULL hostName:nil];
}
- (instancetype)initWithChannel:(struct grpc_channel *)unmanagedChannel - (instancetype)initWithChannel:(struct grpc_channel *)unmanagedChannel
hostName:(NSString *)hostName { hostName:(NSString *)hostName {
if (!unmanagedChannel || !hostName) { if (!unmanagedChannel || !hostName) {
...@@ -113,12 +113,8 @@ ...@@ -113,12 +113,8 @@
} }
- (void)dealloc { - (void)dealloc {
// _unmanagedChannel is NULL when deallocating an object of the base class (because the // TODO(jcanizales): Be sure to add a test with a server that closes the connection prematurely,
// initializer returns a different object). // as in the past that made this call to crash.
if (_unmanagedChannel) { 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 @end
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
#import "GRPCChannel.h" #import "GRPCChannel.h"
@interface GRPCSecureChannel : GRPCChannel @interface GRPCSecureChannel : GRPCChannel
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end @end
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
#import "GRPCChannel.h" #import "GRPCChannel.h"
@interface GRPCUnsecuredChannel : GRPCChannel @interface GRPCUnsecuredChannel : GRPCChannel
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end @end
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