public void ProcessData(StreamFrame frame) { // Do not accept data if the stream is reset. if (State == StreamState.ResetRecvd) { return; } var data = frame.StreamData; if (frame.Offset != null) { _data.Add(frame.Offset.Value, frame.StreamData); } else { // TODO: Careful with duplicate 0 offset packets on the same stream. Probably PROTOCOL_VIOLATION? _data.Add(0, frame.StreamData); } // Either this frame marks the end of the stream, // or fin frame came before the data frames if (frame.EndOfStream) { State = StreamState.SizeKnown; } _currentTransferRate += (ulong)data.Length; // Terminate connection if maximum stream data is reached if (_currentTransferRate >= _maximumStreamData) { var errorPacket = _connection.PacketCreator.CreateConnectionClosePacket(ErrorCode.FLOW_CONTROL_ERROR, "Maximum stream data transfer reached."); _connection.SendData(errorPacket); _connection.TerminateConnection(); return; } if (State == StreamState.SizeKnown && IsStreamFull()) { _connection.DataReceived(this); State = StreamState.DataRecvd; } }