private void ProcessHeaderFrame(int headerlength) { if (!WebSocketFrameHeader.TryParse(_headerBuffer.Array, _headerBuffer.Offset, headerlength, _keyBuffer, out WebSocketFrameHeader header)) { throw new WebSocketException("Cannot understand frame header"); } CurrentHeader = header; if (!header.Flags.Option.IsData()) { ProcessControlFrame(); CurrentHeader = null; } else { _ongoingMessageAwaiting = 0; } _ping.NotifyActivity(); }
private async Task ReadHeader(CancellationToken cancellation) { Int32 readed = 0; var success = await TryReadHeaderUntil(readed, 6, cancellation).ConfigureAwait(false); if (!success) { Close(WebSocketCloseReasons.ProtocolError); return; } readed += 6; Int32 headerlength = WebSocketFrameHeader.GetHeaderLength(_headerBuffer.Array, _headerBuffer.Offset); success = await TryReadHeaderUntil(readed, headerlength, cancellation).ConfigureAwait(false); if (!success) { Close(WebSocketCloseReasons.ProtocolError); return; } WebSocketFrameHeader header; if (!WebSocketFrameHeader.TryParse(_headerBuffer.Array, _headerBuffer.Offset, headerlength, _keyBuffer, out header)) { throw new WebSocketException("Cannot understand frame header"); } CurrentHeader = header; if (!header.Flags.Option.IsData()) { ProcessControlFrame(_clientStream); CurrentHeader = null; } else { _ongoingMessageAwaiting = 0; } _ping.NotifyActivity(); }
private void ParseHeader(Int32 readed) { if (!TryReadHeaderUntil(ref readed, 6)) { Close(WebSocketCloseReasons.ProtocolError); return; } Int32 headerlength = WebSocketFrameHeader.GetHeaderLength(_headerBuffer.Array, _headerBuffer.Offset); if (!TryReadHeaderUntil(ref readed, headerlength)) { Close(WebSocketCloseReasons.ProtocolError); return; } WebSocketFrameHeader header; if (!WebSocketFrameHeader.TryParse(_headerBuffer.Array, _headerBuffer.Offset, headerlength, _keyBuffer, out header)) { throw new WebSocketException("Cannot understand frame header"); } CurrentHeader = header; if (!header.Flags.Option.IsData()) { ProcessControlFrame(_clientStream); CurrentHeader = null; } else { _ongoingMessageAwaiting = 0; } _ping.NotifyActivity(); }