summaryrefslogtreecommitdiffstats
path: root/net/quic/quic_connection.cc
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-21 06:26:58 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-21 06:26:58 +0000
commit525948df785f1e244fef1ac62f44f9ffe386fc10 (patch)
tree824baacd351ca89091de25661430d32d28ab90ea /net/quic/quic_connection.cc
parent2c57a19e2854d16bed7d5f1140f73f96e3cf5944 (diff)
downloadchromium_src-525948df785f1e244fef1ac62f44f9ffe386fc10.zip
chromium_src-525948df785f1e244fef1ac62f44f9ffe386fc10.tar.gz
chromium_src-525948df785f1e244fef1ac62f44f9ffe386fc10.tar.bz2
Sent QUIC "PING" frames when a stream is open and the connection
has been idle for the half idle network timeout. Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=264950 Review URL: https://codereview.chromium.org/243533003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic/quic_connection.cc')
-rw-r--r--net/quic/quic_connection.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc
index e29bea9..74cc16b 100644
--- a/net/quic/quic_connection.cc
+++ b/net/quic/quic_connection.cc
@@ -75,6 +75,8 @@ class AckAlarm : public QuicAlarm::Delegate {
private:
QuicConnection* connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(AckAlarm);
};
// This alarm will be scheduled any time a data-bearing packet is sent out.
@@ -93,6 +95,8 @@ class RetransmissionAlarm : public QuicAlarm::Delegate {
private:
QuicConnection* connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(RetransmissionAlarm);
};
// An alarm that is scheduled when the sent scheduler requires a
@@ -111,6 +115,8 @@ class SendAlarm : public QuicAlarm::Delegate {
private:
QuicConnection* connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(SendAlarm);
};
class TimeoutAlarm : public QuicAlarm::Delegate {
@@ -127,6 +133,23 @@ class TimeoutAlarm : public QuicAlarm::Delegate {
private:
QuicConnection* connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(TimeoutAlarm);
+};
+
+class PingAlarm : public QuicAlarm::Delegate {
+ public:
+ explicit PingAlarm(QuicConnection* connection)
+ : connection_(connection) {
+ }
+
+ virtual QuicTime OnAlarm() OVERRIDE {
+ connection_->SendPing();
+ return QuicTime::Zero();
+ }
+
+ private:
+ QuicConnection* connection_;
};
QuicConnection::PacketType GetPacketType(
@@ -191,6 +214,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_),
@@ -1060,6 +1084,7 @@ void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
MaybeProcessUndecryptablePackets();
MaybeProcessRevivedPacket();
MaybeSendInResponseToPacket();
+ SetPingAlarm();
}
void QuicConnection::OnCanWrite() {
@@ -1409,6 +1434,7 @@ bool QuicConnection::OnPacketSent(WriteResult result) {
if (transmission_type == NOT_RETRANSMISSION) {
time_of_last_sent_new_packet_ = now;
}
+ SetPingAlarm();
DVLOG(1) << ENDPOINT << "time of last sent packet: "
<< now.ToDebuggingValue();
@@ -1484,6 +1510,27 @@ void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) {
stop_waiting->least_unacked - 1);
}
+void QuicConnection::SendPing() {
+ if (retransmission_alarm_->IsSet()) {
+ return;
+ }
+ if (version() <= QUIC_VERSION_17) {
+ // TODO(rch): remove this when we remove version 17.
+ // This is a horrible hideous hack which we should not support.
+ 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 {
+ // TODO(rch): enable this when we merge version 18.
+ // packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame));
+ }
+}
+
void QuicConnection::SendAck() {
ack_alarm_->Cancel();
stop_waiting_count_ = 0;
@@ -1808,6 +1855,20 @@ bool QuicConnection::CheckForTimeout() {
return false;
}
+void QuicConnection::SetPingAlarm() {
+ if (is_server_) {
+ // Only clients send pings.
+ return;
+ }
+ ping_alarm_->Cancel();
+ if (!visitor_->HasOpenDataStreams()) {
+ // Don't send a ping unless there are open streams.
+ return;
+ }
+ QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs);
+ ping_alarm_->Set(clock_->ApproximateNow().Add(ping_timeout));
+}
+
QuicConnection::ScopedPacketBundler::ScopedPacketBundler(
QuicConnection* connection,
AckBundling send_ack)