renjietang | 96fc228 | 2019-06-12 09:51:35 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
renjietang | fee2cc3 | 2019-04-05 11:32:07 -0700 | [diff] [blame] | 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 "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" |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 8 | #include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h" |
renjietang | fee2cc3 | 2019-04-05 11:32:07 -0700 | [diff] [blame] | 9 | |
| 10 | namespace quic { |
| 11 | |
| 12 | QuicSendControlStream::QuicSendControlStream(QuicStreamId id, |
| 13 | QuicSpdySession* session) |
| 14 | : QuicStream(id, session, /*is_static = */ true, WRITE_UNIDIRECTIONAL), |
| 15 | settings_sent_(false) {} |
| 16 | |
| 17 | void 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 | |
| 25 | void QuicSendControlStream::SendSettingsFrame(const SettingsFrame& settings) { |
| 26 | DCHECK(!settings_sent_); |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 27 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 28 | QuicConnection::ScopedPacketFlusher flusher(session()->connection()); |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 29 | // 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 | |
renjietang | fee2cc3 | 2019-04-05 11:32:07 -0700 | [diff] [blame] | 36 | 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 |