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

            Init();
        }
예제 #2
0
        private void EnsureSuccess()
        {
            var error = HttpParserNative.ErrorMessageString(_parser.IntPtr);

            if (!error.Equals(Success, StringComparison.InvariantCulture))
            {
                throw new HttpParserException(error);
            }
        }
예제 #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");
                }
            }
        }
예제 #4
0
 public bool ShouldKeepAlive()
 {
     return(HttpParserNative.ShouldKeepAlive(_parser.IntPtr) != 0);
 }
예제 #5
0
 public void Init()
 {
     HttpParserNative.Init(_parser.IntPtr, _type);
 }