Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: net/quic/core/quic_stream_send_buffer.cc

Issue 2963763003: In QUIC, send data is copied to streams rather than frames. Protected by FLAGS_quic_reloadable_flag… (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_stream_send_buffer.h ('k') | net/quic/core/quic_stream_send_buffer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017 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.
4
5 #include <algorithm>
6
7 #include "net/quic/core/crypto/crypto_protocol.h"
8 #include "net/quic/core/quic_data_writer.h"
9 #include "net/quic/core/quic_stream_send_buffer.h"
10 #include "net/quic/core/quic_utils.h"
11 #include "net/quic/platform/api/quic_bug_tracker.h"
12
13 namespace net {
14
15 QuicStreamDataSlice::QuicStreamDataSlice(UniqueStreamBuffer data,
16 QuicStreamOffset offset,
17 QuicByteCount data_length)
18 : data(std::move(data)),
19 offset(offset),
20 data_length(data_length),
21 data_length_waiting_for_acks(data_length) {}
22
23 QuicStreamDataSlice::~QuicStreamDataSlice() {}
24
25 QuicStreamSendBuffer::QuicStreamSendBuffer(QuicBufferAllocator* allocator)
26 : allocator_(allocator) {}
27
28 QuicStreamSendBuffer::~QuicStreamSendBuffer() {}
29
30 void QuicStreamSendBuffer::SaveStreamData(QuicIOVector iov,
31 size_t iov_offset,
32 QuicStreamOffset offset,
33 QuicByteCount data_length) {
34 DCHECK_LE(iov_offset + data_length, iov.total_length);
35 UniqueStreamBuffer buffer = NewStreamBuffer(allocator_, data_length);
36 QuicUtils::CopyToBuffer(iov, iov_offset, data_length, buffer.get());
37 send_buffer_.emplace_back(std::move(buffer), offset, data_length);
38 }
39
40 bool QuicStreamSendBuffer::WriteStreamData(QuicStreamOffset offset,
41 QuicByteCount data_length,
42 QuicDataWriter* writer) {
43 for (const QuicStreamDataSlice& slice : send_buffer_) {
44 if (offset < slice.offset) {
45 break;
46 }
47 if (offset >= slice.offset + slice.data_length) {
48 continue;
49 }
50 QuicByteCount slice_offset = offset - slice.offset;
51 QuicByteCount copy_length =
52 std::min(data_length, slice.data_length - slice_offset);
53 if (!writer->WriteBytes(slice.data.get() + slice_offset, copy_length)) {
54 return false;
55 }
56 offset += copy_length;
57 data_length -= copy_length;
58 }
59
60 return data_length == 0;
61 }
62
63 void QuicStreamSendBuffer::RemoveStreamFrame(QuicStreamOffset offset,
64 QuicByteCount data_length) {
65 DCHECK_LT(0u, data_length);
66 for (QuicStreamDataSlice& slice : send_buffer_) {
67 if (offset < slice.offset) {
68 break;
69 }
70 if (offset >= slice.offset + slice.data_length) {
71 continue;
72 }
73 QuicByteCount slice_offset = offset - slice.offset;
74 QuicByteCount removing_length =
75 std::min(data_length, slice.data_length - slice_offset);
76 slice.data_length_waiting_for_acks -= removing_length;
77 offset += removing_length;
78 data_length -= removing_length;
79 }
80 DCHECK_EQ(0u, data_length);
81
82 // Remove data which stops waiting for acks. Please note, data can be
83 // acked out of order, but send buffer is cleaned up in order.
84 while (!send_buffer_.empty() &&
85 send_buffer_.front().data_length_waiting_for_acks == 0) {
86 send_buffer_.pop_front();
87 }
88 }
89
90 size_t QuicStreamSendBuffer::size() const {
91 return send_buffer_.size();
92 }
93
94 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_stream_send_buffer.h ('k') | net/quic/core/quic_stream_send_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698