示例#1
0
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback cback, 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, cback, state));
        }
示例#2
0
 public override void Close()
 {
     if (!this.disposed)
     {
         this.disposed = true;
         MemoryStream headers     = this.GetHeaders(true);
         bool         sendChunked = this.response.SendChunked;
         if (headers != null)
         {
             long position = headers.Position;
             if (sendChunked && !this.trailer_sent)
             {
                 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.trailer_sent = true;
         }
         else if (sendChunked && !this.trailer_sent)
         {
             byte[] chunkSizeBytes = ResponseStream.GetChunkSizeBytes(0, true);
             this.InternalWrite(chunkSizeBytes, 0, chunkSizeBytes.Length);
             this.trailer_sent = true;
         }
         this.response.Close();
     }
 }
示例#3
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);
            }
        }