private void onRead(IAsyncResult asyncResult)
        {
            ReadBufferState       readBufferState = (ReadBufferState)asyncResult.AsyncState;
            HttpStreamAsyncResult asyncResult2    = readBufferState.AsyncResult;

            try
            {
                int count = base.EndRead(asyncResult);
                _decoder.Write(asyncResult2.Buffer, asyncResult2.Offset, count);
                count = _decoder.Read(readBufferState.Buffer, readBufferState.Offset, readBufferState.Count);
                readBufferState.Offset += count;
                readBufferState.Count  -= count;
                if (readBufferState.Count == 0 || !_decoder.WantMore || count == 0)
                {
                    _noMoreData        = !_decoder.WantMore && count == 0;
                    asyncResult2.Count = readBufferState.InitialCount - readBufferState.Count;
                    asyncResult2.Complete();
                }
                else
                {
                    asyncResult2.Offset = 0;
                    asyncResult2.Count  = Math.Min(8192, _decoder.ChunkLeft + 6);
                    base.BeginRead(asyncResult2.Buffer, asyncResult2.Offset, asyncResult2.Count, (AsyncCallback)onRead, (object)readBufferState);
                }
            }
            catch (Exception ex)
            {
                _context.Connection.SendError(ex.Message, 400);
                asyncResult2.Complete(ex);
            }
        }
        private void onRead(IAsyncResult asyncResult)
        {
            ReadBufferState       asyncState = (ReadBufferState)asyncResult.AsyncState;
            HttpStreamAsyncResult result     = asyncState.AsyncResult;

            try
            {
                int count = base.EndRead(asyncResult);
                this._decoder.Write(result.Buffer, result.Offset, count);
                count              = this._decoder.Read(asyncState.Buffer, asyncState.Offset, asyncState.Count);
                asyncState.Offset += count;
                asyncState.Count  -= count;
                if ((asyncState.Count != 0) && (this._decoder.WantMore && (count != 0)))
                {
                    result.Offset = 0;
                    result.Count  = Math.Min(0x2000, this._decoder.ChunkLeft + 6);
                    base.BeginRead(result.Buffer, result.Offset, result.Count, new AsyncCallback(this.onRead), asyncState);
                }
                else
                {
                    this._noMoreData = !this._decoder.WantMore && (count == 0);
                    result.Count     = asyncState.InitialCount - asyncState.Count;
                    result.Complete();
                }
            }
            catch (Exception exception)
            {
                this._context.Connection.SendError(exception.Message, 400);
                result.Complete(exception);
            }
        }
        private void OnRead(IAsyncResult base_ares)
        {
            ChunkedInputStream.ReadBufferState readBufferState = (ChunkedInputStream.ReadBufferState)base_ares.AsyncState;
            HttpStreamAsyncResult ares = readBufferState.Ares;

            try
            {
                int num = base.EndRead(base_ares);
                this.decoder.Write(ares.Buffer, ares.Offset, num);
                num = this.decoder.Read(readBufferState.Buffer, readBufferState.Offset, readBufferState.Count);
                readBufferState.Offset += num;
                readBufferState.Count  -= num;
                if (readBufferState.Count == 0 || !this.decoder.WantMore || num == 0)
                {
                    this.no_more_data = (!this.decoder.WantMore && num == 0);
                    ares.Count        = readBufferState.InitialCount - readBufferState.Count;
                    ares.Complete();
                }
                else
                {
                    ares.Offset = 0;
                    ares.Count  = Math.Min(8192, this.decoder.ChunkLeft + 6);
                    base.BeginRead(ares.Buffer, ares.Offset, ares.Count, new AsyncCallback(this.OnRead), readBufferState);
                }
            }
            catch (Exception ex)
            {
                this.context.Connection.SendError(ex.Message, 400);
                ares.Complete(ex);
            }
        }
示例#4
0
        void OnRead(IAsyncResult base_ares)
        {
            ReadBufferState       rb   = (ReadBufferState)base_ares.AsyncState;
            HttpStreamAsyncResult ares = rb.Ares;

            try {
                int nread = base.EndRead(base_ares);
                decoder.Write(ares.Buffer, ares.Offset, nread);
                nread      = decoder.Read(rb.Buffer, rb.Offset, rb.Count);
                rb.Offset += nread;
                rb.Count  -= nread;
                if (rb.Count == 0 || !decoder.WantMore || nread == 0)
                {
                    no_more_data = !decoder.WantMore && nread == 0;
                    ares.Count   = rb.InitialCount - rb.Count;
                    ares.Complete();
                    return;
                }
                ares.Offset = 0;
                ares.Count  = Math.Min(8192, decoder.ChunkLeft + 6);
                base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
            } catch (Exception e) {
                context.Connection.SendError(e.Message, 400);
                ares.Complete(e);
            }
        }
        private void onRead(IAsyncResult asyncResult)
        {
            ReadBufferState       asyncState   = (ReadBufferState)asyncResult.AsyncState;
            HttpStreamAsyncResult initialCount = asyncState.AsyncResult;

            try
            {
                int num = base.EndRead(asyncResult);
                this._decoder.Write(initialCount.Buffer, initialCount.Offset, num);
                num = this._decoder.Read(asyncState.Buffer, asyncState.Offset, asyncState.Count);
                ReadBufferState offset = asyncState;
                offset.Offset = offset.Offset + num;
                ReadBufferState count = asyncState;
                count.Count = count.Count - num;
                if ((asyncState.Count == 0 || !this._decoder.WantMore ? false : num != 0))
                {
                    initialCount.Offset = 0;
                    initialCount.Count  = Math.Min(8192, this._decoder.ChunkLeft + 6);
                    base.BeginRead(initialCount.Buffer, initialCount.Offset, initialCount.Count, new AsyncCallback(this.onRead), asyncState);
                }
                else
                {
                    this._noMoreData   = (this._decoder.WantMore ? false : num == 0);
                    initialCount.Count = asyncState.InitialCount - asyncState.Count;
                    initialCount.Complete();
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                this._context.Connection.SendError(exception.Message, 400);
                initialCount.Complete(exception);
            }
        }
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "A negative value.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "A negative value.");
            }
            int num = buffer.Length;

            if (offset + count > num)
            {
                throw new ArgumentException("The sum of 'offset' and 'count' is greater than 'buffer' length.");
            }
            HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult(callback, state);

            if (_noMoreData)
            {
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            int num2 = _decoder.Read(buffer, offset, count);

            offset += num2;
            count  -= num2;
            if (count == 0)
            {
                httpStreamAsyncResult.Count = num2;
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            if (!_decoder.WantMore)
            {
                _noMoreData = num2 == 0;
                httpStreamAsyncResult.Count = num2;
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            httpStreamAsyncResult.Buffer = new byte[8192];
            httpStreamAsyncResult.Offset = 0;
            httpStreamAsyncResult.Count  = 8192;
            ReadBufferState readBufferState = new ReadBufferState(buffer, offset, count, httpStreamAsyncResult);

            readBufferState.InitialCount += num2;
            base.BeginRead(httpStreamAsyncResult.Buffer, httpStreamAsyncResult.Offset, httpStreamAsyncResult.Count, (AsyncCallback)onRead, (object)readBufferState);
            return(httpStreamAsyncResult);
        }
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "A negative value.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "A negative value.");
            }
            int length = buffer.Length;

            if ((offset + count) > length)
            {
                throw new ArgumentException("The sum of 'offset' and 'count' is greater than 'buffer' length.");
            }
            HttpStreamAsyncResult asyncResult = new HttpStreamAsyncResult(callback, state);

            if (this._noMoreData)
            {
                asyncResult.Complete();
                return(asyncResult);
            }
            int num2 = this._decoder.Read(buffer, offset, count);

            offset += num2;
            count  -= num2;
            if (count == 0)
            {
                asyncResult.Count = num2;
                asyncResult.Complete();
                return(asyncResult);
            }
            if (!this._decoder.WantMore)
            {
                this._noMoreData  = num2 == 0;
                asyncResult.Count = num2;
                asyncResult.Complete();
                return(asyncResult);
            }
            asyncResult.Buffer = new byte[0x2000];
            asyncResult.Offset = 0;
            asyncResult.Count  = 0x2000;
            ReadBufferState state2 = new ReadBufferState(buffer, offset, count, asyncResult);

            state2.InitialCount += num2;
            base.BeginRead(asyncResult.Buffer, asyncResult.Offset, asyncResult.Count, new AsyncCallback(this.onRead), state2);
            return(asyncResult);
        }
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            int num = buffer.Length;

            if (offset < 0 || offset > num)
            {
                throw new ArgumentOutOfRangeException("'offset' exceeds the size of buffer.");
            }
            if (count < 0 || offset > num - count)
            {
                throw new ArgumentOutOfRangeException("'offset' + 'count' exceeds the size of buffer.");
            }
            HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult();

            httpStreamAsyncResult.Callback = cback;
            httpStreamAsyncResult.State    = state;
            if (this.no_more_data)
            {
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            int num2 = this.decoder.Read(buffer, offset, count);

            offset += num2;
            count  -= num2;
            if (count == 0)
            {
                httpStreamAsyncResult.Count = num2;
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            if (!this.decoder.WantMore)
            {
                this.no_more_data           = (num2 == 0);
                httpStreamAsyncResult.Count = num2;
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            httpStreamAsyncResult.Buffer = new byte[8192];
            httpStreamAsyncResult.Offset = 0;
            httpStreamAsyncResult.Count  = 8192;
            ChunkedInputStream.ReadBufferState readBufferState = new ChunkedInputStream.ReadBufferState(buffer, offset, count, httpStreamAsyncResult);
            readBufferState.InitialCount += num2;
            base.BeginRead(httpStreamAsyncResult.Buffer, httpStreamAsyncResult.Offset, httpStreamAsyncResult.Count, new AsyncCallback(this.OnRead), readBufferState);
            return(httpStreamAsyncResult);
        }
示例#9
0
        public override IAsyncResult BeginRead(
            byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            var nread = fillFromBuffer(buffer, offset, count);

            if (nread > 0 || nread == -1)
            {
                var ares = new HttpStreamAsyncResult(callback, state);
                ares.Buffer   = buffer;
                ares.Offset   = offset;
                ares.Count    = count;
                ares.SyncRead = nread > 0 ? nread : 0;
                ares.Complete();

                return(ares);
            }

            // Avoid reading past the end of the request to allow for HTTP pipelining.
            if (_bodyLeft >= 0 && count > _bodyLeft)
            {
                count = (int)_bodyLeft;
            }

            return(_stream.BeginRead(buffer, offset, count, callback, state));
        }
示例#10
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            int num = this.fillFromBuffer(buffer, offset, count);

            if ((num <= 0) && (num != -1))
            {
                if ((this._bodyLeft >= 0L) && (count > this._bodyLeft))
                {
                    count = (int)this._bodyLeft;
                }
                return(this._stream.BeginRead(buffer, offset, count, callback, state));
            }
            HttpStreamAsyncResult result = new HttpStreamAsyncResult(callback, state)
            {
                Buffer   = buffer,
                Offset   = offset,
                Count    = count,
                SyncRead = (num <= 0) ? 0 : num
            };

            result.Complete();
            return(result);
        }
示例#11
0
        public override IAsyncResult BeginRead(byte [] buffer, int offset, int count,
                                               AsyncCallback cback, object state)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(typeof(RequestStream).ToString());
            }

            int nread = FillFromBuffer(buffer, offset, count);

            if (nread > 0 || nread == -1)
            {
                HttpStreamAsyncResult ares = new HttpStreamAsyncResult();
                ares.Buffer    = buffer;
                ares.Offset    = offset;
                ares.Count     = count;
                ares.Callback  = cback;
                ares.State     = state;
                ares.SynchRead = nread;
                ares.Complete();
                return(ares);
            }

            // Avoid reading past the end of the request to allow
            // for HTTP pipelining
            if (remaining_body >= 0 && count > remaining_body)
            {
                count = (int)Math.Min(Int32.MaxValue, remaining_body);
            }
            return(stream.BeginRead(buffer, offset, count, cback, state));
        }
示例#12
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            IAsyncResult asyncResult;

            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            int num = this.fillFromBuffer(buffer, offset, count);

            if ((num > 0 ? false : num != -1))
            {
                if ((this._bodyLeft <(long)0 ? false : (long)count> this._bodyLeft))
                {
                    count = (int)this._bodyLeft;
                }
                asyncResult = this._stream.BeginRead(buffer, offset, count, callback, state);
            }
            else
            {
                HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult(callback, state)
                {
                    Buffer   = buffer,
                    Offset   = offset,
                    Count    = count,
                    SyncRead = (num > 0 ? num : 0)
                };
                httpStreamAsyncResult.Complete();
                asyncResult = httpStreamAsyncResult;
            }
            return(asyncResult);
        }
示例#13
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            int num = this.fillFromBuffer(buffer, offset, count);

            if (num > 0 || num == -1)
            {
                HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult();
                httpStreamAsyncResult.Buffer   = buffer;
                httpStreamAsyncResult.Offset   = offset;
                httpStreamAsyncResult.Count    = count;
                httpStreamAsyncResult.Callback = callback;
                httpStreamAsyncResult.State    = state;
                httpStreamAsyncResult.SyncRead = num;
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            if (this._remainingBody >= 0L && this._remainingBody < (long)count)
            {
                count = (int)this._remainingBody;
            }
            return(this._stream.BeginRead(buffer, offset, count, callback, state));
        }
示例#14
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }
            int num = fillFromBuffer(buffer, offset, count);

            if (num > 0 || num == -1)
            {
                HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult(callback, state);
                httpStreamAsyncResult.Buffer   = buffer;
                httpStreamAsyncResult.Offset   = offset;
                httpStreamAsyncResult.Count    = count;
                httpStreamAsyncResult.SyncRead = ((num > 0) ? num : 0);
                httpStreamAsyncResult.Complete();
                return(httpStreamAsyncResult);
            }
            if (_bodyLeft >= 0 && count > _bodyLeft)
            {
                count = (int)_bodyLeft;
            }
            return(_stream.BeginRead(buffer, offset, count, callback, state));
        }
示例#15
0
        public override IAsyncResult BeginRead(
            byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), "A negative value.");
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), "A negative value.");
            }

            var len = buffer.Length;

            if (offset + count > len)
            {
                throw new ArgumentException(
                          "The sum of 'offset' and 'count' is greater than 'buffer' length.");
            }

            var ares = new HttpStreamAsyncResult(callback, state);

            if (_noMoreData)
            {
                ares.Complete();
                return(ares);
            }

            var nread = _decoder.Read(buffer, offset, count);

            offset += nread;
            count  -= nread;
            if (count == 0)
            {
                // Got all we wanted, no need to bother the decoder yet.
                ares.Count = nread;
                ares.Complete();

                return(ares);
            }

            if (!_decoder.WantMore)
            {
                _noMoreData = nread == 0;
                ares.Count  = nread;
                ares.Complete();

                return(ares);
            }

            ares.Buffer = new byte[_bufferLength];
            ares.Offset = 0;
            ares.Count  = _bufferLength;

            var rstate = new ReadBufferState(buffer, offset, count, ares);

            rstate.InitialCount += nread;
            base.BeginRead(ares.Buffer, ares.Offset, ares.Count, onRead, rstate);

            return(ares);
        }
示例#16
0
        public override IAsyncResult BeginRead(
            byte[] buffer, int offset, int count, AsyncCallback callback, object state
            )
        {
            if (_disposed)
            {
                var name = GetType().ToString();

                throw new ObjectDisposedException(name);
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset < 0)
            {
                var msg = "A negative value.";

                throw new ArgumentOutOfRangeException("offset", msg);
            }

            if (count < 0)
            {
                var msg = "A negative value.";

                throw new ArgumentOutOfRangeException("count", msg);
            }

            var len = buffer.Length;

            if (offset + count > len)
            {
                var msg = "The sum of 'offset' and 'count' is greater than the length of 'buffer'.";

                throw new ArgumentException(msg);
            }

            if (count == 0)
            {
                return(_stream.BeginRead(buffer, offset, 0, callback, state));
            }

            var nread = fillFromBuffer(buffer, offset, count);

            if (nread != 0)
            {
                var ares = new HttpStreamAsyncResult(callback, state);
                ares.Buffer   = buffer;
                ares.Offset   = offset;
                ares.Count    = count;
                ares.SyncRead = nread > 0 ? nread : 0;
                ares.Complete();

                return(ares);
            }

            if (_bodyLeft >= 0 && _bodyLeft < count)
            {
                count = (int)_bodyLeft;
            }

            return(_stream.BeginRead(buffer, offset, count, callback, state));
        }
示例#17
0
        public override IAsyncResult BeginRead(
            byte [] buffer, int offset, int count, AsyncCallback cback, object state)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            int len = buffer.Length;

            if (offset < 0 || offset > len)
            {
                throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
            }

            if (count < 0 || offset > len - count)
            {
                throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
            }

            HttpStreamAsyncResult ares = new HttpStreamAsyncResult();

            ares.Callback = cback;
            ares.State    = state;
            if (no_more_data)
            {
                ares.Complete();
                return(ares);
            }
            int nread = decoder.Read(buffer, offset, count);

            offset += nread;
            count  -= nread;
            if (count == 0)
            {
                // got all we wanted, no need to bother the decoder yet
                ares.Count = nread;
                ares.Complete();
                return(ares);
            }
            if (!decoder.WantMore)
            {
                no_more_data = nread == 0;
                ares.Count   = nread;
                ares.Complete();
                return(ares);
            }
            ares.Buffer = new byte [8192];
            ares.Offset = 0;
            ares.Count  = 8192;
            ReadBufferState rb = new ReadBufferState(buffer, offset, count, ares);

            rb.InitialCount += nread;
            base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
            return(ares);
        }
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            IAsyncResult asyncResult;

            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().ToString());
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "A negative value.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "A negative value.");
            }
            if (offset + count > (int)buffer.Length)
            {
                throw new ArgumentException("The sum of 'offset' and 'count' is greater than 'buffer' length.");
            }
            HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult(callback, state);

            if (!this._noMoreData)
            {
                int num = this._decoder.Read(buffer, offset, count);
                offset += num;
                count  -= num;
                if (count == 0)
                {
                    httpStreamAsyncResult.Count = num;
                    httpStreamAsyncResult.Complete();
                    asyncResult = httpStreamAsyncResult;
                }
                else if (this._decoder.WantMore)
                {
                    httpStreamAsyncResult.Buffer = new byte[8192];
                    httpStreamAsyncResult.Offset = 0;
                    httpStreamAsyncResult.Count  = 8192;
                    ReadBufferState readBufferState = new ReadBufferState(buffer, offset, count, httpStreamAsyncResult);
                    ReadBufferState initialCount    = readBufferState;
                    initialCount.InitialCount = initialCount.InitialCount + num;
                    base.BeginRead(httpStreamAsyncResult.Buffer, httpStreamAsyncResult.Offset, httpStreamAsyncResult.Count, new AsyncCallback(this.onRead), readBufferState);
                    asyncResult = httpStreamAsyncResult;
                }
                else
                {
                    this._noMoreData            = num == 0;
                    httpStreamAsyncResult.Count = num;
                    httpStreamAsyncResult.Complete();
                    asyncResult = httpStreamAsyncResult;
                }
            }
            else
            {
                httpStreamAsyncResult.Complete();
                asyncResult = httpStreamAsyncResult;
            }
            return(asyncResult);
        }
示例#19
0
        public override IAsyncResult BeginRead(
            byte [] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            var len = buffer.Length;

            if (offset < 0 || offset > len)
            {
                throw new ArgumentOutOfRangeException("'offset' exceeds the size of buffer.");
            }

            if (count < 0 || offset > len - count)
            {
                throw new ArgumentOutOfRangeException("'offset' + 'count' exceeds the size of buffer.");
            }

            var ares = new HttpStreamAsyncResult(callback, state);

            if (_noMoreData)
            {
                ares.Complete();
                return(ares);
            }

            var nread = _decoder.Read(buffer, offset, count);

            offset += nread;
            count  -= nread;
            if (count == 0)
            {
                // Got all we wanted, no need to bother the decoder yet.
                ares.Count = nread;
                ares.Complete();

                return(ares);
            }

            if (!_decoder.WantMore)
            {
                _noMoreData = nread == 0;
                ares.Count  = nread;
                ares.Complete();

                return(ares);
            }

            ares.Buffer = new byte [_bufferSize];
            ares.Offset = 0;
            ares.Count  = _bufferSize;

            var readState = new ReadBufferState(buffer, offset, count, ares);

            readState.InitialCount += nread;
            base.BeginRead(ares.Buffer, ares.Offset, ares.Count, onRead, readState);

            return(ares);
        }
示例#20
0
    public override IAsyncResult BeginRead (
      byte [] buffer, int offset, int count, AsyncCallback callback, object state)
    {
      if (_disposed)
        throw new ObjectDisposedException (GetType ().ToString ());

      if (buffer == null)
        throw new ArgumentNullException ("buffer");

      var len = buffer.Length;
      if (offset < 0 || offset > len)
        throw new ArgumentOutOfRangeException ("'offset' exceeds the size of buffer.");

      if (count < 0 || offset > len - count)
        throw new ArgumentOutOfRangeException ("'offset' + 'count' exceeds the size of buffer.");

      var ares = new HttpStreamAsyncResult (callback, state);
      if (_noMoreData) {
        ares.Complete ();
        return ares;
      }

      var nread = _decoder.Read (buffer, offset, count);
      offset += nread;
      count -= nread;
      if (count == 0) {
        // Got all we wanted, no need to bother the decoder yet.
        ares.Count = nread;
        ares.Complete ();

        return ares;
      }

      if (!_decoder.WantMore) {
        _noMoreData = nread == 0;
        ares.Count = nread;
        ares.Complete ();

        return ares;
      }

      ares.Buffer = new byte [_bufferSize];
      ares.Offset = 0;
      ares.Count = _bufferSize;

      var readState = new ReadBufferState (buffer, offset, count, ares);
      readState.InitialCount += nread;
      base.BeginRead (ares.Buffer, ares.Offset, ares.Count, onRead, readState);

      return ares;
    }
        public override IAsyncResult BeginRead(
			byte [] buffer, int offset, int count, AsyncCallback cback, object state)
        {
            if (disposed)
                throw new ObjectDisposedException (GetType ().ToString ());

            if (buffer == null)
                throw new ArgumentNullException ("buffer");

            int len = buffer.Length;
            if (offset < 0 || offset > len)
                throw new ArgumentOutOfRangeException ("'offset' exceeds the size of buffer.");

            if (count < 0 || offset > len - count)
                throw new ArgumentOutOfRangeException ("'offset' + 'count' exceeds the size of buffer.");

            var ares = new HttpStreamAsyncResult ();
            ares.Callback = cback;
            ares.State = state;
            if (no_more_data) {
                ares.Complete ();
                return ares;
            }

            int nread = decoder.Read (buffer, offset, count);
            offset += nread;
            count -= nread;
            if (count == 0) {
                // got all we wanted, no need to bother the decoder yet
                ares.Count = nread;
                ares.Complete ();
                return ares;
            }

            if (!decoder.WantMore) {
                no_more_data = nread == 0;
                ares.Count = nread;
                ares.Complete ();
                return ares;
            }

            ares.Buffer = new byte [8192];
            ares.Offset = 0;
            ares.Count = 8192;
            var rb = new ReadBufferState (buffer, offset, count, ares);
            rb.InitialCount += nread;
            base.BeginRead (ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
            return ares;
        }
示例#22
0
    public override IAsyncResult BeginRead (
      byte [] buffer, int offset, int count, AsyncCallback callback, object state)
    {
      if (_disposed)
        throw new ObjectDisposedException (GetType ().ToString ());

      var nread = fillFromBuffer (buffer, offset, count);
      if (nread > 0 || nread == -1) {
        var ares = new HttpStreamAsyncResult (callback, state);
        ares.Buffer = buffer;
        ares.Offset = offset;
        ares.Count = count;
        ares.SyncRead = nread;
        ares.Complete ();

        return ares;
      }

      // Avoid reading past the end of the request to allow for HTTP pipelining.
      if (_remainingBody >= 0 && _remainingBody < count)
        count = (int) _remainingBody;

      return _stream.BeginRead (buffer, offset, count, callback, state);
    }
        public override IAsyncResult BeginRead(
			byte [] buffer, int offset, int count, AsyncCallback cback, object state)
        {
            if (disposed)
                throw new ObjectDisposedException (GetType ().ToString ());

            int nread = FillFromBuffer (buffer, offset, count);
            if (nread > 0 || nread == -1) {
                var ares = new HttpStreamAsyncResult ();
                ares.Buffer = buffer;
                ares.Offset = offset;
                ares.Count = count;
                ares.Callback = cback;
                ares.State = state;
                ares.SyncRead = nread;
                ares.Complete ();
                return ares;
            }

            // Avoid reading past the end of the request to allow
            // for HTTP pipelining
            if (remaining_body >= 0 && count > remaining_body)
                count = (int) Math.Min (Int32.MaxValue, remaining_body);

            return stream.BeginRead (buffer, offset, count, cback, state);
        }