public bool Accept(SocketAsyncEventArgs socketAsyncEvent)
{
if (!_enabled)
{
Logger.WARN("Acceptor is not enabled.");
_droppedCount++;
return true;
}
Logger.INFO("Client connected:{0}:{1} -> {2}:{3}", (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Address.ToString(), (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Port, _ipAddress, _port);
BaseProtocol pProtocol = ProtocolFactoryManager.CreateProtocolChain(_protocolChain, Parameters);
if (pProtocol == null)
{
Logger.FATAL("Unable to create protocol chain");
socketAsyncEvent.AcceptSocket.Close();
return false;
}
var pTcpCarrier = new TCPCarrier(socketAsyncEvent.AcceptSocket)
{
Protocol = pProtocol.FarEndpoint,
ReadEnabled = true
};
pProtocol.FarEndpoint.IOHandler = pTcpCarrier;
//6. Register the protocol stack with an application
if (Application != null)
{
pProtocol = pProtocol.NearEndpoint;
pProtocol.Application = Application;
}
//if (pProtocol.NearEndpoint.OutputBuffer != null)
// pProtocol.NearEndpoint.EnqueueForOutbound();
if (AcceptEnabled)
{
socketAsyncEvent.AcceptSocket = null;
try
{
if (!Socket.AcceptAsync(socketAsyncEvent))
{
OnEvent(socketAsyncEvent);
}
}
catch (Exception ex)
{
Logger.FATAL(ex.Message);
return false;
}
}
else
{
socketAsyncEvent.ReturnPool();
}
_acceptedCount++;
return true;
}