1 // Copyright 2019 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_send_stream.h"
6
7 #include "absl/base/macros.h"
8 #include "absl/strings/string_view.h"
9 #include "quiche/quic/core/quic_session.h"
10
11 namespace quic {
QpackSendStream(QuicStreamId id,QuicSession * session,uint64_t http3_stream_type)12 QpackSendStream::QpackSendStream(QuicStreamId id, QuicSession* session,
13 uint64_t http3_stream_type)
14 : QuicStream(id, session, /*is_static = */ true, WRITE_UNIDIRECTIONAL),
15 http3_stream_type_(http3_stream_type),
16 stream_type_sent_(false) {}
17
OnStreamReset(const QuicRstStreamFrame &)18 void QpackSendStream::OnStreamReset(const QuicRstStreamFrame& /*frame*/) {
19 QUIC_BUG(quic_bug_10805_1)
20 << "OnStreamReset() called for write unidirectional stream.";
21 }
22
OnStopSending(QuicResetStreamError)23 bool QpackSendStream::OnStopSending(QuicResetStreamError /* code */) {
24 stream_delegate()->OnStreamError(
25 QUIC_HTTP_CLOSED_CRITICAL_STREAM,
26 "STOP_SENDING received for QPACK send stream");
27 return false;
28 }
29
WriteStreamData(absl::string_view data)30 void QpackSendStream::WriteStreamData(absl::string_view data) {
31 QuicConnection::ScopedPacketFlusher flusher(session()->connection());
32 MaybeSendStreamType();
33 WriteOrBufferData(data, false, nullptr);
34 }
35
NumBytesBuffered() const36 uint64_t QpackSendStream::NumBytesBuffered() const {
37 return QuicStream::BufferedDataBytes();
38 }
39
MaybeSendStreamType()40 void QpackSendStream::MaybeSendStreamType() {
41 if (!stream_type_sent_) {
42 char type[sizeof(http3_stream_type_)];
43 QuicDataWriter writer(ABSL_ARRAYSIZE(type), type);
44 writer.WriteVarInt62(http3_stream_type_);
45 WriteOrBufferData(absl::string_view(writer.data(), writer.length()), false,
46 nullptr);
47 stream_type_sent_ = true;
48 }
49 }
50
51 } // namespace quic
52