diff --git a/FastTunnel.Client/appsettings.json b/FastTunnel.Client/appsettings.json index 4973a79..927a230 100644 --- a/FastTunnel.Client/appsettings.json +++ b/FastTunnel.Client/appsettings.json @@ -38,8 +38,8 @@ "SSH": [ { "LocalIp": "127.0.0.1", - "LocalPort": 22, - "RemotePort": 1273 + "LocalPort": 88, + "RemotePort": 9999 }, { "LocalIp": "192.168.0.91", diff --git a/FastTunnel.Core/AsyncListener.cs b/FastTunnel.Core/AsyncListener.cs index 7c62a66..a0d00ab 100644 --- a/FastTunnel.Core/AsyncListener.cs +++ b/FastTunnel.Core/AsyncListener.cs @@ -42,7 +42,6 @@ namespace FastTunnel.Core listenSocket.Listen(100); - // post accepts on the listening socket StartAccept(null); } @@ -68,16 +67,23 @@ namespace FastTunnel.Core private void ProcessAccept(SocketAsyncEventArgs e) { - Interlocked.Increment(ref m_numConnectedSockets); - Console.WriteLine("Client connection accepted. There are {0} clients connected to the server", - m_numConnectedSockets); + if (e.SocketError == SocketError.Success) + { + var accept = e.AcceptSocket; - var accept = e.AcceptSocket; + Interlocked.Increment(ref m_numConnectedSockets); + _logerr.LogInformation($"【{IP}:{Port}】Accepted. There are {{0}} clients connected to the port", + m_numConnectedSockets); - // Accept the next connection request - StartAccept(e); + // Accept the next connection request + StartAccept(e); - _requestDispatcher.Dispatch(accept); + _requestDispatcher.Dispatch(accept); + } + else + { + ShutdownAndClose(); + } } private void AcceptEventArg_Completed(object sender, SocketAsyncEventArgs e) @@ -97,6 +103,7 @@ namespace FastTunnel.Core finally { listenSocket.Close(); + Interlocked.Decrement(ref m_numConnectedSockets); } } } diff --git a/FastTunnel.Core/AsyncSocketSwap.cs b/FastTunnel.Core/AsyncSocketSwap.cs index 0b12b05..fa89684 100644 --- a/FastTunnel.Core/AsyncSocketSwap.cs +++ b/FastTunnel.Core/AsyncSocketSwap.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net.Sockets; +using System.Runtime.ExceptionServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -52,6 +53,7 @@ namespace FastTunnel.Core catch (Exception ex) { Console.WriteLine(ex.ToString()); + ExceptionDispatchInfo.Capture(ex).Throw(); } }); } diff --git a/FastTunnel.Core/Handlers/Server/LoginMessageHandler.cs b/FastTunnel.Core/Handlers/Server/LoginMessageHandler.cs index 23d3420..54063cb 100644 --- a/FastTunnel.Core/Handlers/Server/LoginMessageHandler.cs +++ b/FastTunnel.Core/Handlers/Server/LoginMessageHandler.cs @@ -87,7 +87,6 @@ namespace FastTunnel.Core.Handlers { // cant use WebDomain _logger.LogDebug($"USE WebDomain IN WWW {www}"); - sb.Append($"{Environment.NewLine} cant use {www}"); } } }