Beispiel #1
0
        private void onRead(IAsyncResult asyncResult)
        {
            var rstate = (ReadBufferState)asyncResult.AsyncState;
            var ares   = rstate.AsyncResult;

            try {
                var nread = base.EndRead(asyncResult);
                _decoder.Write(ares.Buffer, ares.Offset, nread);
                nread          = _decoder.Read(rstate.Buffer, rstate.Offset, rstate.Count);
                rstate.Offset += nread;
                rstate.Count  -= nread;
                if (rstate.Count == 0 || !_decoder.WantMore || nread == 0)
                {
                    _noMoreData = !_decoder.WantMore && nread == 0;
                    ares.Count  = rstate.InitialCount - rstate.Count;
                    ares.Complete();

                    return;
                }

                ares.Offset = 0;
                ares.Count  = Math.Min(_bufferLength, _decoder.ChunkLeft + 6);
                base.BeginRead(ares.Buffer, ares.Offset, ares.Count, onRead, rstate);
            }
            catch (Exception ex) {
                _context.Connection.SendError(ex.Message, 400);
                ares.Complete(ex);
            }
        }
        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)
        {
            var rstate = (ReadBufferState)asyncResult.AsyncState;
            var ares   = rstate.AsyncResult;

            try {
                var nread = base.EndRead(asyncResult);

                _decoder.Write(ares.Buffer, ares.Offset, nread);
                nread = _decoder.Read(rstate.Buffer, rstate.Offset, rstate.Count);

                rstate.Offset += nread;
                rstate.Count  -= nread;

                if (rstate.Count == 0 || !_decoder.WantsMore || nread == 0)
                {
                    _noMoreData = !_decoder.WantsMore && nread == 0;

                    ares.Count = rstate.InitialCount - rstate.Count;
                    ares.Complete();

                    return;
                }

                base.BeginRead(ares.Buffer, ares.Offset, ares.Count, onRead, rstate);
            }
            catch (Exception ex) {
                _context.ErrorMessage = "I/O operation aborted";
                _context.SendError();

                ares.Complete(ex);
            }
        }
        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);
            }
        }