aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-05-04 09:20:43 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-05-04 14:56:51 -0700
commit8c2dd9d864cb874f8fbe577faf8c3f72e6a077e4 (patch)
treefc4141f5561aa05f2d0bcce70f9f98296731a1b4 /src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
parent1b54fcf31b32ae8c7f07ae733e781c184791a7c2 (diff)
Fixes for C# cancellation support
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/AsyncCallBase.cs')
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCallBase.cs17
1 files changed, 14 insertions, 3 deletions
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
});
}
+
+
/// <summary>
/// Handles send completion.
/// </summary>