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

Side by Side Diff: net/tools/quic/test_tools/packet_dropping_test_writer.cc

Issue 2125303002: Use overloaded operators with QuicTime for addition, subtraction and scalar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126402784
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tools/quic/test_tools/packet_dropping_test_writer.h" 5 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "net/tools/quic/quic_epoll_connection_helper.h" 10 #include "net/tools/quic/quic_epoll_connection_helper.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 if (!fake_packet_delay_.IsZero() || !fake_bandwidth_.IsZero()) { 113 if (!fake_packet_delay_.IsZero() || !fake_bandwidth_.IsZero()) {
114 if (buffer_size_ > 0 && buf_len + cur_buffer_size_ > buffer_size_) { 114 if (buffer_size_ > 0 && buf_len + cur_buffer_size_ > buffer_size_) {
115 // Drop packets which do not fit into the buffer. 115 // Drop packets which do not fit into the buffer.
116 DVLOG(1) << "Dropping packet because the buffer is full."; 116 DVLOG(1) << "Dropping packet because the buffer is full.";
117 return WriteResult(WRITE_STATUS_OK, buf_len); 117 return WriteResult(WRITE_STATUS_OK, buf_len);
118 } 118 }
119 119
120 // Queue it to be sent. 120 // Queue it to be sent.
121 QuicTime send_time = clock_->ApproximateNow().Add(fake_packet_delay_); 121 QuicTime send_time = clock_->ApproximateNow() + fake_packet_delay_;
122 if (!fake_bandwidth_.IsZero()) { 122 if (!fake_bandwidth_.IsZero()) {
123 // Calculate a time the bandwidth limit would impose. 123 // Calculate a time the bandwidth limit would impose.
124 QuicTime::Delta bandwidth_delay = QuicTime::Delta::FromMicroseconds( 124 QuicTime::Delta bandwidth_delay = QuicTime::Delta::FromMicroseconds(
125 (buf_len * kNumMicrosPerSecond) / fake_bandwidth_.ToBytesPerSecond()); 125 (buf_len * kNumMicrosPerSecond) / fake_bandwidth_.ToBytesPerSecond());
126 send_time = delayed_packets_.empty() 126 send_time = delayed_packets_.empty()
127 ? send_time.Add(bandwidth_delay) 127 ? send_time + bandwidth_delay
128 : delayed_packets_.back().send_time.Add(bandwidth_delay); 128 : delayed_packets_.back().send_time + bandwidth_delay;
129 } 129 }
130 std::unique_ptr<PerPacketOptions> delayed_options; 130 std::unique_ptr<PerPacketOptions> delayed_options;
131 if (options != nullptr) { 131 if (options != nullptr) {
132 delayed_options.reset(options->Clone()); 132 delayed_options.reset(options->Clone());
133 } 133 }
134 delayed_packets_.push_back( 134 delayed_packets_.push_back(
135 DelayedWrite(buffer, buf_len, self_address, peer_address, 135 DelayedWrite(buffer, buf_len, self_address, peer_address,
136 std::move(delayed_options), send_time)); 136 std::move(delayed_options), send_time));
137 cur_buffer_size_ += buf_len; 137 cur_buffer_size_ += buf_len;
138 138
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // IPAddress has no move assignment operator. 237 // IPAddress has no move assignment operator.
238 // 238 //
239 // PacketDroppingTestWriter::DelayedWrite& 239 // PacketDroppingTestWriter::DelayedWrite&
240 // PacketDroppingTestWriter::DelayedWrite::operator=( 240 // PacketDroppingTestWriter::DelayedWrite::operator=(
241 // PacketDroppingTestWriter::DelayedWrite&& other) = default; 241 // PacketDroppingTestWriter::DelayedWrite&& other) = default;
242 242
243 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {} 243 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {}
244 244
245 } // namespace test 245 } // namespace test
246 } // namespace net 246 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_time_wait_list_manager_test.cc ('k') | net/tools/quic/test_tools/quic_test_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698