Index: net/quic/quic_connection.cc |
diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc |
index d6ea19e57624b2874849ec15e27d7c4f31061c8e..182bd301f71d097d79a41b9c5d5d7fe7091534fc 100644 |
--- a/net/quic/quic_connection.cc |
+++ b/net/quic/quic_connection.cc |
@@ -1389,9 +1389,6 @@ bool QuicConnection::WritePacket(QueuedPacket packet) { |
<< packet.packet->length() << " " << encrypted->length() << " " |
<< " close: " << (packet.type == CONNECTION_CLOSE ? "yes" : "no"); |
- DCHECK(pending_write_.get() == NULL); |
- pending_write_.reset(new QueuedPacket(packet)); |
- |
WriteResult result = writer_->WritePacket(encrypted->data(), |
encrypted->length(), |
self_address().address(), |
@@ -1407,23 +1404,52 @@ bool QuicConnection::WritePacket(QueuedPacket packet) { |
*encrypted, |
result); |
} |
+ |
if (result.status == WRITE_STATUS_BLOCKED) { |
visitor_->OnWriteBlocked(); |
// If the socket buffers the the data, then the packet should not |
// be queued and sent again, which would result in an unnecessary |
// duplicate packet being sent. The helper must call OnPacketSent |
// when the packet is actually sent. |
- if (writer_->IsWriteBlockedDataBuffered()) { |
- return true; |
+ if (!writer_->IsWriteBlockedDataBuffered()) { |
+ return false; |
} |
- pending_write_.reset(); |
- return false; |
} |
+ QuicTime now = clock_->Now(); |
+ if (packet.transmission_type == NOT_RETRANSMISSION) { |
+ time_of_last_sent_new_packet_ = now; |
+ } |
+ SetPingAlarm(); |
+ DVLOG(1) << ENDPOINT << "time of last sent packet: " |
+ << now.ToDebuggingValue(); |
- if (OnPacketSent(result)) { |
- return true; |
+ // TODO(ianswett): Change the sequence number length and other packet creator |
+ // options by a more explicit API than setting a struct value directly, |
+ // perhaps via the NetworkChangeVisitor. |
+ packet_generator_.UpdateSequenceNumberLength( |
+ 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); |
+ |
+ if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
+ retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(), |
+ QuicTime::Delta::FromMilliseconds(1)); |
} |
- return false; |
+ |
+ stats_.bytes_sent += result.bytes_written; |
+ ++stats_.packets_sent; |
+ if (packet.transmission_type != NOT_RETRANSMISSION) { |
+ stats_.bytes_retransmitted += result.bytes_written; |
+ ++stats_.packets_retransmitted; |
+ } |
+ |
+ return OnPacketSent(result); |
} |
bool QuicConnection::ShouldDiscardPacket( |
@@ -1468,18 +1494,6 @@ bool QuicConnection::ShouldDiscardPacket( |
} |
bool QuicConnection::OnPacketSent(WriteResult result) { |
- DCHECK_NE(WRITE_STATUS_BLOCKED, result.status); |
- if (pending_write_.get() == NULL) { |
- LOG(DFATAL) << "OnPacketSent called without a pending write."; |
- return false; |
- } |
- |
- QuicPacketSequenceNumber sequence_number = pending_write_->sequence_number; |
- TransmissionType transmission_type = pending_write_->transmission_type; |
- HasRetransmittableData retransmittable = pending_write_->retransmittable; |
- size_t length = pending_write_->length; |
- pending_write_.reset(); |
- |
if (result.status == WRITE_STATUS_ERROR) { |
DVLOG(1) << ENDPOINT << "Write failed with error: " << result.error_code |
<< " (" << ErrorToString(result.error_code) << ")"; |
@@ -1488,38 +1502,6 @@ bool QuicConnection::OnPacketSent(WriteResult result) { |
return false; |
} |
- QuicTime now = clock_->Now(); |
- if (transmission_type == NOT_RETRANSMISSION) { |
- time_of_last_sent_new_packet_ = now; |
- } |
- SetPingAlarm(); |
- DVLOG(1) << ENDPOINT << "time of last sent packet: " |
- << now.ToDebuggingValue(); |
- |
- // TODO(ianswett): Change the sequence number length and other packet creator |
- // options by a more explicit API than setting a struct value directly. |
- packet_generator_.UpdateSequenceNumberLength( |
- sent_packet_manager_.least_packet_awaited_by_peer(), |
- sent_packet_manager_.GetCongestionWindow()); |
- |
- bool reset_retransmission_alarm = |
- sent_packet_manager_.OnPacketSent(sequence_number, now, length, |
- transmission_type, retransmittable); |
- |
- if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
- QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); |
- retransmission_alarm_->Update(retransmission_time, |
- QuicTime::Delta::FromMilliseconds(1)); |
- } |
- |
- stats_.bytes_sent += result.bytes_written; |
- ++stats_.packets_sent; |
- |
- if (transmission_type != NOT_RETRANSMISSION) { |
- stats_.bytes_retransmitted += result.bytes_written; |
- ++stats_.packets_retransmitted; |
- } |
- |
return true; |
} |