fix NullReferenceException

This commit is contained in:
ioxygen 2021-07-29 14:40:47 +08:00
parent bd27741d05
commit b701438617

View File

@ -146,10 +146,20 @@ namespace FastTunnel.Core.Server
{
Interlocked.Increment(ref m_numConnectedSockets);
_logger.LogInformation($"[当前连接数]:{_localEndPoint.Port} | {m_numConnectedSockets}");
_logger.LogDebug($"leftPool: {m_readWritePool.Count}");
try
{
// Get the socket for the accepted client connection and put it into the
// ReadEventArg object user token
SocketAsyncEventArgs readEventArgs = m_readWritePool.Pop();
if (readEventArgs == null)
{
_logger.LogCritical($"Pop result is Null {m_readWritePool.Count}");
release(e);
return;
}
var token = readEventArgs.UserToken as AsyncUserToken;
token.Socket = e.AcceptSocket;
token.MassgeTemp = null;
@ -172,6 +182,12 @@ namespace FastTunnel.Core.Server
// Accept the next connection request
StartAccept(e);
}
catch (Exception ex)
{
_logger.LogCritical(ex, "[ProcessAccept error]");
release(e);
}
}
// This method is called whenever a receive or send operation is completed on a socket
//
@ -318,6 +334,8 @@ namespace FastTunnel.Core.Server
m_readWritePool.Push(e);
m_maxNumberAcceptedClients.Release();
_logger.LogDebug($"release ok");
}
}
}