OLD | NEW |
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 DISALLOW_COPY_AND_ASSIGN(RetransmissionAlarm); | 122 DISALLOW_COPY_AND_ASSIGN(RetransmissionAlarm); |
123 }; | 123 }; |
124 | 124 |
125 // An alarm that is scheduled when the SentPacketManager requires a delay | 125 // An alarm that is scheduled when the SentPacketManager requires a delay |
126 // before sending packets and fires when the packet may be sent. | 126 // before sending packets and fires when the packet may be sent. |
127 class SendAlarm : public QuicAlarm::Delegate { | 127 class SendAlarm : public QuicAlarm::Delegate { |
128 public: | 128 public: |
129 explicit SendAlarm(QuicConnection* connection) : connection_(connection) {} | 129 explicit SendAlarm(QuicConnection* connection) : connection_(connection) {} |
130 | 130 |
131 QuicTime OnAlarm() override { | 131 QuicTime OnAlarm() override { |
132 connection_->WriteIfNotBlocked(); | 132 connection_->WriteAndBundleAcksIfNotBlocked(); |
133 // Never reschedule the alarm, since CanWrite does that. | 133 // Never reschedule the alarm, since CanWrite does that. |
134 return QuicTime::Zero(); | 134 return QuicTime::Zero(); |
135 } | 135 } |
136 | 136 |
137 private: | 137 private: |
138 QuicConnection* connection_; | 138 QuicConnection* connection_; |
139 | 139 |
140 DISALLOW_COPY_AND_ASSIGN(SendAlarm); | 140 DISALLOW_COPY_AND_ASSIGN(SendAlarm); |
141 }; | 141 }; |
142 | 142 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 silent_close_enabled_(false), | 277 silent_close_enabled_(false), |
278 received_packet_manager_(&stats_), | 278 received_packet_manager_(&stats_), |
279 ack_queued_(false), | 279 ack_queued_(false), |
280 num_retransmittable_packets_received_since_last_ack_sent_(0), | 280 num_retransmittable_packets_received_since_last_ack_sent_(0), |
281 last_ack_had_missing_packets_(false), | 281 last_ack_had_missing_packets_(false), |
282 num_packets_received_since_last_ack_sent_(0), | 282 num_packets_received_since_last_ack_sent_(0), |
283 stop_waiting_count_(0), | 283 stop_waiting_count_(0), |
284 ack_mode_(TCP_ACKING), | 284 ack_mode_(TCP_ACKING), |
285 delay_setting_retransmission_alarm_(false), | 285 delay_setting_retransmission_alarm_(false), |
286 pending_retransmission_alarm_(false), | 286 pending_retransmission_alarm_(false), |
| 287 defer_send_in_response_to_packets_(false), |
287 arena_(), | 288 arena_(), |
288 ack_alarm_(helper->CreateAlarm(arena_.New<AckAlarm>(this), &arena_)), | 289 ack_alarm_(helper->CreateAlarm(arena_.New<AckAlarm>(this), &arena_)), |
289 retransmission_alarm_( | 290 retransmission_alarm_( |
290 helper->CreateAlarm(arena_.New<RetransmissionAlarm>(this), &arena_)), | 291 helper->CreateAlarm(arena_.New<RetransmissionAlarm>(this), &arena_)), |
291 send_alarm_(helper->CreateAlarm(arena_.New<SendAlarm>(this), &arena_)), | 292 send_alarm_(helper->CreateAlarm(arena_.New<SendAlarm>(this), &arena_)), |
292 resume_writes_alarm_( | 293 resume_writes_alarm_( |
293 helper->CreateAlarm(arena_.New<SendAlarm>(this), &arena_)), | 294 helper->CreateAlarm(arena_.New<SendAlarm>(this), &arena_)), |
294 timeout_alarm_( | 295 timeout_alarm_( |
295 helper->CreateAlarm(arena_.New<TimeoutAlarm>(this), &arena_)), | 296 helper->CreateAlarm(arena_.New<TimeoutAlarm>(this), &arena_)), |
296 ping_alarm_(helper->CreateAlarm(arena_.New<PingAlarm>(this), &arena_)), | 297 ping_alarm_(helper->CreateAlarm(arena_.New<PingAlarm>(this), &arena_)), |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 } | 1129 } |
1129 | 1130 |
1130 QuicPacketNumber QuicConnection::GetLeastUnacked() const { | 1131 QuicPacketNumber QuicConnection::GetLeastUnacked() const { |
1131 return sent_packet_manager_.GetLeastUnacked(); | 1132 return sent_packet_manager_.GetLeastUnacked(); |
1132 } | 1133 } |
1133 | 1134 |
1134 void QuicConnection::MaybeSendInResponseToPacket() { | 1135 void QuicConnection::MaybeSendInResponseToPacket() { |
1135 if (!connected_) { | 1136 if (!connected_) { |
1136 return; | 1137 return; |
1137 } | 1138 } |
1138 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); | |
1139 | |
1140 // Now that we have received an ack, we might be able to send packets which | 1139 // Now that we have received an ack, we might be able to send packets which |
1141 // are queued locally, or drain streams which are blocked. | 1140 // are queued locally, or drain streams which are blocked. |
1142 WriteIfNotBlocked(); | 1141 if (defer_send_in_response_to_packets_) { |
| 1142 send_alarm_->Cancel(); |
| 1143 send_alarm_->Set(clock_->ApproximateNow()); |
| 1144 } else { |
| 1145 WriteAndBundleAcksIfNotBlocked(); |
| 1146 } |
1143 } | 1147 } |
1144 | 1148 |
1145 void QuicConnection::SendVersionNegotiationPacket() { | 1149 void QuicConnection::SendVersionNegotiationPacket() { |
1146 // TODO(alyssar): implement zero server state negotiation. | 1150 // TODO(alyssar): implement zero server state negotiation. |
1147 pending_version_negotiation_packet_ = true; | 1151 pending_version_negotiation_packet_ = true; |
1148 if (writer_->IsWriteBlocked()) { | 1152 if (writer_->IsWriteBlocked()) { |
1149 visitor_->OnWriteBlocked(); | 1153 visitor_->OnWriteBlocked(); |
1150 return; | 1154 return; |
1151 } | 1155 } |
1152 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" | 1156 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 resume_writes_alarm_->Set(clock_->ApproximateNow()); | 1397 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
1394 } | 1398 } |
1395 } | 1399 } |
1396 | 1400 |
1397 void QuicConnection::WriteIfNotBlocked() { | 1401 void QuicConnection::WriteIfNotBlocked() { |
1398 if (!writer_->IsWriteBlocked()) { | 1402 if (!writer_->IsWriteBlocked()) { |
1399 OnCanWrite(); | 1403 OnCanWrite(); |
1400 } | 1404 } |
1401 } | 1405 } |
1402 | 1406 |
| 1407 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { |
| 1408 if (!writer_->IsWriteBlocked()) { |
| 1409 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); |
| 1410 OnCanWrite(); |
| 1411 } |
| 1412 } |
| 1413 |
1403 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { | 1414 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { |
1404 if (FLAGS_check_peer_address_change_after_decryption) { | 1415 if (FLAGS_check_peer_address_change_after_decryption) { |
1405 if (perspective_ == Perspective::IS_SERVER && | 1416 if (perspective_ == Perspective::IS_SERVER && |
1406 IsInitializedIPEndPoint(self_address_) && | 1417 IsInitializedIPEndPoint(self_address_) && |
1407 IsInitializedIPEndPoint(last_packet_destination_address_) && | 1418 IsInitializedIPEndPoint(last_packet_destination_address_) && |
1408 (!(self_address_ == last_packet_destination_address_))) { | 1419 (!(self_address_ == last_packet_destination_address_))) { |
1409 SendConnectionCloseWithDetails( | 1420 SendConnectionCloseWithDetails( |
1410 QUIC_ERROR_MIGRATING_ADDRESS, | 1421 QUIC_ERROR_MIGRATING_ADDRESS, |
1411 "Self address migration is not supported at the server."); | 1422 "Self address migration is not supported at the server."); |
1412 return false; | 1423 return false; |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 void QuicConnection::OnPathClosed(QuicPathId path_id) { | 2518 void QuicConnection::OnPathClosed(QuicPathId path_id) { |
2508 // Stop receiving packets on this path. | 2519 // Stop receiving packets on this path. |
2509 framer_.OnPathClosed(path_id); | 2520 framer_.OnPathClosed(path_id); |
2510 } | 2521 } |
2511 | 2522 |
2512 bool QuicConnection::ack_frame_updated() const { | 2523 bool QuicConnection::ack_frame_updated() const { |
2513 return received_packet_manager_.ack_frame_updated(); | 2524 return received_packet_manager_.ack_frame_updated(); |
2514 } | 2525 } |
2515 | 2526 |
2516 } // namespace net | 2527 } // namespace net |
OLD | NEW |