clang-format

pull/17578/head
Muxi Yan 6 years ago
parent 03232ba46f
commit 3cdc0db838
  1. 77
      src/objective-c/GRPCClient/GRPCCall.m
  2. 4
      src/objective-c/RxLibrary/GRXBufferedPipe.m
  3. 8
      src/objective-c/RxLibrary/GRXConcurrentWriteable.h
  4. 6
      src/objective-c/RxLibrary/GRXConcurrentWriteable.m
  5. 12
      src/objective-c/RxLibrary/GRXForwardingWriter.m
  6. 4
      src/objective-c/RxLibrary/GRXImmediateSingleWriter.m

@ -448,7 +448,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
return; return;
} }
NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path];
@synchronized (callFlags) { @synchronized(callFlags) {
switch (callSafety) { switch (callSafety) {
case GRPCCallSafetyDefault: case GRPCCallSafetyDefault:
callFlags[hostAndPath] = @0; callFlags[hostAndPath] = @0;
@ -468,7 +468,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
+ (uint32_t)callFlagsForHost:(NSString *)host path:(NSString *)path { + (uint32_t)callFlagsForHost:(NSString *)host path:(NSString *)path {
NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path];
uint32_t flags = 0; uint32_t flags = 0;
@synchronized (callFlags) { @synchronized(callFlags) {
flags = [callFlags[hostAndPath] intValue]; flags = [callFlags[hostAndPath] intValue];
} }
return flags; return flags;
@ -529,7 +529,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
- (void)setResponseDispatchQueue:(dispatch_queue_t)queue { - (void)setResponseDispatchQueue:(dispatch_queue_t)queue {
@synchronized (self) { @synchronized(self) {
if (_state != GRXWriterStateNotStarted) { if (_state != GRXWriterStateNotStarted) {
return; return;
} }
@ -562,14 +562,14 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
- (void)cancel { - (void)cancel {
@synchronized (self) { @synchronized(self) {
if (_state == GRXWriterStateFinished) { if (_state == GRXWriterStateFinished) {
return; return;
} }
[self finishWithError:[NSError [self finishWithError:[NSError
errorWithDomain:kGRPCErrorDomain errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]]; userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]];
[_wrappedCall cancel]; [_wrappedCall cancel];
} }
} }
@ -636,19 +636,19 @@ const char *kCFStreamVarName = "grpc_cfstream";
// don't want to throw, because the app shouldn't crash for a behavior // don't want to throw, because the app shouldn't crash for a behavior
// that's on the hands of any server to have. Instead we finish and ask // that's on the hands of any server to have. Instead we finish and ask
// the server to cancel. // the server to cancel.
@synchronized (strongSelf) { @synchronized(strongSelf) {
[strongSelf [strongSelf
finishWithError:[NSError errorWithDomain:kGRPCErrorDomain finishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeResourceExhausted code:GRPCErrorCodeResourceExhausted
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Client does not have enough memory to " @"Client does not have enough memory to "
@"hold the server response." @"hold the server response."
}]]; }]];
[strongSelf->_wrappedCall cancel]; [strongSelf->_wrappedCall cancel];
} }
} else { } else {
@synchronized (strongSelf) { @synchronized(strongSelf) {
[strongSelf->_responseWriteable enqueueValue:data [strongSelf->_responseWriteable enqueueValue:data
completionHandler:^{ completionHandler:^{
[strongSelf startNextRead]; [strongSelf startNextRead];
@ -689,9 +689,10 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
// TODO(jcanizales): Add error handlers for async failures // TODO(jcanizales): Add error handlers for async failures
GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc] initWithMetadata:headers GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc]
flags:callSafetyFlags initWithMetadata:headers
handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA flags:callSafetyFlags
handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA
dispatch_async(_callQueue, ^{ dispatch_async(_callQueue, ^{
if (!self->_unaryCall) { if (!self->_unaryCall) {
[self->_wrappedCall startBatchWithOperations:@[ op ]]; [self->_wrappedCall startBatchWithOperations:@[ op ]];
@ -731,7 +732,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)writeValue:(id)value { - (void)writeValue:(id)value {
NSAssert([value isKindOfClass:[NSData class]], @"value must be of type NSData"); NSAssert([value isKindOfClass:[NSData class]], @"value must be of type NSData");
@synchronized (self) { @synchronized(self) {
if (_state == GRXWriterStateFinished) { if (_state == GRXWriterStateFinished) {
return; return;
} }
@ -782,9 +783,9 @@ const char *kCFStreamVarName = "grpc_cfstream";
dispatch_async(_callQueue, ^{ dispatch_async(_callQueue, ^{
// TODO(jcanizales): Add error handlers for async failures // TODO(jcanizales): Add error handlers for async failures
[self->_wrappedCall [self->_wrappedCall
startBatchWithOperations:@[ [[GRPCOpRecvMetadata alloc] initWithHandler:headersHandler] ]]; startBatchWithOperations:@[ [[GRPCOpRecvMetadata alloc] initWithHandler:headersHandler] ]];
[self->_wrappedCall [self->_wrappedCall
startBatchWithOperations:@[ [[GRPCOpRecvStatus alloc] initWithHandler:completionHandler] ]]; startBatchWithOperations:@[ [[GRPCOpRecvStatus alloc] initWithHandler:completionHandler] ]];
}); });
} }
@ -825,16 +826,16 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Lock acquired inside startWithWriteable: // Lock acquired inside startWithWriteable:
- (void)startCallWithWriteable:(id<GRXWriteable>)writeable { - (void)startCallWithWriteable:(id<GRXWriteable>)writeable {
@synchronized (self) { @synchronized(self) {
if (_state == GRXWriterStateFinished) { if (_state == GRXWriterStateFinished) {
return; return;
} }
_responseWriteable = _responseWriteable =
[[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue];
GRPCPooledChannel *channel = GRPCPooledChannel *channel =
[[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions];
_wrappedCall = [channel wrappedCallWithPath:_path _wrappedCall = [channel wrappedCallWithPath:_path
completionQueue:[GRPCCompletionQueue completionQueue] completionQueue:[GRPCCompletionQueue completionQueue]
callOptions:_callOptions]; callOptions:_callOptions];
@ -843,9 +844,9 @@ const char *kCFStreamVarName = "grpc_cfstream";
[self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable code:GRPCErrorCodeUnavailable
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Failed to create call or channel." @"Failed to create call or channel."
}]]; }]];
return; return;
} }
@ -869,10 +870,10 @@ const char *kCFStreamVarName = "grpc_cfstream";
_state = GRXWriterStateStarted; _state = GRXWriterStateStarted;
// Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled). // Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled).
// This makes RPCs in which the call isn't externally retained possible (as long as it is started // This makes RPCs in which the call isn't externally retained possible (as long as it is
// before being autoreleased). // started before being autoreleased). Care is taken not to retain self strongly in any of the
// Care is taken not to retain self strongly in any of the blocks used in this implementation, so // blocks used in this implementation, so that the life of the instance is determined by this
// that the life of the instance is determined by this retain cycle. // retain cycle.
_retainSelf = self; _retainSelf = self;
if (_callOptions == nil) { if (_callOptions == nil) {
@ -961,14 +962,14 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Retain because connectivity manager only keeps weak reference to GRPCCall. // Retain because connectivity manager only keeps weak reference to GRPCCall.
__strong GRPCCall *strongSelf = self; __strong GRPCCall *strongSelf = self;
if (strongSelf) { if (strongSelf) {
@synchronized (strongSelf) { @synchronized(strongSelf) {
[_wrappedCall cancel]; [_wrappedCall cancel];
[strongSelf [strongSelf
finishWithError:[NSError errorWithDomain:kGRPCErrorDomain finishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable code:GRPCErrorCodeUnavailable
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : @"Connectivity lost." NSLocalizedDescriptionKey : @"Connectivity lost."
}]]; }]];
} }
} }
} }

@ -52,7 +52,7 @@
value = [value copy]; value = [value copy];
} }
dispatch_async(_writeQueue, ^(void) { dispatch_async(_writeQueue, ^(void) {
@synchronized (self) { @synchronized(self) {
if (self->_state == GRXWriterStateFinished) { if (self->_state == GRXWriterStateFinished) {
return; return;
} }
@ -106,7 +106,7 @@
} }
- (void)startWithWriteable:(id<GRXWriteable>)writeable { - (void)startWithWriteable:(id<GRXWriteable>)writeable {
@synchronized (self) { @synchronized(self) {
self.writeable = writeable; self.writeable = writeable;
_state = GRXWriterStateStarted; _state = GRXWriterStateStarted;
} }

@ -23,10 +23,10 @@
/** /**
* This is a thread-safe wrapper over a GRXWriteable instance. It lets one enqueue calls to a * This is a thread-safe wrapper over a GRXWriteable instance. It lets one enqueue calls to a
* GRXWriteable instance for the thread user provided, guaranteeing that writesFinishedWithError: is the last * GRXWriteable instance for the thread user provided, guaranteeing that writesFinishedWithError: is
* message sent to it (no matter what messages are sent to the wrapper, in what order, nor from * the last message sent to it (no matter what messages are sent to the wrapper, in what order, nor
* which thread). It also guarantees that, if cancelWithError: is called (e.g. * from which thread). It also guarantees that, if cancelWithError: is called (e.g. by the app
* by the app cancelling the writes), no further messages are sent to the writeable except * cancelling the writes), no further messages are sent to the writeable except
* writesFinishedWithError:. * writesFinishedWithError:.
* *
* TODO(jcanizales): Let the user specify another queue for the writeable callbacks. * TODO(jcanizales): Let the user specify another queue for the writeable callbacks.

@ -63,7 +63,7 @@
- (void)enqueueSuccessfulCompletion { - (void)enqueueSuccessfulCompletion {
dispatch_async(_writeableQueue, ^{ dispatch_async(_writeableQueue, ^{
@synchronized (self) { @synchronized(self) {
if (self->_alreadyFinished) { if (self->_alreadyFinished) {
return; return;
} }
@ -76,7 +76,7 @@
- (void)cancelWithError:(NSError *)error { - (void)cancelWithError:(NSError *)error {
NSAssert(error != nil, @"For a successful completion, use enqueueSuccessfulCompletion."); NSAssert(error != nil, @"For a successful completion, use enqueueSuccessfulCompletion.");
@synchronized (self) { @synchronized(self) {
if (self->_alreadyFinished) { if (self->_alreadyFinished) {
return; return;
} }
@ -91,7 +91,7 @@
- (void)cancelSilently { - (void)cancelSilently {
dispatch_async(_writeableQueue, ^{ dispatch_async(_writeableQueue, ^{
@synchronized (self) { @synchronized(self) {
if (self->_alreadyFinished) { if (self->_alreadyFinished) {
return; return;
} }

@ -57,13 +57,13 @@
#pragma mark GRXWriteable implementation #pragma mark GRXWriteable implementation
- (void)writeValue:(id)value { - (void)writeValue:(id)value {
@synchronized (self) { @synchronized(self) {
[_writeable writeValue:value]; [_writeable writeValue:value];
} }
} }
- (void)writesFinishedWithError:(NSError *)errorOrNil { - (void)writesFinishedWithError:(NSError *)errorOrNil {
@synchronized (self) { @synchronized(self) {
_writer = nil; _writer = nil;
[self finishOutputWithError:errorOrNil]; [self finishOutputWithError:errorOrNil];
} }
@ -78,14 +78,14 @@
- (void)setState:(GRXWriterState)state { - (void)setState:(GRXWriterState)state {
GRXWriter *copiedWriter = nil; GRXWriter *copiedWriter = nil;
if (state == GRXWriterStateFinished) { if (state == GRXWriterStateFinished) {
@synchronized (self) { @synchronized(self) {
_writeable = nil; _writeable = nil;
copiedWriter = _writer; copiedWriter = _writer;
_writer = nil; _writer = nil;
} }
copiedWriter.state = GRXWriterStateFinished; copiedWriter.state = GRXWriterStateFinished;
} else { } else {
@synchronized (self) { @synchronized(self) {
copiedWriter = _writer; copiedWriter = _writer;
} }
copiedWriter.state = state; copiedWriter.state = state;
@ -94,7 +94,7 @@
- (void)startWithWriteable:(id<GRXWriteable>)writeable { - (void)startWithWriteable:(id<GRXWriteable>)writeable {
GRXWriter *copiedWriter = nil; GRXWriter *copiedWriter = nil;
@synchronized (self) { @synchronized(self) {
_writeable = writeable; _writeable = writeable;
copiedWriter = _writer; copiedWriter = _writer;
} }
@ -103,7 +103,7 @@
- (void)finishWithError:(NSError *)errorOrNil { - (void)finishWithError:(NSError *)errorOrNil {
GRXWriter *copiedWriter = nil; GRXWriter *copiedWriter = nil;
@synchronized (self) { @synchronized(self) {
[self finishOutputWithError:errorOrNil]; [self finishOutputWithError:errorOrNil];
copiedWriter = _writer; copiedWriter = _writer;
} }

@ -38,7 +38,7 @@
- (void)startWithWriteable:(id<GRXWriteable>)writeable { - (void)startWithWriteable:(id<GRXWriteable>)writeable {
id copiedValue = nil; id copiedValue = nil;
@synchronized (self) { @synchronized(self) {
if (_state != GRXWriterStateNotStarted) { if (_state != GRXWriterStateNotStarted) {
return; return;
} }
@ -63,7 +63,7 @@
// the original \a map function returns a new Writer of another type. So we // the original \a map function returns a new Writer of another type. So we
// need to override this function here. // need to override this function here.
- (GRXWriter *)map:(id (^)(id))map { - (GRXWriter *)map:(id (^)(id))map {
@synchronized (self) { @synchronized(self) {
// Since _value is available when creating the object, we can simply // Since _value is available when creating the object, we can simply
// apply the map and store the output. // apply the map and store the output.
_value = map(_value); _value = map(_value);

Loading…
Cancel
Save