aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-26 12:55:47 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-26 12:55:47 -0700
commitd9aed1d0103122c235c5577f7a00ead9cbc1a7b9 (patch)
treec28b50ccab7a19287984857daf40d552e50247ab /src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
parent7cb085375581ff2b18865e4e72b335276d08d09d (diff)
parent5c575dd6e4b01cd68cca5d1917b58023dcf4ca0f (diff)
Merge github.com:grpc/grpc into elliptic-orange-chamelion
Conflicts: src/csharp/ext/grpc_csharp_ext.c
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/AsyncCallServer.cs')
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCallServer.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
index f809f4a84c..513902ee36 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
@@ -48,6 +48,7 @@ namespace Grpc.Core.Internal
internal class AsyncCallServer<TRequest, TResponse> : AsyncCallBase<TResponse, TRequest>
{
readonly TaskCompletionSource<object> finishedServersideTcs = new TaskCompletionSource<object>();
+ readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
readonly GrpcEnvironment environment;
public AsyncCallServer(Func<TResponse, byte[]> serializer, Func<byte[], TRequest> deserializer, GrpcEnvironment environment) : base(serializer, deserializer)
@@ -118,6 +119,26 @@ namespace Grpc.Core.Internal
}
}
+ /// <summary>
+ /// Gets cancellation token that gets cancelled once close completion
+ /// is received and the cancelled flag is set.
+ /// </summary>
+ public CancellationToken CancellationToken
+ {
+ get
+ {
+ return cancellationTokenSource.Token;
+ }
+ }
+
+ public string Peer
+ {
+ get
+ {
+ return call.GetPeer();
+ }
+ }
+
protected override void OnReleaseResources()
{
environment.DebugStats.ActiveServerCalls.Decrement();
@@ -138,6 +159,8 @@ namespace Grpc.Core.Internal
{
// Once we cancel, we don't have to care that much
// about reads and writes.
+
+ // TODO(jtattermusch): is this still necessary?
Cancel();
}
@@ -145,6 +168,11 @@ namespace Grpc.Core.Internal
}
// TODO(jtattermusch): handle error
+ if (cancelled)
+ {
+ cancellationTokenSource.Cancel();
+ }
+
finishedServersideTcs.SetResult(null);
}
}