public void SendPacket(StreamBuffer buffer, PacketPredicate predicate, IOEventHandler dispatcher, Action <StreamBuffer> onSent = null)
{
if (predicate == null || dispatcher == null)
{
throw new AegisException(AegisResult.InvalidArgument, "The argument predicate and dispatcher cannot be null.");
}
try
{
lock (_session)
{
if (_session.Socket == null)
{
return;
}
// ReadIndex가 OnSocket_Send에서 사용되므로 ReadIndex를 초기화해야 한다.
buffer.ResetReadIndex();
SocketAsyncEventArgs saea = new SocketAsyncEventArgs();
saea.Completed += SendComplete;
saea.SetBuffer(buffer.Buffer, 0, buffer.WrittenBytes);
if (onSent != null)
{
saea.UserToken = new NetworkSendToken(buffer, onSent);
}
_responseSelector.Add(predicate, dispatcher);
if (_session.Socket.SendAsync(saea) == false)
{
ReceiveComplete(null, saea);
}
}
}
catch (SocketException)
{
}
catch (Exception e)
{
Logger.Err(LogMask.Aegis, e.ToString());
}
}