|
|
|
@ -33,7 +33,7 @@ |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions |
|
|
|
|
message:(GPBMessage *)message |
|
|
|
|
responseHandler:(id<GRPCResponseHandler>)handler |
|
|
|
|
responseHandler:(id<GRPCProtoResponseHandler>)handler |
|
|
|
|
callOptions:(GRPCCallOptions *)callOptions |
|
|
|
|
responseClass:(Class)responseClass { |
|
|
|
|
if ((self = [super init])) { |
|
|
|
@ -60,7 +60,7 @@ |
|
|
|
|
|
|
|
|
|
@implementation GRPCStreamingProtoCall { |
|
|
|
|
GRPCRequestOptions *_requestOptions; |
|
|
|
|
id<GRPCResponseHandler> _handler; |
|
|
|
|
id<GRPCProtoResponseHandler> _handler; |
|
|
|
|
GRPCCallOptions *_callOptions; |
|
|
|
|
Class _responseClass; |
|
|
|
|
|
|
|
|
@ -69,7 +69,7 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions |
|
|
|
|
responseHandler:(id<GRPCResponseHandler>)handler |
|
|
|
|
responseHandler:(id<GRPCProtoResponseHandler>)handler |
|
|
|
|
callOptions:(GRPCCallOptions *)callOptions |
|
|
|
|
responseClass:(Class)responseClass { |
|
|
|
|
if ((self = [super init])) { |
|
|
|
@ -98,7 +98,8 @@ |
|
|
|
|
_call = nil; |
|
|
|
|
} |
|
|
|
|
if (_handler) { |
|
|
|
|
id<GRPCResponseHandler> handler = _handler; |
|
|
|
|
id<GRPCProtoResponseHandler> handler = _handler; |
|
|
|
|
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { |
|
|
|
|
dispatch_async(handler.dispatchQueue, ^{ |
|
|
|
|
[handler closedWithTrailingMetadata:nil |
|
|
|
|
error:[NSError errorWithDomain:kGRPCErrorDomain |
|
|
|
@ -108,6 +109,7 @@ |
|
|
|
|
@"Canceled by app" |
|
|
|
|
}]]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
_handler = nil; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -136,27 +138,33 @@ |
|
|
|
|
|
|
|
|
|
- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { |
|
|
|
|
if (_handler) { |
|
|
|
|
id<GRPCResponseHandler> handler = _handler; |
|
|
|
|
id<GRPCProtoResponseHandler> handler = _handler; |
|
|
|
|
if ([handler respondsToSelector:@selector(initialMetadata:)]) { |
|
|
|
|
dispatch_async(handler.dispatchQueue, ^{ |
|
|
|
|
[handler receivedInitialMetadata:initialMetadata]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)receivedMessage:(NSData *)message { |
|
|
|
|
- (void)receivedRawMessage:(NSData *)message { |
|
|
|
|
if (_handler) { |
|
|
|
|
id<GRPCResponseHandler> handler = _handler; |
|
|
|
|
id<GRPCProtoResponseHandler> handler = _handler; |
|
|
|
|
NSError *error = nil; |
|
|
|
|
id parsed = [_responseClass parseFromData:message error:&error]; |
|
|
|
|
if (parsed) { |
|
|
|
|
if ([handler respondsToSelector:@selector(receivedProtoMessage:)]) { |
|
|
|
|
dispatch_async(handler.dispatchQueue, ^{ |
|
|
|
|
[handler receivedMessage:parsed]; |
|
|
|
|
[handler receivedProtoMessage:parsed]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { |
|
|
|
|
dispatch_async(handler.dispatchQueue, ^{ |
|
|
|
|
[handler closedWithTrailingMetadata:nil error:error]; |
|
|
|
|
}); |
|
|
|
|
handler = nil; |
|
|
|
|
} |
|
|
|
|
_handler = nil; |
|
|
|
|
[_call cancel]; |
|
|
|
|
_call = nil; |
|
|
|
|
} |
|
|
|
@ -165,17 +173,17 @@ |
|
|
|
|
|
|
|
|
|
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { |
|
|
|
|
if (_handler) { |
|
|
|
|
id<GRPCResponseHandler> handler = _handler; |
|
|
|
|
id<GRPCProtoResponseHandler> handler = _handler; |
|
|
|
|
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { |
|
|
|
|
dispatch_async(handler.dispatchQueue, ^{ |
|
|
|
|
[handler closedWithTrailingMetadata:trailingMetadata error:error]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
_handler = nil; |
|
|
|
|
} |
|
|
|
|
if (_call) { |
|
|
|
|
[_call cancel]; |
|
|
|
|
_call = nil; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (dispatch_queue_t)dispatchQueue { |
|
|
|
|
return _dispatchQueue; |
|
|
|
|