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

Side by Side Diff: net/tools/quic/quic_time_wait_list_manager.cc

Issue 1413713005: Minor refactor of QuicTimeWaitListManager::ProcessPacket to use early returns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@105358957
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/quic_time_wait_list_manager.h" 5 #include "net/tools/quic/quic_time_wait_list_manager.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 const QuicEncryptedPacket& /*packet*/) { 159 const QuicEncryptedPacket& /*packet*/) {
160 DCHECK(IsConnectionIdInTimeWait(connection_id)); 160 DCHECK(IsConnectionIdInTimeWait(connection_id));
161 DVLOG(1) << "Processing " << connection_id << " in time wait state."; 161 DVLOG(1) << "Processing " << connection_id << " in time wait state.";
162 // TODO(satyamshekhar): Think about handling packets from different client 162 // TODO(satyamshekhar): Think about handling packets from different client
163 // addresses. 163 // addresses.
164 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); 164 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
165 DCHECK(it != connection_id_map_.end()); 165 DCHECK(it != connection_id_map_.end());
166 // Increment the received packet count. 166 // Increment the received packet count.
167 ConnectionIdData* connection_data = &it->second; 167 ConnectionIdData* connection_data = &it->second;
168 ++(connection_data->num_packets); 168 ++(connection_data->num_packets);
169
169 if (!ShouldSendResponse(connection_data->num_packets)) { 170 if (!ShouldSendResponse(connection_data->num_packets)) {
170 return; 171 return;
171 } 172 }
173
172 if (connection_data->close_packet) { 174 if (connection_data->close_packet) {
173 QueuedPacket* queued_packet = new QueuedPacket( 175 QueuedPacket* queued_packet = new QueuedPacket(
174 server_address, client_address, connection_data->close_packet->Clone()); 176 server_address, client_address, connection_data->close_packet->Clone());
175 // Takes ownership of the packet. 177 // Takes ownership of the packet.
176 SendOrQueuePacket(queued_packet); 178 SendOrQueuePacket(queued_packet);
177 } else if (!connection_data->connection_rejected_statelessly) { 179 return;
178 SendPublicReset(server_address, client_address, connection_id, 180 }
179 packet_number); 181
180 } else { 182 if (connection_data->connection_rejected_statelessly) {
181 DVLOG(3) << "Time wait list not sending response for connection " 183 DVLOG(3) << "Time wait list not sending response for connection "
182 << connection_id << " due to previous stateless reject."; 184 << connection_id << " due to previous stateless reject.";
185 return;
183 } 186 }
187
188 SendPublicReset(server_address, client_address, connection_id, packet_number);
184 } 189 }
185 190
186 // Returns true if the number of packets received for this connection_id is a 191 // Returns true if the number of packets received for this connection_id is a
187 // power of 2 to throttle the number of public reset packets we send to a 192 // power of 2 to throttle the number of public reset packets we send to a
188 // client. 193 // client.
189 bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) { 194 bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) {
190 return (received_packet_count & (received_packet_count - 1)) == 0; 195 return (received_packet_count & (received_packet_count - 1)) == 0;
191 } 196 }
192 197
193 void QuicTimeWaitListManager::SendPublicReset( 198 void QuicTimeWaitListManager::SendPublicReset(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return; 311 return;
307 } 312 }
308 while (num_connections() >= 313 while (num_connections() >=
309 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { 314 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) {
310 MaybeExpireOldestConnection(QuicTime::Infinite()); 315 MaybeExpireOldestConnection(QuicTime::Infinite());
311 } 316 }
312 } 317 }
313 318
314 } // namespace tools 319 } // namespace tools
315 } // namespace net 320 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698