Beispiel #1
0
 /// <summary>
 /// Create a new server.
 /// </summary>
 /// <param name="options">Channel options.</param>
 public Server(IEnumerable <ChannelOption> options = null)
 {
     this.environment = GrpcEnvironment.GetInstance();
     using (var channelArgs = ChannelOptions.CreateChannelArgs(options))
     {
         this.handle = ServerSafeHandle.NewServer(environment.CompletionQueue, channelArgs);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Create a new server.
 /// </summary>
 /// <param name="options">Channel options.</param>
 public Server(IEnumerable <ChannelOption> options = null)
 {
     this.serviceDefinitions = new ServiceDefinitionCollection(this);
     this.ports       = new ServerPortCollection(this);
     this.environment = GrpcEnvironment.GetInstance();
     this.options     = options != null ? new List <ChannelOption>(options) : new List <ChannelOption>();
     using (var channelArgs = ChannelOptions.CreateChannelArgs(this.options))
     {
         this.handle = ServerSafeHandle.NewServer(environment.CompletionQueue, channelArgs);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Creates a channel that connects to a specific host.
 /// Port will default to 80 for an unsecure channel and to 443 a secure channel.
 /// </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="options">Channel options.</param>
 public Channel(string host, Credentials credentials = null, IEnumerable <ChannelOption> options = null)
 {
     this.environment = GrpcEnvironment.GetInstance();
     using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(options))
     {
         if (credentials != null)
         {
             using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
             {
                 this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, host, nativeChannelArgs);
             }
         }
         else
         {
             this.handle = ChannelSafeHandle.Create(host, nativeChannelArgs);
         }
     }
     this.target = GetOverridenTarget(host, options);
 }
Beispiel #4
0
        /// <summary>
        /// Creates a channel that connects to a specific host.
        /// Port will default to 80 for an unsecure channel and to 443 for a secure channel.
        /// </summary>
        /// <param name="target">Target of the channel.</param>
        /// <param name="credentials">Credentials to secure the channel.</param>
        /// <param name="options">Channel options.</param>
        public Channel(string target, Credentials credentials, IEnumerable <ChannelOption> options = null)
        {
            this.target      = Preconditions.CheckNotNull(target, "target");
            this.environment = GrpcEnvironment.GetInstance();
            this.options     = options != null ? new List <ChannelOption>(options) : new List <ChannelOption>();

            EnsureUserAgentChannelOption(this.options);
            using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
                using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options))
                {
                    if (nativeCredentials != null)
                    {
                        this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs);
                    }
                    else
                    {
                        this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs);
                    }
                }
        }