Skip to content
Snippets Groups Projects
Commit dead905b authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

expose Channel.Target property

parent 9c7e46f5
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,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()
{
......
......@@ -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,
......
......@@ -56,6 +56,9 @@ namespace Grpc.Core.Internal
static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState,
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);
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment