diff options
author | Muxi Yan <mxyan@google.com> | 2018-11-15 14:56:50 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-11-15 14:56:50 -0800 |
commit | ffeb0e682393e5b76d732e0b034c71f3837b9e57 (patch) | |
tree | 6670407948c46fafdc7ac711cbc9e2803af8dfa2 /src/objective-c/GRPCClient/GRPCCall.m | |
parent | 57464321214a5ce34e5de1868ce4eb3624ebdebb (diff) |
Add *if* after assert
Diffstat (limited to 'src/objective-c/GRPCClient/GRPCCall.m')
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall.m | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 68b51d8c84..f340e2bd8c 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -69,6 +69,12 @@ const char *kCFStreamVarName = "grpc_cfstream"; - (instancetype)initWithHost:(NSString *)host path:(NSString *)path safety:(GRPCCallSafety)safety { NSAssert(host.length != 0 && path.length != 0, @"Host and Path cannot be empty"); + if (host.length == 0) { + host = [NSString string]; + } + if (path.length == 0) { + path = [NSString string]; + } if ((self = [super init])) { _host = [host copy]; _path = [path copy]; @@ -120,6 +126,16 @@ const char *kCFStreamVarName = "grpc_cfstream"; NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value."); NSAssert(responseHandler != nil, @"Response handler required."); + if (requestOptions.host.length == 0 || requestOptions.path.length == 0) { + return nil; + } + if (requestOptions.safety > GRPCCallSafetyCacheableRequest) { + return nil; + } + if (responseHandler == nil) { + return nil; + } + if ((self = [super init])) { _requestOptions = [requestOptions copy]; @@ -158,6 +174,13 @@ const char *kCFStreamVarName = "grpc_cfstream"; dispatch_async(_dispatchQueue, ^{ NSAssert(!self->_started, @"Call already started."); NSAssert(!self->_canceled, @"Call already canceled."); + if (self->_started) { + return; + } + if (self->_canceled) { + return; + } + self->_started = YES; if (!self->_callOptions) { self->_callOptions = [[GRPCCallOptions alloc] init]; @@ -218,6 +241,10 @@ const char *kCFStreamVarName = "grpc_cfstream"; - (void)cancel { dispatch_async(_dispatchQueue, ^{ NSAssert(!self->_canceled, @"Call already canceled."); + if (self->_canceled) { + return; + } + self->_canceled = YES; if (self->_call) { [self->_call cancel]; @@ -248,6 +275,13 @@ const char *kCFStreamVarName = "grpc_cfstream"; dispatch_async(_dispatchQueue, ^{ NSAssert(!self->_canceled, @"Call arleady canceled."); NSAssert(!self->_finished, @"Call is half-closed before sending data."); + if (self->_canceled) { + return; + } + if (self->_finished) { + return; + } + if (self->_pipe) { [self->_pipe writeValue:data]; } @@ -259,6 +293,16 @@ const char *kCFStreamVarName = "grpc_cfstream"; NSAssert(self->_started, @"Call not started."); NSAssert(!self->_canceled, @"Call arleady canceled."); NSAssert(!self->_finished, @"Call already half-closed."); + if (!self->_started) { + return; + } + if (self->_canceled) { + return; + } + if (self->_finished) { + return; + } + if (self->_pipe) { [self->_pipe writesFinishedWithError:nil]; } @@ -412,6 +456,16 @@ const char *kCFStreamVarName = "grpc_cfstream"; @"Invalid call safety value."); NSAssert(requestWriter.state == GRXWriterStateNotStarted, @"The requests writer can't be already started."); + if (!host || !path) { + return nil; + } + if (safety > GRPCCallSafetyCacheableRequest) { + return nil; + } + if (requestWriter.state != GRXWriterStateNotStarted) { + return nil; + } + if ((self = [super init])) { _host = [host copy]; _path = [path copy]; |