| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quartc/quartc_stream.h" | 5 #include "net/quic/quartc/quartc_stream.h" |
| 6 | 6 |
| 7 namespace net { | 7 namespace net { |
| 8 | 8 |
| 9 QuartcStream::QuartcStream(QuicStreamId id, QuicSession* session) | 9 QuartcStream::QuartcStream(QuicStreamId id, QuicSession* session) |
| 10 : ReliableQuicStream(id, session) {} | 10 : QuicStream(id, session) {} |
| 11 QuartcStream::~QuartcStream() {} | 11 QuartcStream::~QuartcStream() {} |
| 12 | 12 |
| 13 void QuartcStream::OnDataAvailable() { | 13 void QuartcStream::OnDataAvailable() { |
| 14 struct iovec iov; | 14 struct iovec iov; |
| 15 while (sequencer()->GetReadableRegions(&iov, 1) == 1) { | 15 while (sequencer()->GetReadableRegions(&iov, 1) == 1) { |
| 16 DCHECK(delegate_); | 16 DCHECK(delegate_); |
| 17 delegate_->OnReceived(this, reinterpret_cast<const char*>(iov.iov_base), | 17 delegate_->OnReceived(this, reinterpret_cast<const char*>(iov.iov_base), |
| 18 iov.iov_len); | 18 iov.iov_len); |
| 19 sequencer()->MarkConsumed(iov.iov_len); | 19 sequencer()->MarkConsumed(iov.iov_len); |
| 20 } | 20 } |
| 21 // All the data has been received if the sequencer is closed. | 21 // All the data has been received if the sequencer is closed. |
| 22 // Notify the delegate by calling the callback function one more time with | 22 // Notify the delegate by calling the callback function one more time with |
| 23 // iov_len = 0. | 23 // iov_len = 0. |
| 24 if (sequencer()->IsClosed()) { | 24 if (sequencer()->IsClosed()) { |
| 25 delegate_->OnReceived(this, reinterpret_cast<const char*>(iov.iov_base), 0); | 25 delegate_->OnReceived(this, reinterpret_cast<const char*>(iov.iov_base), 0); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 void QuartcStream::OnClose() { | 29 void QuartcStream::OnClose() { |
| 30 ReliableQuicStream::OnClose(); | 30 QuicStream::OnClose(); |
| 31 DCHECK(delegate_); | 31 DCHECK(delegate_); |
| 32 delegate_->OnClose(this, connection_error()); | 32 delegate_->OnClose(this, connection_error()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void QuartcStream::OnCanWrite() { | 35 void QuartcStream::OnCanWrite() { |
| 36 ReliableQuicStream::OnCanWrite(); | 36 QuicStream::OnCanWrite(); |
| 37 DCHECK(delegate_); | 37 DCHECK(delegate_); |
| 38 delegate_->OnBufferedAmountDecrease(this); | 38 delegate_->OnBufferedAmountDecrease(this); |
| 39 } | 39 } |
| 40 | 40 |
| 41 uint32_t QuartcStream::stream_id() { | 41 uint32_t QuartcStream::stream_id() { |
| 42 return id(); | 42 return id(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 uint64_t QuartcStream::buffered_amount() { | 45 uint64_t QuartcStream::buffered_amount() { |
| 46 return queued_data_bytes(); | 46 return queued_data_bytes(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool QuartcStream::fin_sent() { | 49 bool QuartcStream::fin_sent() { |
| 50 return ReliableQuicStream::fin_sent(); | 50 return QuicStream::fin_sent(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void QuartcStream::Write(const char* data, | 53 void QuartcStream::Write(const char* data, |
| 54 size_t size, | 54 size_t size, |
| 55 const WriteParameters& param) { | 55 const WriteParameters& param) { |
| 56 WriteOrBufferData(base::StringPiece(data, size), param.fin, nullptr); | 56 WriteOrBufferData(base::StringPiece(data, size), param.fin, nullptr); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void QuartcStream::Close() { | 59 void QuartcStream::Close() { |
| 60 ReliableQuicStream::session()->CloseStream(id()); | 60 QuicStream::session()->CloseStream(id()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void QuartcStream::SetDelegate(QuartcStreamInterface::Delegate* delegate) { | 63 void QuartcStream::SetDelegate(QuartcStreamInterface::Delegate* delegate) { |
| 64 if (delegate_) { | 64 if (delegate_) { |
| 65 LOG(WARNING) << "The delegate for Stream " << id() | 65 LOG(WARNING) << "The delegate for Stream " << id() |
| 66 << " has already been set."; | 66 << " has already been set."; |
| 67 } | 67 } |
| 68 delegate_ = delegate; | 68 delegate_ = delegate; |
| 69 DCHECK(delegate_); | 69 DCHECK(delegate_); |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace net | 72 } // namespace net |
| OLD | NEW |