diff options
author | murgatroid99 <mlumish@google.com> | 2016-12-05 12:18:41 -0800 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2016-12-05 12:18:41 -0800 |
commit | f1c85b0e752ecc5894ddd766cdea162defc8b352 (patch) | |
tree | d7c5b3d4b7ce419cea108f63b832eaf060f3b0cb /src/csharp/Grpc.Core/Internal/AsyncCall.cs | |
parent | da29be5ecef07781ef2cfa743300f971df05af76 (diff) | |
parent | 032ca47012f23aecc7c7bf7f1cc9d998145119d9 (diff) |
Merge branch 'master' into node_electron_build
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/AsyncCall.cs')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/AsyncCall.cs | 107 |
1 files changed, 49 insertions, 58 deletions
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs index 5e61e9ec12..1f738a3b6f 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs @@ -106,7 +106,7 @@ namespace Grpc.Core.Internal using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers)) using (var ctx = BatchContextSafeHandle.Create()) { - call.StartUnary(ctx, payload, metadataArray, GetWriteFlagsForCall()); + call.StartUnary(ctx, payload, GetWriteFlagsForCall(), metadataArray, details.Options.Flags); var ev = cq.Pluck(ctx.Handle); @@ -150,7 +150,7 @@ namespace Grpc.Core.Internal unaryResponseTcs = new TaskCompletionSource<TResponse>(); using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers)) { - call.StartUnary(HandleUnaryResponse, payload, metadataArray, GetWriteFlagsForCall()); + call.StartUnary(HandleUnaryResponse, payload, GetWriteFlagsForCall(), metadataArray, details.Options.Flags); } return unaryResponseTcs.Task; } @@ -174,7 +174,7 @@ namespace Grpc.Core.Internal unaryResponseTcs = new TaskCompletionSource<TResponse>(); using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers)) { - call.StartClientStreaming(HandleUnaryResponse, metadataArray); + call.StartClientStreaming(HandleUnaryResponse, metadataArray, details.Options.Flags); } return unaryResponseTcs.Task; @@ -200,7 +200,7 @@ namespace Grpc.Core.Internal streamingResponseCallFinishedTcs = new TaskCompletionSource<object>(); using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers)) { - call.StartServerStreaming(HandleFinished, payload, metadataArray, GetWriteFlagsForCall()); + call.StartServerStreaming(HandleFinished, payload, GetWriteFlagsForCall(), metadataArray, details.Options.Flags); } call.StartReceiveInitialMetadata(HandleReceivedResponseHeaders); } @@ -222,7 +222,7 @@ namespace Grpc.Core.Internal streamingResponseCallFinishedTcs = new TaskCompletionSource<object>(); using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers)) { - call.StartDuplexStreaming(HandleFinished, metadataArray); + call.StartDuplexStreaming(HandleFinished, metadataArray, details.Options.Flags); } call.StartReceiveInitialMetadata(HandleReceivedResponseHeaders); } @@ -388,35 +388,29 @@ namespace Grpc.Core.Internal private void Initialize(CompletionQueueSafeHandle cq) { - using (Profilers.ForCurrentThread().NewScope("AsyncCall.Initialize")) - { - var call = CreateNativeCall(cq); + var call = CreateNativeCall(cq); - details.Channel.AddCallReference(this); - InitializeInternal(call); - RegisterCancellationCallback(); - } + details.Channel.AddCallReference(this); + InitializeInternal(call); + RegisterCancellationCallback(); } private INativeCall CreateNativeCall(CompletionQueueSafeHandle cq) { - using (Profilers.ForCurrentThread().NewScope("AsyncCall.CreateNativeCall")) - { - if (injectedNativeCall != null) - { - return injectedNativeCall; // allows injecting a mock INativeCall in tests. - } + if (injectedNativeCall != null) + { + return injectedNativeCall; // allows injecting a mock INativeCall in tests. + } - var parentCall = details.Options.PropagationToken != null ? details.Options.PropagationToken.ParentCall : CallSafeHandle.NullInstance; + var parentCall = details.Options.PropagationToken != null ? details.Options.PropagationToken.ParentCall : CallSafeHandle.NullInstance; - var credentials = details.Options.Credentials; - using (var nativeCredentials = credentials != null ? credentials.ToNativeCredentials() : null) - { - var result = details.Channel.Handle.CreateCall( - parentCall, ContextPropagationToken.DefaultMask, cq, - details.Method, details.Host, Timespec.FromDateTime(details.Options.Deadline.Value), nativeCredentials); - return result; - } + var credentials = details.Options.Credentials; + using (var nativeCredentials = credentials != null ? credentials.ToNativeCredentials() : null) + { + var result = details.Channel.Handle.CreateCall( + parentCall, ContextPropagationToken.DefaultMask, cq, + details.Method, details.Host, Timespec.FromDateTime(details.Options.Deadline.Value), nativeCredentials); + return result; } } @@ -456,47 +450,44 @@ namespace Grpc.Core.Internal // NOTE: because this event is a result of batch containing GRPC_OP_RECV_STATUS_ON_CLIENT, // success will be always set to true. - using (Profilers.ForCurrentThread().NewScope("AsyncCall.HandleUnaryResponse")) + TaskCompletionSource<object> delayedStreamingWriteTcs = null; + TResponse msg = default(TResponse); + var deserializeException = TryDeserialize(receivedMessage, out msg); + + lock (myLock) { - TaskCompletionSource<object> delayedStreamingWriteTcs = null; - TResponse msg = default(TResponse); - var deserializeException = TryDeserialize(receivedMessage, out msg); + finished = true; - lock (myLock) + if (deserializeException != null && receivedStatus.Status.StatusCode == StatusCode.OK) { - finished = true; - - if (deserializeException != null && receivedStatus.Status.StatusCode == StatusCode.OK) - { - receivedStatus = new ClientSideStatus(DeserializeResponseFailureStatus, receivedStatus.Trailers); - } - finishedStatus = receivedStatus; - - if (isStreamingWriteCompletionDelayed) - { - delayedStreamingWriteTcs = streamingWriteTcs; - streamingWriteTcs = null; - } - - ReleaseResourcesIfPossible(); + receivedStatus = new ClientSideStatus(DeserializeResponseFailureStatus, receivedStatus.Trailers); } + finishedStatus = receivedStatus; - responseHeadersTcs.SetResult(responseHeaders); - - if (delayedStreamingWriteTcs != null) + if (isStreamingWriteCompletionDelayed) { - delayedStreamingWriteTcs.SetException(GetRpcExceptionClientOnly()); + delayedStreamingWriteTcs = streamingWriteTcs; + streamingWriteTcs = null; } - var status = receivedStatus.Status; - if (status.StatusCode != StatusCode.OK) - { - unaryResponseTcs.SetException(new RpcException(status)); - return; - } + ReleaseResourcesIfPossible(); + } + + responseHeadersTcs.SetResult(responseHeaders); - unaryResponseTcs.SetResult(msg); + if (delayedStreamingWriteTcs != null) + { + delayedStreamingWriteTcs.SetException(GetRpcExceptionClientOnly()); + } + + var status = receivedStatus.Status; + if (status.StatusCode != StatusCode.OK) + { + unaryResponseTcs.SetException(new RpcException(status)); + return; } + + unaryResponseTcs.SetResult(msg); } /// <summary> |