Пример #1
0
        /// <summary>
        /// Begins an asynchronous request to shut the connection down.
        /// </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 shutdown.</returns>
        /// <exception cref="InvalidOperationException"><see cref="BeginShutdown"/> has already been called.</exception>
        // Thanks to Michael J. Moore and Stefan Bernbo for notifying us about a bug in this method.
        public IAsyncResult BeginShutdown(AsyncCallback callback, object state)
        {
            if (m_ShutdownResult != null)
            {
                throw new InvalidOperationException();
            }
            AsyncResult ar = new AsyncResult(callback, state, null);

            m_ShutdownResult = ar;
            if (!this.Connected)
            {
                ar.Notify(null);
            }
            else if (SecureProtocol == SecureProtocol.None)
            {
                base.Shutdown(SocketShutdown.Both);
                ar.Notify(null);
            }
            else
            {
                m_Controller.BeginShutdown(new AsyncCallback(this.OnShutdown), null);
            }
            return(ar);
        }
Пример #2
0
		/// <summary>
		/// Begins an asynchronous request to shut the connection down.
		/// </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 shutdown.</returns>
		/// <exception cref="InvalidOperationException"><see cref="BeginShutdown"/> has already been called.</exception>
		// Thanks to Michael J. Moore and Stefan Bernbo for notifying us about a bug in this method.
		public IAsyncResult BeginShutdown(AsyncCallback callback, object state) {
			if (m_ShutdownResult != null)
				throw new InvalidOperationException();
			AsyncResult ar = new AsyncResult(callback, state, null);
			m_ShutdownResult = ar;
			if (!this.Connected) {
				ar.Notify(null);
			} else if (SecureProtocol == SecureProtocol.None) {
				base.Shutdown(SocketShutdown.Both);
				ar.Notify(null);
			} else {
				m_Controller.BeginShutdown(new AsyncCallback(this.OnShutdown), null);
			}
			return ar;
		}