Esempio n. 1
0
        private void FlushCachedResponse(bool isFinal)
        {
            bool async         = false;
            int  minimumLength = 0;

            IntPtr[] bodyFragments       = null;
            int[]    bodyFragmentLengths = null;
            long     num2 = 0L;

            try
            {
                if (_cachedResponseBodyLength > 0)
                {
                    minimumLength       = _cachedResponseBodyBytes.Count;
                    bodyFragments       = RecyclableArrayHelper.GetIntPtrArray(minimumLength);
                    bodyFragmentLengths = RecyclableArrayHelper.GetIntegerArray(minimumLength);
                    for (int index = 0; index < minimumLength; index++)
                    {
                        var bytes = (MemoryBytes)_cachedResponseBodyBytes[index];
                        bodyFragments[index] = bytes.LockMemory();
                        if (!isFinal || !bytes.IsBufferFromUnmanagedPool)
                        {
                            _requiresAsyncFlushCallback = true;
                        }
                        if (bytes.UseTransmitFile)
                        {
                            bodyFragmentLengths[index] = -bytes.Size;
                            _ignoreMinAsyncSize        = true;
                            num2 += bytes.FileSize;
                        }
                        else
                        {
                            bodyFragmentLengths[index] = bytes.Size;
                            num2 += bytes.Size;
                        }
                    }
                }
                int doneWithSession = (isFinal ? 1 : 0);
                int finalStatus     = (isFinal ? (_cachedResponseKeepConnected != 0 ? 2 : 1) : 0);
                _cachedResponseBodyBytesIoLockCount = 2;
                _endOfRequestCallbackLockCount++;
                try { FlushCore(_cachedResponseStatus, _cachedResponseHeaders, _cachedResponseKeepConnected, _cachedResponseBodyLength, minimumLength, bodyFragments, bodyFragmentLengths, doneWithSession, finalStatus, out async); }
                finally
                {
                    if (isFinal)
                    {
                        Close();
                    }
                }
            }
            finally
            {
                if (!async)
                {
                    _cachedResponseBodyBytesIoLockCount--;
                    _endOfRequestCallbackLockCount--;
                }
                UnlockCachedResponseBytesOnceAfterIoComplete();
                RecyclableArrayHelper.ReuseIntPtrArray(bodyFragments);
                RecyclableArrayHelper.ReuseIntegerArray(bodyFragmentLengths);
            }
        }
 private void FlushCachedResponse(bool isFinal)
 {
     if (this._ecb != IntPtr.Zero)
     {
         bool     async               = false;
         int      minimumLength       = 0;
         IntPtr[] bodyFragments       = null;
         int[]    bodyFragmentLengths = null;
         long     num2 = 0L;
         try
         {
             if (this._cachedResponseBodyLength > 0)
             {
                 minimumLength       = this._cachedResponseBodyBytes.Count;
                 bodyFragments       = RecyclableArrayHelper.GetIntPtrArray(minimumLength);
                 bodyFragmentLengths = RecyclableArrayHelper.GetIntegerArray(minimumLength);
                 for (int i = 0; i < minimumLength; i++)
                 {
                     MemoryBytes bytes = (MemoryBytes)this._cachedResponseBodyBytes[i];
                     bodyFragments[i] = bytes.LockMemory();
                     if (!isFinal || !bytes.IsBufferFromUnmanagedPool)
                     {
                         this._requiresAsyncFlushCallback = true;
                     }
                     if (bytes.UseTransmitFile)
                     {
                         bodyFragmentLengths[i]   = -bytes.Size;
                         this._ignoreMinAsyncSize = true;
                         num2 += bytes.FileSize;
                     }
                     else
                     {
                         bodyFragmentLengths[i] = bytes.Size;
                         num2 += bytes.Size;
                     }
                 }
             }
             int doneWithSession = isFinal ? 1 : 0;
             int finalStatus     = isFinal ? ((this._cachedResponseKeepConnected != 0) ? 2 : 1) : 0;
             this._cachedResponseBodyBytesIoLockCount = 2;
             this._endOfRequestCallbackLockCount++;
             if (isFinal)
             {
                 PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_EXECUTING);
             }
             int delta = (int)num2;
             if (delta > 0)
             {
                 PerfCounters.IncrementCounterEx(AppPerfCounter.REQUEST_BYTES_OUT, delta);
             }
             try
             {
                 this.FlushCore(this._cachedResponseStatus, this._cachedResponseHeaders, this._cachedResponseKeepConnected, this._cachedResponseBodyLength, minimumLength, bodyFragments, bodyFragmentLengths, doneWithSession, finalStatus, out async);
             }
             finally
             {
                 if (isFinal)
                 {
                     this.Close();
                     this._ecb = IntPtr.Zero;
                 }
             }
         }
         finally
         {
             if (!async)
             {
                 this._cachedResponseBodyBytesIoLockCount--;
                 this._endOfRequestCallbackLockCount--;
             }
             this.UnlockCachedResponseBytesOnceAfterIoComplete();
             RecyclableArrayHelper.ReuseIntPtrArray(bodyFragments);
             RecyclableArrayHelper.ReuseIntegerArray(bodyFragmentLengths);
         }
     }
 }