aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Server.cs
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-26 12:37:53 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-26 12:37:53 -0700
commitdfc42da76011eec3270b3dbcc94748916e0aa5b2 (patch)
tree5e1a69afefaaee7457ed1fa5796d00c06957757e /src/csharp/Grpc.Core/Server.cs
parentb256faa353159c0b6f3477777bed75b4f9de3e16 (diff)
parent5c575dd6e4b01cd68cca5d1917b58023dcf4ca0f (diff)
Merge github.com:grpc/grpc into sometimes-its-good-just-to-check-in-with-each-other
Conflicts: src/core/iomgr/tcp_server_windows.c
Diffstat (limited to 'src/csharp/Grpc.Core/Server.cs')
-rw-r--r--src/csharp/Grpc.Core/Server.cs60
1 files changed, 23 insertions, 37 deletions
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index fd30735359..3217547cc4 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -38,6 +38,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Grpc.Core.Internal;
+using Grpc.Core.Logging;
using Grpc.Core.Utils;
namespace Grpc.Core
@@ -52,6 +53,8 @@ namespace Grpc.Core
/// </summary>
public const int PickUnusedPort = 0;
+ static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<Server>();
+
readonly GrpcEnvironment environment;
readonly List<ChannelOption> options;
readonly ServerSafeHandle handle;
@@ -95,28 +98,31 @@ namespace Grpc.Core
}
/// <summary>
- /// Add a non-secure port on which server should listen.
+ /// Add a port on which server should listen.
/// Only call this before Start().
/// </summary>
/// <returns>The port on which server will be listening.</returns>
/// <param name="host">the host</param>
/// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
- public int AddListeningPort(string host, int port)
+ public int AddPort(string host, int port, ServerCredentials credentials)
{
- return AddListeningPortInternal(host, port, null);
- }
-
- /// <summary>
- /// Add a non-secure port on which server should listen.
- /// Only call this before Start().
- /// </summary>
- /// <returns>The port on which server will be listening.</returns>
- /// <param name="host">the host</param>
- /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
- public int AddListeningPort(string host, int port, ServerCredentials credentials)
- {
- Preconditions.CheckNotNull(credentials);
- return AddListeningPortInternal(host, port, credentials);
+ lock (myLock)
+ {
+ Preconditions.CheckNotNull(credentials);
+ Preconditions.CheckState(!startRequested);
+ var address = string.Format("{0}:{1}", host, port);
+ using (var nativeCredentials = credentials.ToNativeCredentials())
+ {
+ if (nativeCredentials != null)
+ {
+ return handle.AddSecurePort(address, nativeCredentials);
+ }
+ else
+ {
+ return handle.AddInsecurePort(address);
+ }
+ }
+ }
}
/// <summary>
@@ -183,26 +189,6 @@ namespace Grpc.Core
handle.Dispose();
}
- private int AddListeningPortInternal(string host, int port, ServerCredentials credentials)
- {
- lock (myLock)
- {
- Preconditions.CheckState(!startRequested);
- var address = string.Format("{0}:{1}", host, port);
- if (credentials != null)
- {
- using (var nativeCredentials = credentials.ToNativeCredentials())
- {
- return handle.AddListeningPort(address, nativeCredentials);
- }
- }
- else
- {
- return handle.AddListeningPort(address);
- }
- }
- }
-
/// <summary>
/// Allows one new RPC call to be received by server.
/// </summary>
@@ -233,7 +219,7 @@ namespace Grpc.Core
}
catch (Exception e)
{
- Console.WriteLine("Exception while handling RPC: " + e);
+ Logger.Warning(e, "Exception while handling RPC.");
}
}