diff options
author | Muxi Yan <mxyan@google.com> | 2018-11-08 15:33:27 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-11-08 15:33:27 -0800 |
commit | d72d5b2c8eaa8a434a7db4624fe6a45bc0d6bde4 (patch) | |
tree | 5561a5a513a8e1564ebd97896f5a1c54f72db322 /src/objective-c | |
parent | c9c060c52da12cc55bbd383b1544260ad665dbab (diff) |
Some nit fixes
Diffstat (limited to 'src/objective-c')
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall.m | 4 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannel.m | 21 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannelPool.h | 2 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannelPool.m | 1 |
4 files changed, 16 insertions, 12 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 321a0bd1bd..9b9b4f9547 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.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) { diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 0ca2a35992..773f4261d7 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -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]; } diff --git a/src/objective-c/GRPCClient/private/GRPCChannelPool.h b/src/objective-c/GRPCClient/private/GRPCChannelPool.h index 2244361df2..f99c0ba4dc 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelPool.h +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.h @@ -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. diff --git a/src/objective-c/GRPCClient/private/GRPCChannelPool.m b/src/objective-c/GRPCClient/private/GRPCChannelPool.m index b4a589ae83..1bf2a5c563 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelPool.m +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.m @@ -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]) { |