Org.Mentalis.Security.Ssl.SecureSocket.EndSend C# (CSharp) Method

EndSend() public method

Ends a pending asynchronous send.
is a null reference (Nothing in Visual Basic). was not returned by a call to the method. was previously called for the asynchronous read. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurs while communicating with the remote host.
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>

Usage Example

 /// <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);
     }
 }