1 // Copyright 2015 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.
5 #include "net/quic/p2p/quic_p2p_stream.h"
7 #include "base/callback_helpers.h"
8 #include "net/base/net_errors.h"
9 #include "net/quic/quic_session.h"
10 #include "net/quic/quic_write_blocked_list.h"
14 QuicP2PStream::QuicP2PStream(QuicStreamId id
, QuicSession
* session
)
15 : ReliableQuicStream(id
, session
) {}
17 QuicP2PStream::~QuicP2PStream() {}
19 void QuicP2PStream::OnDataAvailable() {
24 if (sequencer()->GetReadableRegions(&iov
, 1) != 1) {
25 // No more data to read.
28 delegate_
->OnDataReceived(reinterpret_cast<const char*>(iov
.iov_base
),
30 sequencer()->MarkConsumed(iov
.iov_len
);
34 void QuicP2PStream::OnClose() {
35 ReliableQuicStream::OnClose();
38 Delegate
* delegate
= delegate_
;
40 delegate
->OnClose(connection_error());
44 void QuicP2PStream::OnCanWrite() {
45 ReliableQuicStream::OnCanWrite();
47 if (!HasBufferedData() && !write_callback_
.is_null()) {
48 base::ResetAndReturn(&write_callback_
).Run(last_write_size_
);
52 QuicPriority
QuicP2PStream::EffectivePriority() const {
56 void QuicP2PStream::WriteHeader(base::StringPiece data
) {
57 WriteOrBufferData(data
, false, nullptr);
60 int QuicP2PStream::Write(base::StringPiece data
,
61 const CompletionCallback
& callback
) {
62 DCHECK(write_callback_
.is_null());
64 // Writes the data, or buffers it.
65 WriteOrBufferData(data
, false, nullptr);
66 if (!HasBufferedData()) {
70 write_callback_
= callback
;
71 last_write_size_
= data
.size();
72 return ERR_IO_PENDING
;
75 void QuicP2PStream::SetDelegate(QuicP2PStream::Delegate
* delegate
) {
76 DCHECK(!(delegate_
&& delegate
));