Пример #1
0
        internal virtual MemoryBytes PackageFile(string filename, long offset64, long length64, bool isImpersonating)
        {
            int offset = Convert.ToInt32(offset64);

            Convert.ToInt32(length64);
            FileStream  stream = null;
            MemoryBytes bytes  = null;

            try
            {
                stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                int count  = ((int)stream.Length) - offset;
                var buffer = new byte[count];
                int size   = stream.Read(buffer, offset, count);
                bytes = new MemoryBytes(buffer, size);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return(bytes);
        }
Пример #2
0
 private void AddBodyToCachedResponse(MemoryBytes bytes)
 {
     if (_cachedResponseBodyBytes == null)
     {
         _cachedResponseBodyBytes = new ArrayList();
     }
     _cachedResponseBodyBytes.Add(bytes);
     _cachedResponseBodyLength += bytes.Size;
 }
 private void AddBodyToCachedResponse(MemoryBytes bytes)
 {
     if (this._cachedResponseBodyBytes == null)
     {
         this._cachedResponseBodyBytes = new ArrayList();
     }
     this._cachedResponseBodyBytes.Add(bytes);
     this._cachedResponseBodyLength += bytes.Size;
 }
    // PackageFile for in-proc case
    internal virtual MemoryBytes PackageFile(String filename, long offset64, long length64, bool isImpersonating) {
        // The offset and length must be less than Int32.MaxValue for in-proc. 
        // This should be true, since HttpFileResponseElement.ctor throws ArgumentOutOfRangeException for in-proc
        Debug.Assert(offset64 < Int32.MaxValue);
        Debug.Assert(length64 < Int32.MaxValue);
        int offset = Convert.ToInt32(offset64);
        int length = Convert.ToInt32(length64);

        FileStream f = null;
        MemoryBytes bytes = null;
        try {
            Debug.Assert(offset < length);
            f = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            Debug.Assert((f.Length - offset) == length);
            int size = (int) (f.Length - offset);
            byte[] fileBytes = new byte[size];
            int bytesRead = f.Read(fileBytes, offset, size);
            bytes = new MemoryBytes(fileBytes, bytesRead);
        }
        finally {
            if (f != null)
                f.Close();
        }

        return bytes;
    }
 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);
         }
     }
 }
 internal virtual MemoryBytes PackageFile(string filename, long offset64, long length64, bool isImpersonating)
 {
     int offset = Convert.ToInt32(offset64);
     Convert.ToInt32(length64);
     FileStream stream = null;
     MemoryBytes bytes = null;
     try
     {
         stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
         int count = ((int) stream.Length) - offset;
         byte[] buffer = new byte[count];
         int size = stream.Read(buffer, offset, count);
         bytes = new MemoryBytes(buffer, size);
     }
     finally
     {
         if (stream != null)
         {
             stream.Close();
         }
     }
     return bytes;
 }
        private void AddBodyToCachedResponse(MemoryBytes bytes) {
            if ( _cachedResponseBodyBytes == null ) {
                _cachedResponseBodyBytes = new ArrayList();
            }
            Debug.Assert(null !=bytes, "null != bytes");

            _cachedResponseBodyBytes.Add(bytes);
            _cachedResponseBodyLength += bytes.Size;
        }