/// <summary>
/// Called when the bytes have been sent to the remote server
/// </summary>
/// <param name="asyncResult">The <see cref="IAsyncResult"/> representing the asynchronous call.</param>
private void OnBytesSent(IAsyncResult asyncResult)
{
try {
int sent = Socket.EndSend(asyncResult);
sent += (int)asyncResult.AsyncState;
if (sent == WriteResult.Buffer.Length)
{
OnWriteComplete(null);
}
else
{
Socket.BeginSend(WriteResult.Buffer, sent, WriteResult.Buffer.Length - sent, SocketFlags.None, new AsyncCallback(OnBytesSent), sent);
}
} catch (Exception e) {
OnWriteComplete(e);
}
}