-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalOnlyIPCTransportHelper.cs
47 lines (40 loc) · 1.35 KB
/
LocalOnlyIPCTransportHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Akka.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Akka.Remote.LocalOnlyIPC;
public static class LocalOnlyIPCTransportHelper
{
public const int HighestWellKnownConnectionNumber = 32768;
public const int HighestAllowedConnectionNumber = 65536;
public static AkkaConfigurationBuilder WithLocalOnlyIPCRemoting(
this AkkaConfigurationBuilder builder,
LocalOnlyRemotingOptions options)
{
options.Build(builder);
return builder;
}
internal static int GetFreeRandomPortForSchemeId(
int lowerBoundNr,
int upperBoundNr,
string schemeIdentifier,
Func<string, int, bool> portIsUsable)
{
Random randomPortGenerator = new Random();
List<int> availablePorts = Enumerable
.Range(lowerBoundNr, upperBoundNr - lowerBoundNr)
.ToList();
int port;
do
{
if (availablePorts.Count == 0)
{
throw new Exception($"No more free ports available for transport {schemeIdentifier}");
}
port = randomPortGenerator.Next(lowerBoundNr, upperBoundNr);
availablePorts.Remove(port);
}
while (portIsUsable(schemeIdentifier, port) == false);
return port;
}
}