aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Channel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Core/Channel.cs')
-rw-r--r--src/csharp/Grpc.Core/Channel.cs40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs
index 44b610f65b..d6bfbb7bc4 100644
--- a/src/csharp/Grpc.Core/Channel.cs
+++ b/src/csharp/Grpc.Core/Channel.cs
@@ -29,6 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
+using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -50,10 +51,10 @@ namespace Grpc.Core
/// </summary>
/// <param name="host">The DNS name of IP address of the host.</param>
/// <param name="credentials">Optional credentials to create a secure channel.</param>
- /// <param name="channelArgs">Optional channel arguments.</param>
- public Channel(string host, Credentials credentials = null, ChannelArgs channelArgs = null)
+ /// <param name="options">Channel options.</param>
+ public Channel(string host, Credentials credentials = null, IEnumerable<ChannelOption> options = null)
{
- using (ChannelArgsSafeHandle nativeChannelArgs = CreateNativeChannelArgs(channelArgs))
+ using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(options))
{
if (credentials != null)
{
@@ -67,7 +68,7 @@ namespace Grpc.Core
this.handle = ChannelSafeHandle.Create(host, nativeChannelArgs);
}
}
- this.target = GetOverridenTarget(host, channelArgs);
+ this.target = GetOverridenTarget(host, options);
}
/// <summary>
@@ -76,9 +77,9 @@ namespace Grpc.Core
/// <param name="host">DNS name or IP address</param>
/// <param name="port">the port</param>
/// <param name="credentials">Optional credentials to create a secure channel.</param>
- /// <param name="channelArgs">Optional channel arguments.</param>
- public Channel(string host, int port, Credentials credentials = null, ChannelArgs channelArgs = null) :
- this(string.Format("{0}:{1}", host, port), credentials, channelArgs)
+ /// <param name="options">Channel options.</param>
+ public Channel(string host, int port, Credentials credentials = null, IEnumerable<ChannelOption> options = null) :
+ this(string.Format("{0}:{1}", host, port), credentials, options)
{
}
@@ -112,22 +113,25 @@ namespace Grpc.Core
}
}
- private static string GetOverridenTarget(string target, ChannelArgs args)
+ /// <summary>
+ /// Look for SslTargetNameOverride option and return its value instead of originalTarget
+ /// if found.
+ /// </summary>
+ private static string GetOverridenTarget(string originalTarget, IEnumerable<ChannelOption> options)
{
- if (args != null && !string.IsNullOrEmpty(args.GetSslTargetNameOverride()))
+ if (options == null)
{
- return args.GetSslTargetNameOverride();
+ return originalTarget;
}
- return target;
- }
-
- private static ChannelArgsSafeHandle CreateNativeChannelArgs(ChannelArgs args)
- {
- if (args == null)
+ foreach (var option in options)
{
- return ChannelArgsSafeHandle.CreateNull();
+ if (option.Type == ChannelOption.OptionType.String
+ && option.Name == ChannelOptions.SslTargetNameOverride)
+ {
+ return option.StringValue;
+ }
}
- return args.ToNativeChannelArgs();
+ return originalTarget;
}
}
}