Some nit fixes

pull/16190/head
Muxi Yan 6 years ago
parent c9c060c52d
commit d72d5b2c8e
  1. 4
      src/objective-c/GRPCClient/GRPCCall.m
  2. 21
      src/objective-c/GRPCClient/private/GRPCChannel.m
  3. 2
      src/objective-c/GRPCClient/private/GRPCChannelPool.h
  4. 1
      src/objective-c/GRPCClient/private/GRPCChannelPool.m

@ -108,6 +108,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
/** Flags whether call has been canceled. */
BOOL _canceled;
/** Flags whether call has been finished. */
BOOL _finished;
}
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
@ -144,6 +145,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
dispatch_set_target_queue(responseHandler.dispatchQueue, _dispatchQueue);
_started = NO;
_canceled = NO;
_finished = YES;
}
return self;
@ -252,7 +254,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)finish {
dispatch_async(_dispatchQueue, ^{
NSAssert(self->started, @"Call not started.");
NSAssert(self->_started, @"Call not started.");
NSAssert(!self->_canceled, @"Call arleady canceled.");
NSAssert(!self->_finished, @"Call already half-closed.");
if (self->_call) {

@ -53,7 +53,7 @@ static GRPCChannelPool *gChannelPool;
/** Reduce call ref count to the channel and maybe set the timer. */
- (void)unrefChannel;
/** Disconnect the channel immediately. */
/** Disconnect the channel. Any further ref/unref are discarded. */
- (void)disconnect;
@end
@ -67,9 +67,8 @@ static GRPCChannelPool *gChannelPool;
dispatch_queue_t _dispatchQueue;
/**
* Date and time when last timer is scheduled. When a timer is fired, if
* _lastDispatch + _destroyDelay < now, it can be determined that another timer is scheduled after
* schedule of the current timer, hence the current one should be discarded.
* Date and time when last timer is scheduled. If a firing timer's scheduled date is different
* from this, it is discarded.
*/
NSDate *_lastDispatch;
}
@ -113,7 +112,7 @@ static GRPCChannelPool *gChannelPool;
dispatch_time_t delay =
dispatch_time(DISPATCH_TIME_NOW, (int64_t)self->_destroyDelay * NSEC_PER_SEC);
dispatch_after(delay, self->_dispatchQueue, ^{
[self timerFireWithScheduleDate:now];
[self timedDisconnectWithScheduleDate:now];
});
}
}
@ -131,7 +130,7 @@ static GRPCChannelPool *gChannelPool;
});
}
- (void)timerFireWithScheduleDate:(NSDate *)scheduleDate {
- (void)timedDisconnectWithScheduleDate:(NSDate *)scheduleDate {
dispatch_async(_dispatchQueue, ^{
if (self->_disconnected || self->_lastDispatch != scheduleDate) {
return;
@ -183,6 +182,8 @@ static GRPCChannelPool *gChannelPool;
grpc_slice_unref(host_slice);
}
grpc_slice_unref(path_slice);
} else {
NSAssert(self->_unmanagedChannel != nil, @"Invalid channeg.");
}
});
return call;
@ -255,10 +256,9 @@ static GRPCChannelPool *gChannelPool;
}
+ (nullable instancetype)createChannelWithConfiguration:(GRPCChannelConfiguration *)config {
NSAssert(config != nil, @"configuration cannot be empty");
NSString *host = config.host;
if (host.length == 0) {
return nil;
}
NSAssert(host.length != 0, @"host cannot be nil");
NSDictionary *channelArgs;
if (config.callOptions.additionalChannelArgs.count != 0) {
@ -287,6 +287,9 @@ static GRPCChannelPool *gChannelPool;
GRPCChannelConfiguration *channelConfig =
[[GRPCChannelConfiguration alloc] initWithHost:host callOptions:callOptions];
if (channelConfig == nil) {
return nil;
}
return [gChannelPool channelWithConfiguration:channelConfig];
}

@ -57,8 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface GRPCChannelPool : NSObject
- (instancetype)init;
/**
* Return a channel with a particular configuration. If the channel does not exist, execute \a
* createChannel then add it in the pool. If the channel exists, increase its reference count.

@ -192,6 +192,7 @@ extern const char *kCFStreamVarName;
}
- (GRPCChannel *)channelWithConfiguration:(GRPCChannelConfiguration *)configuration {
NSAssert(configuration != nil, @"Must has a configuration");
GRPCChannel *channel;
@synchronized(self) {
if ([_channelPool objectForKey:configuration]) {

Loading…
Cancel
Save