public EndSend ( IAsyncResult asyncResult ) : int | ||
asyncResult | IAsyncResult | The result of the asynchronous operation. |
return | int |
public override int EndSend(IAsyncResult asyncResult) {
if (SecureProtocol == SecureProtocol.None)
return base.EndSend(asyncResult);
if (asyncResult == null)
throw new ArgumentNullException();
TransferItem ti = m_Controller.EndSend(asyncResult);
if (ti == null)
throw new ArgumentException();
while (!ti.AsyncResult.IsCompleted) {
ti.AsyncResult.AsyncWaitHandle.WaitOne(200, false);
}
if (ti.AsyncResult.AsyncException != null)
throw new SecurityException("An error occurs while communicating with the remote host.", ti.AsyncResult.AsyncException);
return ti.OriginalSize;
}
/// <summary>
/// <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); } }