Remove GRPCChannel-initWithHost to simplify implementation

pull/2754/head
Jorge Canizales 9 years ago
parent bd993df3f6
commit 148403af98
  1. 1
      src/objective-c/GRPCClient/private/GRPCChannel.h
  2. 16
      src/objective-c/GRPCClient/private/GRPCChannel.m
  3. 2
      src/objective-c/GRPCClient/private/GRPCSecureChannel.h
  4. 2
      src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.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;

@ -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);
}
}
@end

@ -34,5 +34,5 @@
#import "GRPCChannel.h"
@interface GRPCSecureChannel : GRPCChannel
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end

@ -34,5 +34,5 @@
#import "GRPCChannel.h"
@interface GRPCUnsecuredChannel : GRPCChannel
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end

Loading…
Cancel
Save