• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/qpack/qpack_decoder_stream_sender.h"
6 
7 #include <cstddef>
8 #include <limits>
9 #include <string>
10 #include <utility>
11 
12 #include "absl/strings/string_view.h"
13 #include "quiche/quic/core/qpack/qpack_instructions.h"
14 #include "quiche/quic/platform/api/quic_flag_utils.h"
15 #include "quiche/quic/platform/api/quic_logging.h"
16 
17 namespace quic {
18 
QpackDecoderStreamSender()19 QpackDecoderStreamSender::QpackDecoderStreamSender() : delegate_(nullptr) {}
20 
SendInsertCountIncrement(uint64_t increment)21 void QpackDecoderStreamSender::SendInsertCountIncrement(uint64_t increment) {
22   instruction_encoder_.Encode(
23       QpackInstructionWithValues::InsertCountIncrement(increment), &buffer_);
24 }
25 
SendHeaderAcknowledgement(QuicStreamId stream_id)26 void QpackDecoderStreamSender::SendHeaderAcknowledgement(
27     QuicStreamId stream_id) {
28   instruction_encoder_.Encode(
29       QpackInstructionWithValues::HeaderAcknowledgement(stream_id), &buffer_);
30 }
31 
SendStreamCancellation(QuicStreamId stream_id)32 void QpackDecoderStreamSender::SendStreamCancellation(QuicStreamId stream_id) {
33   instruction_encoder_.Encode(
34       QpackInstructionWithValues::StreamCancellation(stream_id), &buffer_);
35 }
36 
Flush()37 void QpackDecoderStreamSender::Flush() {
38   if (buffer_.empty() || delegate_ == nullptr) {
39     return;
40   }
41   if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data2)) {
42     QUIC_RESTART_FLAG_COUNT_N(quic_opport_bundle_qpack_decoder_data2, 3, 4);
43     // Swap buffer_ before calling WriteStreamData, which might result in a
44     // reentrant call to `Flush()`.
45     std::string copy;
46     std::swap(copy, buffer_);
47     delegate_->WriteStreamData(copy);
48     return;
49   }
50   delegate_->WriteStreamData(buffer_);
51   buffer_.clear();
52 }
53 
54 }  // namespace quic
55