From 8c2dd9d864cb874f8fbe577faf8c3f72e6a077e4 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 4 May 2015 09:20:43 -0700 Subject: Fixes for C# cancellation support --- src/csharp/Grpc.Core/Internal/AsyncCallBase.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/csharp/Grpc.Core/Internal/AsyncCallBase.cs') diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs index b911cdcc87..7cf0f6ff84 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs @@ -180,7 +180,8 @@ namespace Grpc.Core.Internal { if (!disposed && call != null) { - if (halfclosed && readingDone && finished) + bool noMoreSendCompletions = halfclosed || (cancelRequested && sendCompletionDelegate == null); + if (noMoreSendCompletions && readingDone && finished) { ReleaseResources(); return true; @@ -207,8 +208,9 @@ namespace Grpc.Core.Internal protected void CheckSendingAllowed() { Preconditions.CheckState(started); - Preconditions.CheckState(!disposed); Preconditions.CheckState(!errorOccured); + CheckNotCancelled(); + Preconditions.CheckState(!disposed); Preconditions.CheckState(!halfcloseRequested, "Already halfclosed."); Preconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time"); @@ -221,7 +223,14 @@ namespace Grpc.Core.Internal Preconditions.CheckState(!errorOccured); Preconditions.CheckState(!readingDone, "Stream has already been closed."); - Preconditions.CheckState(readCompletionDelegate == null, "Only one write can be pending at a time"); + Preconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time"); + } + + protected void CheckNotCancelled() { + if (cancelRequested) + { + throw new OperationCanceledException("Remote call has been cancelled."); + } } protected byte[] UnsafeSerialize(TWrite msg) @@ -292,6 +301,8 @@ namespace Grpc.Core.Internal }); } + + /// /// Handles send completion. /// -- cgit v1.2.3