aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/ProtoRPC/ProtoRPC.m
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-10-23 10:03:48 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-10-23 10:03:48 -0700
commite39c146f0f7f1a56e0cd65ec5d707c8bb091366e (patch)
treee1a886a3d55284d077759ef653e575b25106796b /src/objective-c/ProtoRPC/ProtoRPC.m
parent76ddfcb6cb87611addcbc68b01264e37a4705d27 (diff)
Revert "Do not issue more message when the call is canceled"
Diffstat (limited to 'src/objective-c/ProtoRPC/ProtoRPC.m')
-rw-r--r--src/objective-c/ProtoRPC/ProtoRPC.m43
1 files changed, 10 insertions, 33 deletions
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m
index 6085f89356..294f3a4cf5 100644
--- a/src/objective-c/ProtoRPC/ProtoRPC.m
+++ b/src/objective-c/ProtoRPC/ProtoRPC.m
@@ -84,11 +84,6 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
GRPCCall2 *_call;
dispatch_queue_t _dispatchQueue;
- /**
- * Flags that the call has been canceled. When this is true, pending initial metadata and message
- * should not be issued to \a _handler. This ivar must be accessed with lock to self.
- */
- BOOL _canceled;
}
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
@@ -118,7 +113,6 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
_dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL);
}
dispatch_set_target_queue(handler.dispatchQueue, _dispatchQueue);
- _canceled = NO;
[self start];
}
@@ -134,15 +128,12 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (void)cancel {
dispatch_async(_dispatchQueue, ^{
- if (self->_call) {
- [self->_call cancel];
- self->_call = nil;
+ if (_call) {
+ [_call cancel];
+ _call = nil;
}
- if (self->_handler) {
- @synchronized(self) {
- self->_canceled = YES;
- }
- id<GRPCProtoResponseHandler> handler = self->_handler;
+ if (_handler) {
+ id<GRPCProtoResponseHandler> handler = _handler;
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
dispatch_async(handler.dispatchQueue, ^{
[handler closedWithTrailingMetadata:nil
@@ -154,7 +145,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}]];
});
}
- self->_handler = nil;
+ _handler = nil;
}
});
}
@@ -182,17 +173,10 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata {
if (_handler && initialMetadata != nil) {
- __block id<GRPCResponseHandler> handler = _handler;
+ id<GRPCProtoResponseHandler> handler = _handler;
if ([handler respondsToSelector:@selector(initialMetadata:)]) {
dispatch_async(handler.dispatchQueue, ^{
- // Do not issue initial metadata if the call is already canceled.
- __block BOOL canceled = NO;
- @synchronized(self) {
- canceled = self->_canceled;
- }
- if (!canceled) {
- [handler receivedInitialMetadata:initialMetadata];
- }
+ [handler receivedInitialMetadata:initialMetadata];
});
}
}
@@ -200,20 +184,13 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (void)receivedRawMessage:(NSData *_Nullable)message {
if (_handler && message != nil) {
- __block id<GRPCProtoResponseHandler> handler = _handler;
+ id<GRPCProtoResponseHandler> handler = _handler;
NSError *error = nil;
GPBMessage *parsed = [_responseClass parseFromData:message error:&error];
if (parsed) {
if ([handler respondsToSelector:@selector(receivedProtoMessage:)]) {
dispatch_async(handler.dispatchQueue, ^{
- // Do not issue message if the call is already canceled.
- __block BOOL canceled = NO;
- @synchronized(self) {
- canceled = self->_canceled;
- }
- if (!canceled) {
- [handler receivedProtoMessage:parsed];
- }
+ [handler receivedProtoMessage:parsed];
});
}
} else {