diff options
author | 2017-06-15 17:48:42 -0700 | |
---|---|---|
committer | 2017-06-15 17:48:42 -0700 | |
commit | d5b0455110b834c7fa102a0338882a4f98d31ae8 (patch) | |
tree | dcc9789852f362a5986709587475aee4822cd350 /src/csharp/Grpc.Core/Server.cs | |
parent | fb5ad8d2b9b5fc541a3a85703783fe8e7e4ee91b (diff) | |
parent | 2f850801235580217bb74c5911686bce0374dcad (diff) |
Merge remote-tracking branch 'upstream/v1.4.x' into upmerge_1.4.x
Diffstat (limited to 'src/csharp/Grpc.Core/Server.cs')
-rw-r--r-- | src/csharp/Grpc.Core/Server.cs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs index 462713e6bb..77ad876bdf 100644 --- a/src/csharp/Grpc.Core/Server.cs +++ b/src/csharp/Grpc.Core/Server.cs @@ -19,6 +19,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Grpc.Core.Internal; @@ -140,6 +141,7 @@ namespace Grpc.Core /// <summary> /// Starts the server. + /// Throws <c>IOException</c> if not successful. /// </summary> public void Start() { @@ -148,7 +150,8 @@ namespace Grpc.Core GrpcPreconditions.CheckState(!startRequested); GrpcPreconditions.CheckState(!shutdownRequested); startRequested = true; - + + CheckPortsBoundSuccessfully(); handle.Start(); for (int i = 0; i < requestCallTokensPerCq; i++) @@ -301,6 +304,22 @@ namespace Grpc.Core } } + /// <summary> + /// Checks that all ports have been bound successfully. + /// </summary> + private void CheckPortsBoundSuccessfully() + { + lock (myLock) + { + var unboundPort = ports.FirstOrDefault(port => port.BoundPort == 0); + if (unboundPort != null) + { + throw new IOException( + string.Format("Failed to bind port \"{0}:{1}\"", unboundPort.Host, unboundPort.Port)); + } + } + } + private void DisposeHandle() { var activeCallCount = activeCallCounter.Count; |