Index: net/quic/quic_connection.cc |
diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc |
index 99d841f03bb62e33e584b700de994692756d4403..115345db97447a12660639abf93ffa25bb51bd07 100644 |
--- a/net/quic/quic_connection.cc |
+++ b/net/quic/quic_connection.cc |
@@ -129,6 +129,21 @@ class TimeoutAlarm : public QuicAlarm::Delegate { |
QuicConnection* connection_; |
}; |
+class PingAlarm : public QuicAlarm::Delegate { |
+ public: |
+ explicit PingAlarm(QuicConnection* connection) |
+ : connection_(connection) { |
+ } |
+ |
+ virtual QuicTime OnAlarm() override { |
+ connection_->SendPing(); |
+ return QuicTime::Zero(); |
+ } |
+ |
+ private: |
+ QuicConnection* connection_; |
+}; |
jar (doing other things)
2014/04/18 21:57:13
nit: NO_DEFAULT_COPY_AND_ASSIGN
Ryan Hamilton
2014/04/19 13:55:59
Done.
|
+ |
QuicConnection::PacketType GetPacketType( |
const RetransmittableFrames* retransmittable_frames) { |
if (!retransmittable_frames) { |
@@ -191,6 +206,7 @@ QuicConnection::QuicConnection(QuicConnectionId connection_id, |
send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
+ ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), |
debug_visitor_(NULL), |
packet_creator_(connection_id_, &framer_, random_generator_, is_server), |
packet_generator_(this, NULL, &packet_creator_), |
@@ -1058,6 +1074,7 @@ void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, |
MaybeProcessUndecryptablePackets(); |
MaybeProcessRevivedPacket(); |
MaybeSendInResponseToPacket(); |
+ SetPingAlarm(); |
} |
void QuicConnection::OnCanWrite() { |
@@ -1406,6 +1423,7 @@ bool QuicConnection::OnPacketSent(WriteResult result) { |
QuicTime now = clock_->Now(); |
if (transmission_type == NOT_RETRANSMISSION) { |
time_of_last_sent_new_packet_ = now; |
+ SetPingAlarm(); |
jar (doing other things)
2014/04/18 21:57:13
Why don't we always set this? Why do we care if it
Ryan Hamilton
2014/04/19 13:55:59
Done. I was keeping it in sync with the timeout al
|
} |
DVLOG(1) << ENDPOINT << "time of last sent packet: " |
<< now.ToDebuggingValue(); |
@@ -1482,6 +1500,22 @@ void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { |
stop_waiting->least_unacked - 1); |
} |
+void QuicConnection::SendPing() { |
+ if (version() <= QUIC_VERSION_17) { |
+ IOVector data; |
+ char c_data[] = "C"; |
+ data.Append(c_data, 1); |
+ QuicConsumedData consumed_data = |
+ packet_generator_.ConsumeData(kCryptoStreamId, data, 0, false, NULL); |
+ if (consumed_data.bytes_consumed == 0) { |
+ DLOG(ERROR) << "Unable to send ping!?"; |
+ } |
+ } else { |
+ //packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); |
+ } |
+ SetPingAlarm(); |
jar (doing other things)
2014/04/18 21:57:13
Do we don't need to set it again? Shouldn't it sho
Ryan Hamilton
2014/04/19 13:55:59
Interesting! Yes, good point, the send of the PING
|
+} |
+ |
void QuicConnection::SendAck() { |
ack_alarm_->Cancel(); |
stop_waiting_count_ = 0; |
@@ -1802,6 +1836,22 @@ bool QuicConnection::CheckForTimeout() { |
return false; |
} |
+void QuicConnection::SetPingAlarm() { |
+ if (is_server_) { |
+ // Only clients send pings. |
+ return; |
+ } |
+ ping_alarm_->Cancel(); |
+ if (!visitor_->HasOpenStreams()) { |
+ // Don't send a ping unless there are open streams. |
+ return; |
+ } |
+ QuicTime time_of_last_packet = max(time_of_last_received_packet_, |
+ time_of_last_sent_new_packet_); |
+ QuicTime::Delta ping_timeout = idle_network_timeout_.Multiply(0.5); |
+ ping_alarm_->Set(time_of_last_packet.Add(ping_timeout)); |
+} |
+ |
QuicConnection::ScopedPacketBundler::ScopedPacketBundler( |
QuicConnection* connection, |
AckBundling send_ack) |