public HttpParser(HttpParserType type, IHttpParserHandler handler) { _type = type; _handler = handler; _parser = new UnmanagedMemory(HttpParserNative.Size()); _settings = SetupParserSettings(); Init(); }
private void EnsureSuccess() { var error = HttpParserNative.ErrorMessageString(_parser.IntPtr); if (!error.Equals(Success, StringComparison.InvariantCulture)) { throw new HttpParserException(error); } }
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"); } } }
public bool ShouldKeepAlive() { return(HttpParserNative.ShouldKeepAlive(_parser.IntPtr) != 0); }
public void Init() { HttpParserNative.Init(_parser.IntPtr, _type); }