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

EndReceive() public method

Ends a pending asynchronous read.
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 socket. The has been closed. An error occurs while communicating with the remote host.
public EndReceive ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult Stores state information for this asynchronous operation as well as any user defined data.
return int
		public override int EndReceive(IAsyncResult asyncResult) {
			if (SecureProtocol == SecureProtocol.None)
				return base.EndReceive(asyncResult);
			// Make sure everything is in order
			if (asyncResult == null)
				throw new ArgumentNullException();
			TransferItem ti = m_Controller.EndReceive(asyncResult);
			if (ti == null)
				throw new ArgumentException();
			// Process the (secure) EndReceive
			// block if the operation hasn't ended yet
            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.\r\n" + ti.AsyncResult.AsyncException.ToString(), ti.AsyncResult.AsyncException);
			if (ti.Transferred == 0)
				m_SentShutdownNotification = true;
			return ti.Transferred;
		}
		/// <summary>

Usage Example

 /// <summary>
 /// Handles the end of an asynchronous read.
 /// </summary>
 /// <param name="asyncResult">An <see cref="IAsyncResult"/> representing an asynchronous call. </param>
 /// <returns>The number of bytes read from the stream.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="asyncResult"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
 /// <exception cref="IOException">There is a failure while reading from the network.</exception>
 public override int EndRead(IAsyncResult asyncResult)
 {
     if (asyncResult == null)
     {
         throw new ArgumentNullException();
     }
     if (Socket == null)
     {
         throw new IOException();
     }
     try {
         return(Socket.EndReceive(asyncResult));
     } catch (Exception e) {
         throw new IOException("An I/O exception occurred.", e);
     }
 }