diff options
author | Craig Tiller <ctiller@google.com> | 2015-06-01 08:47:28 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-06-01 08:47:28 -0700 |
commit | 6852744580024cd875f2c8f0f4e1000c8e7ac433 (patch) | |
tree | 19f3d79fa05b8879afafa7bbf45492e5a4ba15ef /src/csharp/Grpc.Core | |
parent | 9349c0a104337d7ebca3a9881d33312c7b65fb88 (diff) | |
parent | c590f213c7a7d0b9b1692826050152130fa5709f (diff) |
Merge branch 'you-complete-me' into we-dont-need-no-backup
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs | 19 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Server.cs | 18 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs index 7a1c016ae2..c44ee87bad 100644 --- a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs @@ -60,10 +60,10 @@ namespace Grpc.Core.Internal static extern void grpcsharp_server_start(ServerSafeHandle server); [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_shutdown(ServerSafeHandle server); + static extern void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, [MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback); [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, [MarshalAs(UnmanagedType.FunctionPtr)] CompletionCallbackDelegate callback); + static extern void grpcsharp_server_cancel_all_calls(ServerSafeHandle server); [DllImport("grpc_csharp_ext.dll")] static extern void grpcsharp_server_destroy(IntPtr server); @@ -92,14 +92,9 @@ namespace Grpc.Core.Internal grpcsharp_server_start(this); } - public void Shutdown() + public void ShutdownAndNotify(CompletionQueueSafeHandle cq, CompletionCallbackDelegate callback) { - grpcsharp_server_shutdown(this); - } - - public void ShutdownAndNotify(CompletionCallbackDelegate callback) - { - grpcsharp_server_shutdown_and_notify_callback(this, callback); + grpcsharp_server_shutdown_and_notify_callback(this, cq, callback); } public void RequestCall(CompletionQueueSafeHandle cq, CompletionCallbackDelegate callback) @@ -112,6 +107,12 @@ namespace Grpc.Core.Internal grpcsharp_server_destroy(handle); return true; } + + // Only to be called after ShutdownAndNotify. + public void CancelAllCalls() + { + grpcsharp_server_cancel_all_calls(this); + } private static void AssertCallOk(GRPCCallError callError) { diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs index 4a7abbb33f..0f4d77eaf3 100644 --- a/src/csharp/Grpc.Core/Server.cs +++ b/src/csharp/Grpc.Core/Server.cs @@ -144,7 +144,7 @@ namespace Grpc.Core shutdownRequested = true; } - handle.ShutdownAndNotify(serverShutdownHandler); + handle.ShutdownAndNotify(GetCompletionQueue(), serverShutdownHandler); await shutdownTcs.Task; handle.Dispose(); } @@ -160,8 +160,22 @@ namespace Grpc.Core } } - public void Kill() + /// <summary> + /// Requests server shutdown while cancelling all the in-progress calls. + /// The returned task finishes when shutdown procedure is complete. + /// </summary> + public async Task KillAsync() { + lock (myLock) + { + Preconditions.CheckState(startRequested); + Preconditions.CheckState(!shutdownRequested); + shutdownRequested = true; + } + + handle.ShutdownAndNotify(GetCompletionQueue(), serverShutdownHandler); + handle.CancelAllCalls(); + await shutdownTcs.Task; handle.Dispose(); } |