private void EndWriteCore(IAsyncResult asyncResult)
        {
            HttpResponseStreamAsyncResult castedAsyncResult = asyncResult as HttpResponseStreamAsyncResult;

            if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this)
            {
                throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
            }
            if (castedAsyncResult.EndCalled)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndWrite)));
            }
            castedAsyncResult.EndCalled = true;
            // wait & then check for errors
            object returnValue = castedAsyncResult.InternalWaitForCompletion();

            Exception exception = returnValue as Exception;

            if (exception != null)
            {
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.Error(this, "Rethrowing exception:" + exception);
                }
                _closed = true;
                _httpContext.Abort();
                ExceptionDispatchInfo.Throw(exception);
            }
        }
Ejemplo n.º 2
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            if (Logging.On)
            {
                Logging.Enter(Logging.HttpListener, this, "EndWrite", "");
            }
            GlobalLog.Print("HttpResponseStream#" + ValidationHelper.HashString(this) + "::EndWrite() asyncResult#" + ValidationHelper.HashString(asyncResult));
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            HttpResponseStreamAsyncResult castedAsyncResult = asyncResult as HttpResponseStreamAsyncResult;

            if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this)
            {
                throw new ArgumentException(SR.GetString(SR.net_io_invalidasyncresult), "asyncResult");
            }
            if (castedAsyncResult.EndCalled)
            {
                throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndWrite"));
            }
            castedAsyncResult.EndCalled = true;
            // wait & then check for errors
            object returnValue = castedAsyncResult.InternalWaitForCompletion();

            Exception exception = returnValue as Exception;

            if (exception != null)
            {
                GlobalLog.Print("HttpResponseStream#" + ValidationHelper.HashString(this) + "::EndWrite() rethrowing exception:" + exception);
                if (Logging.On)
                {
                    Logging.Exception(Logging.HttpListener, this, "EndWrite", exception);
                }
                m_Closed = true;
                m_HttpContext.Abort();
                throw exception;
            }
            //


            GlobalLog.Print("HttpResponseStream#" + ValidationHelper.HashString(this) + "::EndWrite()");
            if (Logging.On)
            {
                Logging.Exit(Logging.HttpListener, this, "EndWrite", "");
            }
        }
Ejemplo n.º 3
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            if (Logging.On)
            {
                Logging.Enter(Logging.HttpListener, this, "EndWrite", "");
            }
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            HttpResponseStreamAsyncResult result = asyncResult as HttpResponseStreamAsyncResult;

            if ((result == null) || (result.AsyncObject != this))
            {
                throw new ArgumentException(SR.GetString("net_io_invalidasyncresult"), "asyncResult");
            }
            if (result.EndCalled)
            {
                throw new InvalidOperationException(SR.GetString("net_io_invalidendcall", new object[] { "EndWrite" }));
            }
            result.EndCalled = true;
            object    obj2 = result.InternalWaitForCompletion();
            Exception e    = obj2 as Exception;

            if (e != null)
            {
                if (Logging.On)
                {
                    Logging.Exception(Logging.HttpListener, this, "EndWrite", e);
                }
                this.m_HttpContext.Abort();
                throw e;
            }
            this.UpdateAfterWrite((uint)obj2);
            if (Logging.On)
            {
                Logging.Exit(Logging.HttpListener, this, "EndWrite", "");
            }
        }