diff options
Diffstat (limited to 'src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs')
-rw-r--r-- | src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs b/src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs new file mode 100644 index 0000000000..3a09d8b1b6 --- /dev/null +++ b/src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Google.GRPC.Core.Internal +{ + /// <summary> + /// grpc_channel from <grpc/grpc.h> + /// </summary> + internal class ChannelSafeHandle : SafeHandleZeroIsInvalid + { + [DllImport("libgrpc.so")] + static extern ChannelSafeHandle grpc_channel_create(string target, IntPtr channelArgs); + + [DllImport("libgrpc.so")] + static extern void grpc_channel_destroy(IntPtr channel); + + private ChannelSafeHandle() + { + } + + public static ChannelSafeHandle Create(string target, IntPtr channelArgs) + { + return grpc_channel_create(target, channelArgs); + } + + protected override bool ReleaseHandle() + { + grpc_channel_destroy(handle); + return true; + } + } +}
\ No newline at end of file |