diff options
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs index 4a5584121e..1dbd1f4e34 100644 --- a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs @@ -41,27 +41,7 @@ namespace Grpc.Core.Internal /// </summary> internal class ChannelSafeHandle : SafeHandleZeroIsInvalid { - [DllImport("grpc_csharp_ext.dll")] - static extern ChannelSafeHandle grpcsharp_insecure_channel_create(string target, ChannelArgsSafeHandle channelArgs); - - [DllImport("grpc_csharp_ext.dll")] - static extern ChannelSafeHandle grpcsharp_secure_channel_create(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs); - - [DllImport("grpc_csharp_ext.dll")] - static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline); - - [DllImport("grpc_csharp_ext.dll")] - static extern ChannelState grpcsharp_channel_check_connectivity_state(ChannelSafeHandle channel, int tryToConnect); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, - Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); - - [DllImport("grpc_csharp_ext.dll")] - static extern CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call); - - [DllImport("grpc_csharp_ext.dll")] - static extern void grpcsharp_channel_destroy(IntPtr channel); + static readonly NativeMethods Native = NativeMethods.Get(); private ChannelSafeHandle() { @@ -72,7 +52,7 @@ 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_insecure_channel_create(target, channelArgs); + return Native.grpcsharp_insecure_channel_create(target, channelArgs); } public static ChannelSafeHandle CreateSecure(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs) @@ -80,14 +60,14 @@ 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_secure_channel_create(credentials, target, channelArgs); + return Native.grpcsharp_secure_channel_create(credentials, target, channelArgs); } public CallSafeHandle CreateCall(CompletionRegistry registry, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline, CallCredentialsSafeHandle credentials) { using (Profilers.ForCurrentThread().NewScope("ChannelSafeHandle.CreateCall")) { - var result = grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline); + var result = Native.grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline); if (credentials != null) { result.SetCredentials(credentials); @@ -99,7 +79,7 @@ namespace Grpc.Core.Internal public ChannelState CheckConnectivityState(bool tryToConnect) { - return grpcsharp_channel_check_connectivity_state(this, tryToConnect ? 1 : 0); + return Native.grpcsharp_channel_check_connectivity_state(this, tryToConnect ? 1 : 0); } public void WatchConnectivityState(ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, @@ -107,12 +87,12 @@ namespace Grpc.Core.Internal { var ctx = BatchContextSafeHandle.Create(); completionRegistry.RegisterBatchCompletion(ctx, callback); - grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx); + Native.grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx); } public string GetTarget() { - using (var cstring = grpcsharp_channel_get_target(this)) + using (var cstring = Native.grpcsharp_channel_get_target(this)) { return cstring.GetValue(); } @@ -120,7 +100,7 @@ namespace Grpc.Core.Internal protected override bool ReleaseHandle() { - grpcsharp_channel_destroy(handle); + Native.grpcsharp_channel_destroy(handle); GrpcEnvironment.GrpcNativeShutdown(); return true; } |