Пример #1
0
        public override void Close()
        {
            if (this._disposed)
            {
                return;
            }
            this._disposed = true;
            MemoryStream headers     = this.getHeaders(true);
            bool         sendChunked = this._response.SendChunked;

            if (headers != null)
            {
                long position = headers.Position;
                if (sendChunked && !this._trailerSent)
                {
                    byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(0, true);
                    headers.Position = headers.Length;
                    headers.Write(chunkSizeBytes, 0, chunkSizeBytes.Length);
                }
                this.InternalWrite(headers.GetBuffer(), (int)position, (int)(headers.Length - position));
                this._trailerSent = true;
            }
            else if (sendChunked && !this._trailerSent)
            {
                byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(0, true);
                this.InternalWrite(chunkSizeBytes, 0, chunkSizeBytes.Length);
                this._trailerSent = true;
            }
            this._response.Close();
        }
Пример #2
0
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            MemoryStream headers     = this.getHeaders(false);
            bool         sendChunked = this._response.SendChunked;

            if (headers != null)
            {
                long position = headers.Position;
                headers.Position = headers.Length;
                if (sendChunked)
                {
                    byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(count, false);
                    headers.Write(chunkSizeBytes, 0, chunkSizeBytes.Length);
                }
                headers.Write(buffer, offset, count);
                buffer = headers.GetBuffer();
                offset = (int)position;
                count  = (int)(headers.Position - position);
            }
            else if (sendChunked)
            {
                byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(count, false);
                this.InternalWrite(chunkSizeBytes, 0, chunkSizeBytes.Length);
            }
            return(this._stream.BeginWrite(buffer, offset, count, callback, state));
        }
 private void writeChunked(byte[] buffer, int offset, int count)
 {
     byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(count, false);
     this._stream.Write(chunkSizeBytes, 0, (int)chunkSizeBytes.Length);
     this._stream.Write(buffer, offset, count);
     this._stream.Write(ResponseStream._crlf, 0, 2);
 }
        private bool flush(bool closing)
        {
            bool flag;

            if (!this._response.HeadersSent)
            {
                if (!this.flushHeaders(closing))
                {
                    if (closing)
                    {
                        this._response.CloseConnection = true;
                    }
                    flag = false;
                    return(flag);
                }
                this._sendChunked = this._response.SendChunked;
                this._writeBody   = (this._sendChunked ? this._writeChunked : this._write);
            }
            this.flushBody(closing);
            if ((!closing ? false : this._sendChunked))
            {
                byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(0, true);
                this._write(chunkSizeBytes, 0, (int)chunkSizeBytes.Length);
            }
            flag = true;
            return(flag);
        }
Пример #5
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            MemoryStream headers     = this.getHeaders(false);
            bool         sendChunked = this._response.SendChunked;

            if (headers != null)
            {
                long position = headers.Position;
                headers.Position = headers.Length;
                if (sendChunked)
                {
                    byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(count, false);
                    headers.Write(chunkSizeBytes, 0, chunkSizeBytes.Length);
                }
                int num = Math.Min(count, 16384 - (int)headers.Position + (int)position);
                headers.Write(buffer, offset, num);
                count  -= num;
                offset += num;
                this.InternalWrite(headers.GetBuffer(), (int)position, (int)(headers.Length - position));
                headers.SetLength(0L);
                headers.Capacity = 0;
            }
            else if (sendChunked)
            {
                byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(count, false);
                this.InternalWrite(chunkSizeBytes, 0, chunkSizeBytes.Length);
            }
            if (count > 0)
            {
                this.InternalWrite(buffer, offset, count);
            }
            if (sendChunked)
            {
                this.InternalWrite(ResponseStream._crlf, 0, 2);
            }
        }
 internal void Close(bool force)
 {
     if (!this._disposed)
     {
         this._disposed = true;
         if ((force ? true : !this.flush(true)))
         {
             if (this._sendChunked)
             {
                 byte[] chunkSizeBytes = ResponseStream.getChunkSizeBytes(0, true);
                 this._write(chunkSizeBytes, 0, (int)chunkSizeBytes.Length);
             }
             this._body.Dispose();
             this._body = null;
             this._response.Abort();
         }
         else
         {
             this._response.Close();
         }
         this._response = null;
         this._stream   = null;
     }
 }