aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2016-06-01 12:47:46 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2016-06-06 15:04:03 -0700
commit63386a1064f9b27b0590c1e10f7176a45b0a3f36 (patch)
treec4ef1acde2d0ffbdc77a54a08f62b96b92fdc093
parent4aea5281de1fb5686ae5bb6305e51b704ac57317 (diff)
deduplicate server shutdown logic
-rw-r--r--src/csharp/Grpc.Core/Server.cs57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index 18a808e604..88045a51c8 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -155,21 +155,9 @@ namespace Grpc.Core
/// <remarks>
/// It is strongly recommended to shutdown all previously created servers before exiting from the process.
/// </remarks>
- public async Task ShutdownAsync()
+ public Task ShutdownAsync()
{
- lock (myLock)
- {
- GrpcPreconditions.CheckState(startRequested);
- GrpcPreconditions.CheckState(!shutdownRequested);
- shutdownRequested = true;
- }
-
- var cq = environment.CompletionQueues.First(); // any cq will do
- handle.ShutdownAndNotify(HandleServerShutdown, cq);
- await shutdownTcs.Task.ConfigureAwait(false);
- DisposeHandle();
-
- await GrpcEnvironment.ReleaseAsync().ConfigureAwait(false);
+ return ShutdownInternalAsync(false);
}
/// <summary>
@@ -179,22 +167,9 @@ namespace Grpc.Core
/// <remarks>
/// It is strongly recommended to shutdown all previously created servers before exiting from the process.
/// </remarks>
- public async Task KillAsync()
+ public Task KillAsync()
{
- lock (myLock)
- {
- GrpcPreconditions.CheckState(startRequested);
- GrpcPreconditions.CheckState(!shutdownRequested);
- shutdownRequested = true;
- }
-
- var cq = environment.CompletionQueues.First(); // any cq will do
- handle.ShutdownAndNotify(HandleServerShutdown, cq);
- handle.CancelAllCalls();
- await shutdownTcs.Task.ConfigureAwait(false);
- DisposeHandle();
-
- await GrpcEnvironment.ReleaseAsync().ConfigureAwait(false);
+ return ShutdownInternalAsync(true);
}
internal void AddCallReference(object call)
@@ -213,6 +188,30 @@ namespace Grpc.Core
}
/// <summary>
+ /// Shuts down the server.
+ /// </summary>
+ private async Task ShutdownInternalAsync(bool kill)
+ {
+ lock (myLock)
+ {
+ GrpcPreconditions.CheckState(startRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
+ shutdownRequested = true;
+ }
+
+ var cq = environment.CompletionQueues.First(); // any cq will do
+ handle.ShutdownAndNotify(HandleServerShutdown, cq);
+ if (kill)
+ {
+ handle.CancelAllCalls();
+ }
+ await shutdownTcs.Task.ConfigureAwait(false);
+ DisposeHandle();
+
+ await GrpcEnvironment.ReleaseAsync().ConfigureAwait(false);
+ }
+
+ /// <summary>
/// Adds a service definition.
/// </summary>
private void AddServiceDefinitionInternal(ServerServiceDefinition serviceDefinition)