aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/GrpcCore/Channel.cs
blob: b0d8beeb7bf5e0bbc98cc4feae1a3e2c1fe266ae (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Google.GRPC.Core.Internal;

namespace Google.GRPC.Core
{
	public class Channel : IDisposable
	{
        /// <summary>
        /// Make sure GPRC environment is initialized before any channels get used.
        /// </summary>
        static Channel() {
            GrpcEnvironment.EnsureInitialized();
        }
       
        readonly ChannelSafeHandle handle;
        readonly String target;

        // TODO: add way how to create grpc_secure_channel....
		// TODO: add support for channel args...
		public Channel(string target)
		{
            this.handle = ChannelSafeHandle.Create(target, IntPtr.Zero);
			this.target = target;
		}

        internal ChannelSafeHandle Handle
        {
            get
            {
                return this.handle;
            }
        }

        public string Target
        {
            get
            {
                return this.target;
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (handle != null && !handle.IsInvalid)
            {
                handle.Dispose();
            }
        }
	}
}