aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-11-14 17:59:30 -0800
committerGravatar Muxi Yan <mxyan@google.com>2018-11-14 17:59:30 -0800
commit2bd38f29df16b874bea254e001e3c40d6945c28c (patch)
tree6786a741cfad16e2f41c96b02ee8937494c2cc9b /src/objective-c
parente023468e9a82a4338e30e57ab822c86406480b94 (diff)
Batch fixes
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.m17
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m7
2 files changed, 13 insertions, 11 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m
index fc0448bb96..52dacad9f5 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.m
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.m
@@ -84,7 +84,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
NSString *userAgent = @"grpc-objc/" GRPC_OBJC_VERSION_STRING;
NSString *userAgentPrefix = _callOptions.userAgentPrefix;
- if (userAgentPrefix) {
+ if (userAgentPrefix.length != 0) {
args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] =
[_callOptions.userAgentPrefix stringByAppendingFormat:@" %@", userAgent];
} else {
@@ -242,7 +242,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
if (self->_disconnected) {
isDisconnected = YES;
} else {
- GRPCAssert(self->_unmanagedChannel != NULL, NSInvalidArgumentException, @"Invalid channel.");
+ GRPCAssert(self->_unmanagedChannel != NULL, NSInternalInconsistencyException, @"Channel should have valid unmanaged channel.");
NSString *serverAuthority =
callOptions.transportType == GRPCTransportTypeCronet ? nil : callOptions.serverAuthority;
@@ -281,14 +281,17 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
// This function should be called on _dispatchQueue.
- (void)ref {
- _refcount++;
- if (_refcount == 1 && _lastDispatch != nil) {
- _lastDispatch = nil;
- }
+ dispatch_sync(_dispatchQueue, ^{
+ self->_refcount++;
+ if (self->_refcount == 1 && self->_lastDispatch != nil) {
+ self->_lastDispatch = nil;
+ }
+ });
}
- (void)unref {
dispatch_async(_dispatchQueue, ^{
+ GRPCAssert(self->_refcount > 0, NSInternalInconsistencyException, @"Illegal reference count.");
self->_refcount--;
if (self->_refcount == 0 && !self->_disconnected) {
// Start timer.
@@ -298,7 +301,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
self->_lastDispatch = now;
dispatch_after(delay, self->_dispatchQueue, ^{
// Timed disconnection.
- if (self->_lastDispatch == now) {
+ if (!self->_disconnected && self->_lastDispatch == now) {
grpc_channel_destroy(self->_unmanagedChannel);
self->_unmanagedChannel = NULL;
self->_disconnected = YES;
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
index 2358c7bb0a..f3fe8bac45 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -30,6 +30,7 @@
#import "NSData+GRPC.h"
#import "NSDictionary+GRPC.h"
#import "NSError+GRPC.h"
+#import "utilities.h"
#import "GRPCOpBatchLog.h"
@@ -248,16 +249,14 @@
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
callOptions:(GRPCCallOptions *)callOptions {
- if (host.length == 0 || path.length == 0) {
- [NSException raise:NSInvalidArgumentException format:@"path and host cannot be nil."];
- }
+ GRPCAssert(host.length != 0 && path.length != 0, NSInvalidArgumentException, @"path and host cannot be nil.");
if ((self = [super init])) {
// Each completion queue consumes one thread. There's a trade to be made between creating and
// consuming too many threads and having contention of multiple calls in a single completion
// queue. Currently we use a singleton queue.
_queue = [GRPCCompletionQueue completionQueue];
- BOOL disconnected;
+ BOOL disconnected = NO;
do {
_channel = [[GRPCChannelPool sharedInstance] channelWithHost:host callOptions:callOptions];
if (_channel == nil) {