Example #1
0
 public ReqRespStream(Transport2HttpHandler transport2HttpHandler)
 {
     _transport2HttpHandler = transport2HttpHandler;
     _buf = transport2HttpHandler.Buffer;
     _responseMaxLen = transport2HttpHandler.ReceiveBufferSize;
     ResponseStartOffset = transport2HttpHandler.ResponseBodyBufferOffset;
 }
Example #2
0
 public ReqRespStream(Transport2HttpHandler transport2HttpHandler)
 {
     _transport2HttpHandler = transport2HttpHandler;
     _buf                = transport2HttpHandler.Buffer;
     _responseMaxLen     = transport2HttpHandler.ReceiveBufferSize;
     ResponseStartOffset = transport2HttpHandler.ResponseBodyBufferOffset;
 }
Example #3
0
        public bool ProcessByte(byte b)
        {
            switch (_state)
            {
            case State.InHex:
                var h = Transport2HttpHandler.ParseHexChar(b);
                if (h < 0)
                {
                    _state = State.AfterHex;
                    goto case State.AfterHex;
                }
                _nextAvail = _nextAvail * 16 + h;
                break;

            case State.AfterHex:
                if (b == 13)
                {
                    _state = State.AfterCR;
                }
                break;

            case State.AfterCR:
                if (b == 10)
                {
                    _state     = State.InData;
                    _dataAvail = _nextAvail;
                    break;
                }
                _state = State.AfterHex;
                break;

            case State.InData:
                if (b == 13)
                {
                    _state = State.AfterCR2;
                }
                else
                {
                    Debug.Assert(_nextAvail == 0);
                    _state = State.InTrailer;
                }
                break;

            case State.AfterCR2:
                Debug.Assert(b == 10);
                if (_nextAvail == 0)
                {
                    _state     = State.End;
                    _dataAvail = -1;
                    return(true);
                }
                _state     = State.InHex;
                _nextAvail = 0;
                break;

            case State.AfterLF2:
                if (b == 13)
                {
                    _state = State.AfterCR3;
                }
                else
                {
                    _state = State.InTrailer;
                }
                break;

            case State.InTrailer:
                if (b == 13)
                {
                    _state = State.AfterTrailerCR;
                }
                break;

            case State.AfterTrailerCR:
                Debug.Assert(b == 10);
                _state = State.AfterLF2;
                break;

            case State.AfterCR3:
                Debug.Assert(b == 10);
                _state     = State.End;
                _dataAvail = -1;
                return(true);

            default:
                throw new InvalidOperationException();
            }
            return(false);
        }