diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2015-08-01 21:34:31 -0700 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2015-08-04 11:30:04 -0700 |
commit | dead905b87c159ce8af7252c17f05cb3e40e7826 (patch) | |
tree | be370b6c18c9aead9289031a9e786caffdc65937 /src/csharp | |
parent | 9c7e46f55c71bb8bd99e07ebebc924a195fc5957 (diff) |
expose Channel.Target property
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ChannelTest.cs | 9 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Channel.cs | 9 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs | 11 | ||||
-rw-r--r-- | src/csharp/ext/grpc_csharp_ext.c | 4 |
4 files changed, 33 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs index bfe001b292..60b45176e5 100644 --- a/src/csharp/Grpc.Core.Tests/ChannelTest.cs +++ b/src/csharp/Grpc.Core.Tests/ChannelTest.cs @@ -72,6 +72,15 @@ namespace Grpc.Core.Tests } [Test] + public void Target() + { + using (var channel = new Channel("127.0.0.1", Credentials.Insecure)) + { + Assert.IsTrue(channel.Target.Contains("127.0.0.1")); + } + } + + [Test] public void Dispose_IsIdempotent() { var channel = new Channel("localhost", Credentials.Insecure); diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index 04fea8c924..0b69610443 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -131,6 +131,15 @@ namespace Grpc.Core return tcs.Task; } + /// <summary> Address of the remote endpoint in URI format.</summary> + public string Target + { + get + { + return handle.GetTarget(); + } + } + /// <summary> /// Allows explicitly requesting channel to connect without starting an RPC. /// Returned task completes once state Ready was seen. If the deadline is reached, diff --git a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs index c017560b56..7324ebdf57 100644 --- a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs @@ -57,6 +57,9 @@ namespace Grpc.Core.Internal 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); private ChannelSafeHandle() @@ -93,6 +96,14 @@ namespace Grpc.Core.Internal grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx); } + public string GetTarget() + { + using (var cstring = grpcsharp_channel_get_target(this)) + { + return cstring.GetValue(); + } + } + protected override bool ReleaseHandle() { grpcsharp_channel_destroy(handle); diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 0e3a83d244..8e2a5f0269 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -394,6 +394,10 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_channel_watch_connectivity_state( deadline, cq, ctx); } +GPR_EXPORT char *GPR_CALLTYPE grpcsharp_channel_get_target(grpc_channel *channel) { + return grpc_channel_get_target(channel); +} + /* Channel args */ GPR_EXPORT grpc_channel_args *GPR_CALLTYPE |