|
|
|
@ -98,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> |
|
|
|
@ -186,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> |
|
|
|
|