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 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);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 7
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);
        }
    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;
    }
Esempio n. 9
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;
		}
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }