diff options
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs index 5ee7ac14e8..a57fb3b789 100644 --- a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs @@ -1,6 +1,6 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -44,29 +44,7 @@ namespace Grpc.Core.Internal /// </summary> internal sealed class ServerSafeHandle : SafeHandleZeroIsInvalid { - [DllImport("grpc_csharp_ext.dll")] - static extern ServerSafeHandle grpcsharp_server_create(CompletionQueueSafeHandle cq, ChannelArgsSafeHandle args); - - [DllImport("grpc_csharp_ext.dll")] - static extern int grpcsharp_server_add_insecure_http2_port(ServerSafeHandle server, string addr); - - [DllImport("grpc_csharp_ext.dll")] - static extern int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_start(ServerSafeHandle server); - - [DllImport("grpc_csharp_ext.dll")] - static extern GRPCCallError grpcsharp_server_request_call(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_cancel_all_calls(ServerSafeHandle server); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_server_destroy(IntPtr server); + static readonly NativeMethods Native = NativeMethods.Get(); private ServerSafeHandle() { @@ -77,41 +55,41 @@ namespace Grpc.Core.Internal // Increment reference count for the native gRPC environment to make sure we don't do grpc_shutdown() before destroying the server handle. // Doing so would make object finalizer crash if we end up abandoning the handle. GrpcEnvironment.GrpcNativeInit(); - return grpcsharp_server_create(cq, args); + return Native.grpcsharp_server_create(cq, args); } public int AddInsecurePort(string addr) { - return grpcsharp_server_add_insecure_http2_port(this, addr); + return Native.grpcsharp_server_add_insecure_http2_port(this, addr); } public int AddSecurePort(string addr, ServerCredentialsSafeHandle credentials) { - return grpcsharp_server_add_secure_http2_port(this, addr, credentials); + return Native.grpcsharp_server_add_secure_http2_port(this, addr, credentials); } public void Start() { - grpcsharp_server_start(this); + Native.grpcsharp_server_start(this); } public void ShutdownAndNotify(BatchCompletionDelegate callback, GrpcEnvironment environment) { var ctx = BatchContextSafeHandle.Create(); environment.CompletionRegistry.RegisterBatchCompletion(ctx, callback); - grpcsharp_server_shutdown_and_notify_callback(this, environment.CompletionQueue, ctx); + Native.grpcsharp_server_shutdown_and_notify_callback(this, environment.CompletionQueue, ctx); } public void RequestCall(BatchCompletionDelegate callback, GrpcEnvironment environment) { var ctx = BatchContextSafeHandle.Create(); environment.CompletionRegistry.RegisterBatchCompletion(ctx, callback); - grpcsharp_server_request_call(this, environment.CompletionQueue, ctx).CheckOk(); + Native.grpcsharp_server_request_call(this, environment.CompletionQueue, ctx).CheckOk(); } protected override bool ReleaseHandle() { - grpcsharp_server_destroy(handle); + Native.grpcsharp_server_destroy(handle); GrpcEnvironment.GrpcNativeShutdown(); return true; } @@ -119,7 +97,7 @@ namespace Grpc.Core.Internal // Only to be called after ShutdownAndNotify. public void CancelAllCalls() { - grpcsharp_server_cancel_all_calls(this); + Native.grpcsharp_server_cancel_all_calls(this); } } } |