aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2017-05-26 14:19:23 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2017-06-01 00:13:09 +0200
commit9d56717be4fa5d0c05e42bb1137b30ef121960d8 (patch)
tree605b40d2ee67c56ef87e3d063912503cac9b8103 /src/csharp/Grpc.Core
parent5cae37ab5e0232bb48c0427168ccd6c9d069f6e0 (diff)
throw if server started with unbound ports
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r--src/csharp/Grpc.Core/Server.cs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index 63c1d9cd00..7ba204a0b6 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -34,6 +34,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core.Internal;
@@ -155,6 +156,7 @@ namespace Grpc.Core
/// <summary>
/// Starts the server.
+ /// Throws <c>IOException</c> if not successful.
/// </summary>
public void Start()
{
@@ -163,7 +165,8 @@ namespace Grpc.Core
GrpcPreconditions.CheckState(!startRequested);
GrpcPreconditions.CheckState(!shutdownRequested);
startRequested = true;
-
+
+ CheckPortsBoundSuccessfully();
handle.Start();
for (int i = 0; i < requestCallTokensPerCq; i++)
@@ -316,6 +319,20 @@ namespace Grpc.Core
}
}
+ /// <summary>
+ /// Checks that all ports have been bound successfully.
+ /// </summary>
+ private void CheckPortsBoundSuccessfully()
+ {
+ lock (myLock)
+ {
+ if (!ports.All((port) => port.BoundPort != 0))
+ {
+ throw new IOException("Failed to bind some of ports exposed by the server.");
+ }
+ }
+ }
+
private void DisposeHandle()
{
var activeCallCount = activeCallCounter.Count;