Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 8337761

Browse files
authored
Merge pull request #343 from justcoding121/develop
Include exception data when listener faield to start
2 parents 5c7f112 + 18dafe5 commit 8337761

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void StartProxy()
8989
proxyServer.AddEndPoint(explicitEndPoint);
9090
proxyServer.Start();
9191

92-
9392
//Transparent endpoint is useful for reverse proxy (client is not aware of the existence of proxy)
9493
//A transparent endpoint usually requires a network router port forwarding HTTP(S) packets or DNS
9594
//to send data to this endPoint

Titanium.Web.Proxy/Models/EndPoint.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ protected ProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl)
2525
Port = port;
2626
EnableSsl = enableSsl;
2727
}
28-
29-
28+
3029
/// <summary>
3130
/// underlying TCP Listener object
3231
/// </summary>
@@ -53,7 +52,6 @@ protected ProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl)
5352
public bool IpV6Enabled => Equals(IpAddress, IPAddress.IPv6Any)
5453
|| Equals(IpAddress, IPAddress.IPv6Loopback)
5554
|| Equals(IpAddress, IPAddress.IPv6None);
56-
5755
}
5856

5957
/// <summary>

Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,22 @@ public void Dispose()
646646
private void Listen(ProxyEndPoint endPoint)
647647
{
648648
endPoint.Listener = new TcpListener(endPoint.IpAddress, endPoint.Port);
649-
endPoint.Listener.Start();
649+
try
650+
{
651+
endPoint.Listener.Start();
650652

651-
endPoint.Port = ((IPEndPoint)endPoint.Listener.LocalEndpoint).Port;
652-
// accept clients asynchronously
653-
endPoint.Listener.BeginAcceptTcpClient(OnAcceptConnection, endPoint);
653+
endPoint.Port = ((IPEndPoint)endPoint.Listener.LocalEndpoint).Port;
654+
655+
// accept clients asynchronously
656+
endPoint.Listener.BeginAcceptTcpClient(OnAcceptConnection, endPoint);
657+
}
658+
catch (SocketException ex)
659+
{
660+
var pex = new Exception($"Endpoint {endPoint} failed to start. Check inner exception and exception data for details.", ex);
661+
pex.Data.Add("ipAddress", endPoint.IpAddress);
662+
pex.Data.Add("port", endPoint.Port);
663+
throw pex;
664+
}
654665
}
655666

656667
/// <summary>

0 commit comments

Comments
 (0)