public ReadBufferState(
 byte[] buffer, int offset, int count, HttpStreamAsyncResult asyncResult)
   {
       _buffer = buffer;
         _offset = offset;
         _count = count;
         _initialCount = count;
         _asyncResult = asyncResult;
   }
        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);
        }