private void SocketEvent_Receive(IAsyncResult ar)
{
EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
try
{
lock (this)
{
var socket = _socket;
int transBytes = socket?.EndReceiveFrom(ar, ref remoteEP) ?? -1;
if (transBytes == -1)
return;
EventRead?.Invoke(new IOEventResult(remoteEP, IOEventType.Read, _receivedBuffer, 0, transBytes, 0));
WaitForReceive();
}
}
catch (SocketException)
{
EventClose?.Invoke(new IOEventResult(remoteEP, IOEventType.Close, AegisResult.ClosedByRemote));
WaitForReceive();
}
catch (Exception e)
{
if (ExceptionRaised == null)
Logger.Err(LogMask.Aegis, e.ToString());
else
ExceptionRaised.Invoke(e);
}
}