1 // Copyright 2022 The Chromium Authors
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/websockets/websocket_quic_spdy_stream.h"
6 #include "net/base/io_buffer.h"
7 #include "net/http/http_status_code.h"
8 #include "net/third_party/quiche/src/quiche/quic/core/http/spdy_utils.h"
9
10 namespace net {
11
WebSocketQuicSpdyStream(quic::QuicStreamId id,quic::QuicSpdyClientSessionBase * session,quic::StreamType type)12 WebSocketQuicSpdyStream::WebSocketQuicSpdyStream(
13 quic::QuicStreamId id,
14 quic::QuicSpdyClientSessionBase* session,
15 quic::StreamType type)
16 : quic::QuicSpdyStream(id, session, type) {}
17
~WebSocketQuicSpdyStream()18 WebSocketQuicSpdyStream::~WebSocketQuicSpdyStream() {
19 if (delegate_) {
20 delegate_->ClearStream();
21 }
22 }
23
OnBodyAvailable()24 void WebSocketQuicSpdyStream::OnBodyAvailable() {
25 if (delegate_) {
26 delegate_->OnBodyAvailable();
27 }
28 }
29
OnInitialHeadersComplete(bool fin,size_t frame_len,const quic::QuicHeaderList & header_list)30 void WebSocketQuicSpdyStream::OnInitialHeadersComplete(
31 bool fin,
32 size_t frame_len,
33 const quic::QuicHeaderList& header_list) {
34 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len, header_list);
35 if (delegate_) {
36 delegate_->OnInitialHeadersComplete(fin, frame_len, header_list);
37 }
38 }
39
Read(IOBuffer * buf,int buf_len)40 int WebSocketQuicSpdyStream::Read(IOBuffer* buf, int buf_len) {
41 DCHECK_GT(buf_len, 0);
42 DCHECK(buf->data());
43
44 if (IsDoneReading()) {
45 return 0; // EOF
46 }
47
48 if (!HasBytesToRead()) {
49 return ERR_IO_PENDING;
50 }
51
52 iovec iov;
53 iov.iov_base = buf->data();
54 iov.iov_len = buf_len;
55 size_t bytes_read = Readv(&iov, 1);
56 // Since HasBytesToRead is true, Readv() must have read some data.
57 DCHECK_NE(0u, bytes_read);
58 return bytes_read;
59 }
60
61 } // namespace net
62