diff options
Diffstat (limited to 'src/csharp/GrpcCore/Channel.cs')
-rw-r--r-- | src/csharp/GrpcCore/Channel.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/csharp/GrpcCore/Channel.cs b/src/csharp/GrpcCore/Channel.cs new file mode 100644 index 0000000000..b0d8beeb7b --- /dev/null +++ b/src/csharp/GrpcCore/Channel.cs @@ -0,0 +1,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(); + } + } + } +}
\ No newline at end of file |