blob: 8002b0c182bbe05ba403554800ef4317110e7def [file] [log] [blame]
renjietang96fc2282019-06-12 09:51:35 -07001// Copyright 2019 The Chromium Authors. All rights reserved.
renjietangfee2cc32019-04-05 11:32:07 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/third_party/quiche/src/quic/core/http/quic_send_control_stream.h"
6
7#include "net/third_party/quiche/src/quic/core/http/quic_spdy_session.h"
renjietang3a1bb802019-06-11 10:42:41 -07008#include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h"
renjietangfee2cc32019-04-05 11:32:07 -07009
10namespace quic {
11
12QuicSendControlStream::QuicSendControlStream(QuicStreamId id,
13 QuicSpdySession* session)
14 : QuicStream(id, session, /*is_static = */ true, WRITE_UNIDIRECTIONAL),
15 settings_sent_(false) {}
16
17void QuicSendControlStream::OnStreamReset(const QuicRstStreamFrame& frame) {
18 // TODO(renjietang) Change the error code to H/3 specific
19 // HTTP_CLOSED_CRITICAL_STREAM.
20 session()->connection()->CloseConnection(
21 QUIC_INVALID_STREAM_ID, "Attempt to reset send control stream",
22 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
23}
24
25void QuicSendControlStream::SendSettingsFrame(const SettingsFrame& settings) {
26 DCHECK(!settings_sent_);
renjietang3a1bb802019-06-11 10:42:41 -070027
fayanga4b37b22019-06-18 13:37:47 -070028 QuicConnection::ScopedPacketFlusher flusher(session()->connection());
renjietang3a1bb802019-06-11 10:42:41 -070029 // Send the stream type on so the peer knows about this stream.
30 char data[sizeof(kControlStream)];
31 QuicDataWriter writer(QUIC_ARRAYSIZE(data), data);
32 writer.WriteVarInt62(kControlStream);
33 WriteOrBufferData(QuicStringPiece(writer.data(), writer.length()), false,
34 nullptr);
35
renjietangfee2cc32019-04-05 11:32:07 -070036 std::unique_ptr<char[]> buffer;
37 QuicByteCount frame_length =
38 encoder_.SerializeSettingsFrame(settings, &buffer);
39 WriteOrBufferData(QuicStringPiece(buffer.get(), frame_length),
40 /*fin = */ false, nullptr);
41 settings_sent_ = true;
42}
43
44} // namespace quic