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

Side by Side Diff: net/quic/quic_connection.cc

Issue 903973002: Minor cleanup and optimization of QuicConnection::IsConnectionClose. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Rename_QuicAckNotifier_84624660
Patch Set: Created 5 years, 10 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/quic_connection.h ('k') | 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/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 packet->serialized_packet.packet = nullptr; 1396 packet->serialized_packet.packet = nullptr;
1397 return true; 1397 return true;
1398 } 1398 }
1399 1399
1400 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { 1400 bool QuicConnection::WritePacketInner(QueuedPacket* packet) {
1401 if (ShouldDiscardPacket(*packet)) { 1401 if (ShouldDiscardPacket(*packet)) {
1402 ++stats_.packets_discarded; 1402 ++stats_.packets_discarded;
1403 return true; 1403 return true;
1404 } 1404 }
1405 // Connection close packets are encrypted and saved, so don't exit early. 1405 // Connection close packets are encrypted and saved, so don't exit early.
1406 if (writer_->IsWriteBlocked() && !IsConnectionClose(*packet)) { 1406 const bool is_connection_close = IsConnectionClose(*packet);
1407 if (writer_->IsWriteBlocked() && !is_connection_close) {
1407 return false; 1408 return false;
1408 } 1409 }
1409 1410
1410 QuicPacketSequenceNumber sequence_number = 1411 QuicPacketSequenceNumber sequence_number =
1411 packet->serialized_packet.sequence_number; 1412 packet->serialized_packet.sequence_number;
1412 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); 1413 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number);
1413 sequence_number_of_last_sent_packet_ = sequence_number; 1414 sequence_number_of_last_sent_packet_ = sequence_number;
1414 1415
1415 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( 1416 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(
1416 packet->encryption_level, 1417 packet->encryption_level,
1417 sequence_number, 1418 sequence_number,
1418 *packet->serialized_packet.packet); 1419 *packet->serialized_packet.packet);
1419 if (encrypted == nullptr) { 1420 if (encrypted == nullptr) {
1420 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " 1421 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number "
1421 << sequence_number; 1422 << sequence_number;
1422 // CloseConnection does not send close packet, so no infinite loop here. 1423 // CloseConnection does not send close packet, so no infinite loop here.
1423 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); 1424 CloseConnection(QUIC_ENCRYPTION_FAILURE, false);
1424 return false; 1425 return false;
1425 } 1426 }
1426 1427
1427 // Connection close packets are eventually owned by TimeWaitListManager. 1428 // Connection close packets are eventually owned by TimeWaitListManager.
1428 // Others are deleted at the end of this call. 1429 // Others are deleted at the end of this call.
1429 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; 1430 scoped_ptr<QuicEncryptedPacket> encrypted_deleter;
1430 if (IsConnectionClose(*packet)) { 1431 if (is_connection_close) {
1431 DCHECK(connection_close_packet_.get() == nullptr); 1432 DCHECK(connection_close_packet_.get() == nullptr);
1432 connection_close_packet_.reset(encrypted); 1433 connection_close_packet_.reset(encrypted);
1433 // This assures we won't try to write *forced* packets when blocked. 1434 // This assures we won't try to write *forced* packets when blocked.
1434 // Return true to stop processing. 1435 // Return true to stop processing.
1435 if (writer_->IsWriteBlocked()) { 1436 if (writer_->IsWriteBlocked()) {
1436 visitor_->OnWriteBlocked(); 1437 visitor_->OnWriteBlocked();
1437 return true; 1438 return true;
1438 } 1439 }
1439 } else { 1440 } else {
1440 encrypted_deleter.reset(encrypted); 1441 encrypted_deleter.reset(encrypted);
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 // Retransmitted packets retransmittable frames are owned by the unacked 2098 // Retransmitted packets retransmittable frames are owned by the unacked
2098 // packet map, but are not present in the serialized packet. 2099 // packet map, but are not present in the serialized packet.
2099 if (packet.transmission_type != NOT_RETRANSMISSION || 2100 if (packet.transmission_type != NOT_RETRANSMISSION ||
2100 packet.serialized_packet.retransmittable_frames != nullptr) { 2101 packet.serialized_packet.retransmittable_frames != nullptr) {
2101 return HAS_RETRANSMITTABLE_DATA; 2102 return HAS_RETRANSMITTABLE_DATA;
2102 } else { 2103 } else {
2103 return NO_RETRANSMITTABLE_DATA; 2104 return NO_RETRANSMITTABLE_DATA;
2104 } 2105 }
2105 } 2106 }
2106 2107
2107 bool QuicConnection::IsConnectionClose( 2108 bool QuicConnection::IsConnectionClose(const QueuedPacket& packet) {
2108 QueuedPacket packet) { 2109 const RetransmittableFrames* retransmittable_frames =
2109 RetransmittableFrames* retransmittable_frames =
2110 packet.serialized_packet.retransmittable_frames; 2110 packet.serialized_packet.retransmittable_frames;
2111 if (!retransmittable_frames) { 2111 if (retransmittable_frames == nullptr) {
2112 return false; 2112 return false;
2113 } 2113 }
2114 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2114 for (const QuicFrame& frame : retransmittable_frames->frames()) {
2115 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2115 if (frame.type == CONNECTION_CLOSE_FRAME) {
2116 return true; 2116 return true;
2117 } 2117 }
2118 } 2118 }
2119 return false; 2119 return false;
2120 } 2120 }
2121 2121
2122 } // namespace net 2122 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698