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

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

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 28 matching lines...) Expand all
39 39
40 virtual QuicTime OnAlarm() OVERRIDE { 40 virtual QuicTime OnAlarm() OVERRIDE {
41 return writer_->ReleaseOldPackets(); 41 return writer_->ReleaseOldPackets();
42 } 42 }
43 43
44 private: 44 private:
45 PacketDroppingTestWriter* writer_; 45 PacketDroppingTestWriter* writer_;
46 }; 46 };
47 47
48 PacketDroppingTestWriter::PacketDroppingTestWriter() 48 PacketDroppingTestWriter::PacketDroppingTestWriter()
49 : clock_(NULL), 49 : clock_(nullptr),
50 cur_buffer_size_(0), 50 cur_buffer_size_(0),
51 config_mutex_(), 51 config_mutex_(),
52 fake_packet_loss_percentage_(0), 52 fake_packet_loss_percentage_(0),
53 fake_blocked_socket_percentage_(0), 53 fake_blocked_socket_percentage_(0),
54 fake_packet_reorder_percentage_(0), 54 fake_packet_reorder_percentage_(0),
55 fake_packet_delay_(QuicTime::Delta::Zero()), 55 fake_packet_delay_(QuicTime::Delta::Zero()),
56 fake_bandwidth_(QuicBandwidth::Zero()), 56 fake_bandwidth_(QuicBandwidth::Zero()),
57 buffer_size_(0) { 57 buffer_size_(0) {
58 uint32 seed = base::RandInt(0, std::numeric_limits<int32>::max()); 58 uint32 seed = base::RandInt(0, std::numeric_limits<int32>::max());
59 VLOG(1) << "Seeding packet loss with " << seed; 59 VLOG(1) << "Seeding packet loss with " << seed;
(...skipping 23 matching lines...) Expand all
83 base::AutoLock locked(config_mutex_); 83 base::AutoLock locked(config_mutex_);
84 if (fake_packet_loss_percentage_ > 0 && 84 if (fake_packet_loss_percentage_ > 0 &&
85 simple_random_.RandUint64() % 100 < 85 simple_random_.RandUint64() % 100 <
86 static_cast<uint64>(fake_packet_loss_percentage_)) { 86 static_cast<uint64>(fake_packet_loss_percentage_)) {
87 DVLOG(1) << "Dropping packet."; 87 DVLOG(1) << "Dropping packet.";
88 return WriteResult(WRITE_STATUS_OK, buf_len); 88 return WriteResult(WRITE_STATUS_OK, buf_len);
89 } 89 }
90 if (fake_blocked_socket_percentage_ > 0 && 90 if (fake_blocked_socket_percentage_ > 0 &&
91 simple_random_.RandUint64() % 100 < 91 simple_random_.RandUint64() % 100 <
92 static_cast<uint64>(fake_blocked_socket_percentage_)) { 92 static_cast<uint64>(fake_blocked_socket_percentage_)) {
93 CHECK(on_can_write_.get() != NULL); 93 CHECK(on_can_write_.get() != nullptr);
94 DVLOG(1) << "Blocking socket."; 94 DVLOG(1) << "Blocking socket.";
95 if (!write_unblocked_alarm_->IsSet()) { 95 if (!write_unblocked_alarm_->IsSet()) {
96 // Set the alarm to fire immediately. 96 // Set the alarm to fire immediately.
97 write_unblocked_alarm_->Set(clock_->ApproximateNow()); 97 write_unblocked_alarm_->Set(clock_->ApproximateNow());
98 } 98 }
99 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); 99 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN);
100 } 100 }
101 101
102 if (!fake_packet_delay_.IsZero() || !fake_bandwidth_.IsZero()) { 102 if (!fake_packet_delay_.IsZero() || !fake_bandwidth_.IsZero()) {
103 if (buffer_size_ > 0 && buf_len + cur_buffer_size_ > buffer_size_) { 103 if (buffer_size_ > 0 && buf_len + cur_buffer_size_ > buffer_size_) {
(...skipping 23 matching lines...) Expand all
127 } 127 }
128 128
129 return WriteResult(WRITE_STATUS_OK, buf_len); 129 return WriteResult(WRITE_STATUS_OK, buf_len);
130 } 130 }
131 131
132 return QuicPacketWriterWrapper::WritePacket( 132 return QuicPacketWriterWrapper::WritePacket(
133 buffer, buf_len, self_address, peer_address); 133 buffer, buf_len, self_address, peer_address);
134 } 134 }
135 135
136 bool PacketDroppingTestWriter::IsWriteBlocked() const { 136 bool PacketDroppingTestWriter::IsWriteBlocked() const {
137 if (write_unblocked_alarm_.get() != NULL && write_unblocked_alarm_->IsSet()) { 137 if (write_unblocked_alarm_.get() != nullptr &&
138 write_unblocked_alarm_->IsSet()) {
138 return true; 139 return true;
139 } 140 }
140 return QuicPacketWriterWrapper::IsWriteBlocked(); 141 return QuicPacketWriterWrapper::IsWriteBlocked();
141 } 142 }
142 143
143 void PacketDroppingTestWriter::SetWritable() { 144 void PacketDroppingTestWriter::SetWritable() {
144 if (write_unblocked_alarm_.get() != NULL && write_unblocked_alarm_->IsSet()) { 145 if (write_unblocked_alarm_.get() != nullptr &&
146 write_unblocked_alarm_->IsSet()) {
145 write_unblocked_alarm_->Cancel(); 147 write_unblocked_alarm_->Cancel();
146 } 148 }
147 QuicPacketWriterWrapper::SetWritable(); 149 QuicPacketWriterWrapper::SetWritable();
148 } 150 }
149 151
150 QuicTime PacketDroppingTestWriter::ReleaseNextPacket() { 152 QuicTime PacketDroppingTestWriter::ReleaseNextPacket() {
151 if (delayed_packets_.empty()) { 153 if (delayed_packets_.empty()) {
152 return QuicTime::Zero(); 154 return QuicTime::Zero();
153 } 155 }
154 base::AutoLock locked(config_mutex_); 156 base::AutoLock locked(config_mutex_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 : buffer(buffer, buf_len), 206 : buffer(buffer, buf_len),
205 self_address(self_address), 207 self_address(self_address),
206 peer_address(peer_address), 208 peer_address(peer_address),
207 send_time(send_time) {} 209 send_time(send_time) {}
208 210
209 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {} 211 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {}
210 212
211 } // namespace test 213 } // namespace test
212 } // namespace tools 214 } // namespace tools
213 } // namespace net 215 } // 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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698