Example #1
0
        /// <summary>
        /// Ends an asynchronous request to create a new <see cref="SecureSocket"/> to accept an incoming connection request.
        /// </summary>
        /// <param name="asyncResult">Stores state information for this asynchronous operation as well as any user defined data.</param>
        /// <returns>A SecureSocket to handle the incoming connection.</returns>
        /// <remarks>The returned <see cref="VirtualSocket"/> can be cast to a SecureSocket if necessary.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="asyncResult"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="asyncResult"/> was not created by a call to <see cref="BeginAccept"/>.</exception>
        /// <exception cref="SocketException">An operating system error occurs while accessing the SecureSocket.</exception>
        /// <exception cref="ObjectDisposedException">The SecureSocket has been closed.</exception>
        /// <exception cref="SecurityException">Unable to create the credentials -or- client authentication error.</exception>
        public override VirtualSocket EndAccept(IAsyncResult asyncResult)
        {
            // Make sure everything is in order
            if (asyncResult == null)
            {
                throw new ArgumentNullException();
            }
            if (m_AcceptResult == null)
            {
                throw new InvalidOperationException();
            }
            if (m_AcceptResult != asyncResult)
            {
                throw new ArgumentException();
            }
            AsyncAcceptResult ar = m_AcceptResult;

            // Process the (secure) EndAccept
            // block if the operation hasn't ended yet
            if (!ar.IsCompleted)
            {
                ar.AsyncWaitHandle.WaitOne();
            }
            m_AcceptResult = null;
            if (ar.AsyncException != null)
            {
                throw ar.AsyncException;
            }
            return(ar.AcceptedSocket);
        }
Example #2
0
        /// <summary>
        /// Begins an asynchronous request to create a new <see cref="SecureSocket"/> to accept an incoming connection request.
        /// </summary>
        /// <param name="callback">The <see cref="AsyncCallback"/> delegate.</param>
        /// <param name="state">An object containing state information for this request.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous SecureSocket creation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="callback"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="SocketException">An operating system error occurs while creating the SecureSocket.</exception>
        /// <exception cref="ObjectDisposedException">The SecureSocket has been closed.</exception>
        public override IAsyncResult BeginAccept(AsyncCallback callback, object state)
        {
            if (m_AcceptResult != null)
            {
                throw new SocketException();
            }
            AsyncAcceptResult ret = new AsyncAcceptResult(callback, state, null);

            m_AcceptResult = ret;
            base.BeginAccept(new AsyncCallback(this.OnAccept), null);
            return(ret);
        }
		/// <summary>
		/// Begins an asynchronous request to create a new <see cref="SecureSocket"/> to accept an incoming connection request.
		/// </summary>
		/// <param name="callback">The <see cref="AsyncCallback"/> delegate.</param>
		/// <param name="state">An object containing state information for this request.</param>
		/// <returns>An <see cref="IAsyncResult"/> that references the asynchronous SecureSocket creation.</returns>
		/// <exception cref="ArgumentNullException"><paramref name="callback"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
		/// <exception cref="SocketException">An operating system error occurs while creating the SecureSocket.</exception>
		/// <exception cref="ObjectDisposedException">The SecureSocket has been closed.</exception>
		public override IAsyncResult BeginAccept(AsyncCallback callback, object state) {
			if (m_AcceptResult != null)
				throw new SocketException();
			AsyncAcceptResult ret = new AsyncAcceptResult(callback, state, null);
			m_AcceptResult = ret;
			base.BeginAccept(new AsyncCallback(this.OnAccept), null);
			return ret;
		}
        /// <summary>
        /// Ends an asynchronous request to create a new <see cref="SecureSocket"/> to accept an incoming connection request.
        /// </summary>
        /// <param name="asyncResult">Stores state information for this asynchronous operation as well as any user defined data.</param>
        /// <returns>A SecureSocket to handle the incoming connection.</returns>
        /// <remarks>The returned <see cref="VirtualSocket"/> can be cast to a SecureSocket if necessary.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="asyncResult"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="asyncResult"/> was not created by a call to <see cref="BeginAccept"/>.</exception>
        /// <exception cref="SocketException">An operating system error occurs while accessing the SecureSocket.</exception>
        /// <exception cref="ObjectDisposedException">The SecureSocket has been closed.</exception>
        /// <exception cref="SecurityException">Unable to create the credentials -or- client authentication error.</exception>
        public override VirtualSocket EndAccept(IAsyncResult asyncResult, CancellationToken cancel, ISocketMonitor monitor = null)
        {
            // Make sure everything is in order
            if (asyncResult == null)
                throw new ArgumentNullException();
            if (m_AcceptResult == null)
                throw new InvalidOperationException();
            if (m_AcceptResult != asyncResult)
                throw new ArgumentException();
            AsyncAcceptResult ar = m_AcceptResult;
            // Process the (secure) EndAccept
            // block if the operation hasn't ended yet
            while (!ar.IsCompleted)
            {
                ar.AsyncWaitHandle.WaitOne(200, false);
            }

            if (cancel.IsCancellationRequested)
            {
                cancel.ThrowIfCancellationRequested();
                return null;
            }

            m_AcceptResult = null;
            if (ar.AsyncException != null)
                throw ar.AsyncException;

            if (monitor != null)
                monitor.Attach(ar.AcceptedSocket);

            return ar.AcceptedSocket;
        }
Example #5
0
 /// <summary>
 /// Ends an asynchronous request to create a new <see cref="SecureSocket"/> to accept an incoming connection request.
 /// </summary>
 /// <param name="asyncResult">Stores state information for this asynchronous operation as well as any user defined data.</param>
 /// <returns>A SecureSocket to handle the incoming connection.</returns>
 /// <remarks>The returned <see cref="VirtualSocket"/> can be cast to a SecureSocket if necessary.</remarks>
 /// <exception cref="ArgumentNullException"><paramref name="asyncResult"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
 /// <exception cref="ArgumentException"><paramref name="asyncResult"/> was not created by a call to <see cref="BeginAccept"/>.</exception>
 /// <exception cref="SocketException">An operating system error occurs while accessing the SecureSocket.</exception>
 /// <exception cref="ObjectDisposedException">The SecureSocket has been closed.</exception>
 /// <exception cref="SecurityException">Unable to create the credentials -or- client authentication error.</exception>
 public override VirtualSocket EndAccept(IAsyncResult asyncResult)
 {
     // Make sure everything is in order
     if (asyncResult == null)
         throw new ArgumentNullException();
     if (m_AcceptResult == null)
         throw new InvalidOperationException();
     if (m_AcceptResult != asyncResult)
         throw new ArgumentException();
     AsyncAcceptResult ar = m_AcceptResult;
     // Process the (secure) EndAccept
     // block if the operation hasn't ended yet
     if (!ar.IsCompleted)
         ar.AsyncWaitHandle.WaitOne();
     m_AcceptResult = null;
     if (ar.AsyncException != null)
         throw ar.AsyncException;
     return ar.AcceptedSocket;
 }