aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/GrpcCore/Internal/ChannelSafeHandle.cs
blob: 6436f2bb310ab820c83ca621b85a1d2227896c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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("grpc_csharp_ext.dll")]
        static extern ChannelSafeHandle grpcsharp_channel_create(string target, IntPtr channelArgs);

		[DllImport("grpc_csharp_ext.dll")]
		static extern void grpcsharp_channel_destroy(IntPtr channel);

        private ChannelSafeHandle()
        {
        }

        public static ChannelSafeHandle Create(string target, IntPtr channelArgs)
        {
            return grpcsharp_channel_create(target, channelArgs);
        }

		protected override bool ReleaseHandle()
		{
			grpcsharp_channel_destroy(handle);
			return true;
		}
	}
}