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

Unified Diff: net/quic/quic_connection.cc

Issue 509203003: Nest a QUIC SerializedPacket inside a QUIC QueuedPacket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_PacketType_74148481
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_connection.cc
diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc
index 30e874665e707fa7b80a64c740ccad17bc615913..872c43527e6ebacd971473631381b62d6cec9b7d 100644
--- a/net/quic/quic_connection.cc
+++ b/net/quic/quic_connection.cc
@@ -154,35 +154,14 @@ class PingAlarm : public QuicAlarm::Delegate {
DISALLOW_COPY_AND_ASSIGN(PingAlarm);
};
-bool IsConnectionClose(
- const RetransmittableFrames* retransmittable_frames) {
- if (!retransmittable_frames) {
- return false;
- }
- for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
- if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
- return true;
- }
- }
- return false;
-}
-
} // namespace
QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet,
EncryptionLevel level,
TransmissionType transmission_type)
- : sequence_number(packet.sequence_number),
- packet(packet.packet),
+ : serialized_packet(packet),
encryption_level(level),
- transmission_type(transmission_type),
- retransmittable((transmission_type != NOT_RETRANSMISSION ||
- packet.retransmittable_frames != NULL) ?
- HAS_RETRANSMITTABLE_DATA : NO_RETRANSMITTABLE_DATA),
- handshake(packet.retransmittable_frames == NULL ?
- NOT_HANDSHAKE : packet.retransmittable_frames->HasCryptoHandshake()),
- is_connection_close(IsConnectionClose(packet.retransmittable_frames)),
- length(packet.packet->length()) {
+ transmission_type(transmission_type) {
}
#define ENDPOINT (is_server_ ? "Server: " : " Client: ")
@@ -262,7 +241,7 @@ QuicConnection::~QuicConnection() {
STLDeleteValues(&group_map_);
for (QueuedPacketList::iterator it = queued_packets_.begin();
it != queued_packets_.end(); ++it) {
- delete it->packet;
+ delete it->serialized_packet.packet;
}
}
@@ -1230,7 +1209,7 @@ void QuicConnection::WriteQueuedPackets() {
while (!writer_->IsWriteBlocked() &&
packet_iterator != queued_packets_.end()) {
if (WritePacket(*packet_iterator)) {
- delete packet_iterator->packet;
+ delete packet_iterator->serialized_packet.packet;
packet_iterator = queued_packets_.erase(packet_iterator);
} else {
// Continue, because some queued packets may still be writable.
@@ -1331,10 +1310,11 @@ bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) {
}
bool QuicConnection::WritePacket(QueuedPacket packet) {
- QuicPacketSequenceNumber sequence_number = packet.sequence_number;
+ QuicPacketSequenceNumber sequence_number =
+ packet.serialized_packet.sequence_number;
if (ShouldDiscardPacket(packet.encryption_level,
sequence_number,
- packet.retransmittable)) {
+ IsRetransmittable(packet))) {
++stats_.packets_discarded;
return true;
}
@@ -1345,7 +1325,9 @@ bool QuicConnection::WritePacket(QueuedPacket packet) {
sequence_number_of_last_sent_packet_ = sequence_number;
QuicEncryptedPacket* encrypted = framer_.EncryptPacket(
- packet.encryption_level, sequence_number, *packet.packet);
+ packet.encryption_level,
+ sequence_number,
+ *packet.serialized_packet.packet);
if (encrypted == NULL) {
LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number "
<< sequence_number;
@@ -1357,7 +1339,7 @@ bool QuicConnection::WritePacket(QueuedPacket packet) {
// Connection close packets are eventually owned by TimeWaitListManager.
// Others are deleted at the end of this call.
scoped_ptr<QuicEncryptedPacket> encrypted_deleter;
- if (packet.is_connection_close) {
+ if (IsConnectionClose(packet)) {
DCHECK(connection_close_packet_.get() == NULL);
connection_close_packet_.reset(encrypted);
// This assures we won't try to write *forced* packets when blocked.
@@ -1374,16 +1356,19 @@ bool QuicConnection::WritePacket(QueuedPacket packet) {
DCHECK_LE(encrypted->length(), kMaxPacketSize);
}
DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length());
- DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number
- << " : " << (packet.packet->is_fec_packet() ? "FEC " :
- (packet.retransmittable == HAS_RETRANSMITTABLE_DATA
- ? "data bearing " : " ack only "))
+ DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number << " : "
+ << (packet.serialized_packet.packet->is_fec_packet() ? "FEC " :
+ (IsRetransmittable(packet) == HAS_RETRANSMITTABLE_DATA
+ ? "data bearing " : " ack only "))
<< ", encryption level: "
<< QuicUtils::EncryptionLevelToString(packet.encryption_level)
- << ", length:" << packet.packet->length() << ", encrypted length:"
+ << ", length:"
+ << packet.serialized_packet.packet->length()
+ << ", encrypted length:"
<< encrypted->length();
DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl
- << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece());
+ << QuicUtils::StringToHexASCIIDump(
+ packet.serialized_packet.packet->AsStringPiece());
WriteResult result = writer_->WritePacket(encrypted->data(),
encrypted->length(),
@@ -1426,12 +1411,12 @@ bool QuicConnection::WritePacket(QueuedPacket packet) {
sent_packet_manager_.least_packet_awaited_by_peer(),
sent_packet_manager_.GetCongestionWindow());
- bool reset_retransmission_alarm =
- sent_packet_manager_.OnPacketSent(sequence_number,
- now,
- encrypted->length(),
- packet.transmission_type,
- packet.retransmittable);
+ bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
+ sequence_number,
+ now,
+ encrypted->length(),
+ packet.transmission_type,
+ IsRetransmittable(packet));
if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(),
@@ -1538,7 +1523,8 @@ bool QuicConnection::SendOrQueuePacket(EncryptionLevel level,
QueuedPacket queued_packet(packet, level, transmission_type);
// If there are already queued packets, put this at the end,
// unless it's ConnectionClose, in which case it is written immediately.
- if ((queued_packet.is_connection_close || queued_packets_.empty()) &&
+ if ((IsConnectionClose(queued_packet)
+ || queued_packets_.empty()) &&
WritePacket(queued_packet)) {
delete packet.packet;
return true;
@@ -1995,4 +1981,31 @@ QuicConnection::ScopedPacketBundler::~ScopedPacketBundler() {
connection_->packet_generator_.InBatchMode());
}
+HasRetransmittableData QuicConnection::IsRetransmittable(
+ QueuedPacket packet) {
+ // TODO(cyr): Understand why the first check here is necessary. Without it,
+ // DiscardRetransmit test fails.
+ if (packet.transmission_type != NOT_RETRANSMISSION ||
+ packet.serialized_packet.retransmittable_frames != NULL) {
+ return HAS_RETRANSMITTABLE_DATA;
+ } else {
+ return NO_RETRANSMITTABLE_DATA;
+ }
+}
+
+bool QuicConnection::IsConnectionClose(
+ QueuedPacket packet) {
+ RetransmittableFrames* retransmittable_frames =
+ packet.serialized_packet.retransmittable_frames;
+ if (!retransmittable_frames) {
+ return false;
+ }
+ for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
+ if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace net
« 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