Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / quic / p2p / quic_p2p_stream.cc
blobaf31f3cff43d5edba2ed165bcbe51c4293d79098
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"
12 namespace net {
14 QuicP2PStream::QuicP2PStream(QuicStreamId id, QuicSession* session)
15 : ReliableQuicStream(id, session) {}
17 QuicP2PStream::~QuicP2PStream() {}
19 void QuicP2PStream::OnDataAvailable() {
20 DCHECK(delegate_);
22 struct iovec iov;
23 while (true) {
24 if (sequencer()->GetReadableRegions(&iov, 1) != 1) {
25 // No more data to read.
26 break;
28 delegate_->OnDataReceived(reinterpret_cast<const char*>(iov.iov_base),
29 iov.iov_len);
30 sequencer()->MarkConsumed(iov.iov_len);
34 void QuicP2PStream::OnClose() {
35 ReliableQuicStream::OnClose();
37 if (delegate_) {
38 Delegate* delegate = delegate_;
39 delegate_ = nullptr;
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 {
53 return priority_;
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()) {
67 return data.size();
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));
77 delegate_ = delegate;
80 } // namespace net