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

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

Issue 2561913003: Create a QUIC wrapper around a mutex and a mutex lock. (Closed)
Patch Set: fix Created 4 years 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/platform/impl/quic_socket_utils.h" 10 #include "net/tools/quic/platform/impl/quic_socket_utils.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 WriteResult PacketDroppingTestWriter::WritePacket( 78 WriteResult PacketDroppingTestWriter::WritePacket(
79 const char* buffer, 79 const char* buffer,
80 size_t buf_len, 80 size_t buf_len,
81 const QuicIpAddress& self_address, 81 const QuicIpAddress& self_address,
82 const QuicSocketAddress& peer_address, 82 const QuicSocketAddress& peer_address,
83 PerPacketOptions* options) { 83 PerPacketOptions* options) {
84 ++num_calls_to_write_; 84 ++num_calls_to_write_;
85 ReleaseOldPackets(); 85 ReleaseOldPackets();
86 86
87 base::AutoLock locked(config_mutex_); 87 QuicReaderMutexLock lock(&config_mutex_);
88 if (fake_drop_first_n_packets_ > 0 && 88 if (fake_drop_first_n_packets_ > 0 &&
89 num_calls_to_write_ <= 89 num_calls_to_write_ <=
90 static_cast<uint64_t>(fake_drop_first_n_packets_)) { 90 static_cast<uint64_t>(fake_drop_first_n_packets_)) {
91 DVLOG(1) << "Dropping first " << fake_drop_first_n_packets_ 91 DVLOG(1) << "Dropping first " << fake_drop_first_n_packets_
92 << " packets (packet number " << num_calls_to_write_ << ")"; 92 << " packets (packet number " << num_calls_to_write_ << ")";
93 return WriteResult(WRITE_STATUS_OK, buf_len); 93 return WriteResult(WRITE_STATUS_OK, buf_len);
94 } 94 }
95 if (fake_packet_loss_percentage_ > 0 && 95 if (fake_packet_loss_percentage_ > 0 &&
96 simple_random_.RandUint64() % 100 < 96 simple_random_.RandUint64() % 100 <
97 static_cast<uint64_t>(fake_packet_loss_percentage_)) { 97 static_cast<uint64_t>(fake_packet_loss_percentage_)) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 write_unblocked_alarm_->IsSet()) { 161 write_unblocked_alarm_->IsSet()) {
162 write_unblocked_alarm_->Cancel(); 162 write_unblocked_alarm_->Cancel();
163 } 163 }
164 QuicPacketWriterWrapper::SetWritable(); 164 QuicPacketWriterWrapper::SetWritable();
165 } 165 }
166 166
167 QuicTime PacketDroppingTestWriter::ReleaseNextPacket() { 167 QuicTime PacketDroppingTestWriter::ReleaseNextPacket() {
168 if (delayed_packets_.empty()) { 168 if (delayed_packets_.empty()) {
169 return QuicTime::Zero(); 169 return QuicTime::Zero();
170 } 170 }
171 base::AutoLock locked(config_mutex_); 171 QuicReaderMutexLock lock(&config_mutex_);
172 DelayedPacketList::iterator iter = delayed_packets_.begin(); 172 DelayedPacketList::iterator iter = delayed_packets_.begin();
173 // Determine if we should re-order. 173 // Determine if we should re-order.
174 if (delayed_packets_.size() > 1 && fake_packet_reorder_percentage_ > 0 && 174 if (delayed_packets_.size() > 1 && fake_packet_reorder_percentage_ > 0 &&
175 simple_random_.RandUint64() % 100 < 175 simple_random_.RandUint64() % 100 <
176 static_cast<uint64_t>(fake_packet_reorder_percentage_)) { 176 static_cast<uint64_t>(fake_packet_reorder_percentage_)) {
177 DVLOG(1) << "Reordering packets."; 177 DVLOG(1) << "Reordering packets.";
178 ++iter; 178 ++iter;
179 // Swap the send times when re-ordering packets. 179 // Swap the send times when re-ordering packets.
180 delayed_packets_.begin()->send_time = iter->send_time; 180 delayed_packets_.begin()->send_time = iter->send_time;
181 } 181 }
(...skipping 55 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/test_tools/packet_dropping_test_writer.h ('k') | net/tools/quic/test_tools/quic_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698