Esempio n. 1
0
        public HttpParser(HttpParserType type, IHttpParserHandler handler)
        {
            _type     = type;
            _handler  = handler;
            _parser   = new UnmanagedMemory(HttpParserNative.Size());
            _settings = SetupParserSettings();

            Init();
        }
Esempio n. 2
0
        private void EnsureSuccess()
        {
            var error = HttpParserNative.ErrorMessageString(_parser.IntPtr);

            if (!error.Equals(Success, StringComparison.InvariantCulture))
            {
                throw new HttpParserException(error);
            }
        }
Esempio n. 3
0
        public void Execute(ArraySegment <byte> buffer)
        {
            _buffer = buffer;

            using (var pin = new BytePin(_buffer.Array))
            {
                _bufferPinPtr = pin[_buffer.Offset];
                var lengthPtr = new UIntPtr((uint)_buffer.Count);
                var parsedPtr = HttpParserNative.Execute(_parser.IntPtr,
                                                         ref _settings, _bufferPinPtr, lengthPtr);

                EnsureSuccess();

                var parsed = (int)parsedPtr.ToUInt32();
                var length = (int)lengthPtr.ToUInt32();

                if (parsed != length)
                {
                    throw new HttpParserException("unable to parse");
                }
            }
        }
Esempio n. 4
0
 public bool ShouldKeepAlive()
 {
     return(HttpParserNative.ShouldKeepAlive(_parser.IntPtr) != 0);
 }
Esempio n. 5
0
 public void Init()
 {
     HttpParserNative.Init(_parser.IntPtr, _type);
 }