mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-30 06:12:18 +02:00
Revert PortUtil.cs changes (#147)
This commit is contained in:
@@ -9,7 +9,6 @@ namespace WireMock.Http
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class PortUtil
|
public static class PortUtil
|
||||||
{
|
{
|
||||||
private static readonly IPEndPoint DefaultLoopbackEndpoint = new IPEndPoint(IPAddress.Loopback, port: 0);
|
|
||||||
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)?/", RegexOptions.Compiled);
|
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)?/", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -18,10 +17,17 @@ namespace WireMock.Http
|
|||||||
/// <remarks>see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net.</remarks>
|
/// <remarks>see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net.</remarks>
|
||||||
public static int FindFreeTcpPort()
|
public static int FindFreeTcpPort()
|
||||||
{
|
{
|
||||||
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
TcpListener tcpListener = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
socket.Bind(DefaultLoopbackEndpoint);
|
tcpListener = new TcpListener(IPAddress.Loopback, 0);
|
||||||
return ((IPEndPoint)socket.LocalEndPoint).Port;
|
tcpListener.Start();
|
||||||
|
|
||||||
|
return ((IPEndPoint)tcpListener.LocalEndpoint).Port;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
tcpListener?.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user