Make QuicSession::ResetStream() smarter.
If the stream reseted doesn't exist, we always send out 0 as the bytes written. And if it doesn, we always send what the stream has written. So we don't need the explicit parameter for bytes_written.
No behavior change. not protected.
PiperOrigin-RevId: 319211675
Change-Id: I6c96d94e2d0ec1eca0c86a4740a7384aa15c8529
diff --git a/quic/core/http/end_to_end_test.cc b/quic/core/http/end_to_end_test.cc
index 005e463..f333264 100644
--- a/quic/core/http/end_to_end_test.cc
+++ b/quic/core/http/end_to_end_test.cc
@@ -1944,7 +1944,7 @@
// Transmit the cancel, and ensure the connection is torn down properly.
SetPacketLossPercentage(0);
QuicStreamId stream_id = GetNthClientInitiatedBidirectionalId(0);
- session->ResetStream(stream_id, QUIC_STREAM_CANCELLED, 0);
+ session->ResetStream(stream_id, QUIC_STREAM_CANCELLED);
// WaitForEvents waits 50ms and returns true if there are outstanding
// requests.
diff --git a/quic/core/http/quic_client_promised_info_test.cc b/quic/core/http/quic_client_promised_info_test.cc
index 0836f9a..e1b00c8 100644
--- a/quic/core/http/quic_client_promised_info_test.cc
+++ b/quic/core/http/quic_client_promised_info_test.cc
@@ -328,7 +328,7 @@
EXPECT_CALL(*connection_, SendControlFrame(_));
EXPECT_CALL(*connection_,
OnStreamReset(promise_id_, QUIC_STREAM_PEER_GOING_AWAY));
- session_.ResetStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY, 0);
+ session_.ResetStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY);
// Now initiate rendezvous.
TestPushPromiseDelegate delegate(/*match=*/true);
diff --git a/quic/core/http/quic_spdy_client_session_base.cc b/quic/core/http/quic_spdy_client_session_base.cc
index b433c56..3050989 100644
--- a/quic/core/http/quic_spdy_client_session_base.cc
+++ b/quic/core/http/quic_spdy_client_session_base.cc
@@ -204,7 +204,7 @@
QuicStreamId id,
QuicRstStreamErrorCode error_code) {
DCHECK(QuicUtils::IsServerInitiatedStreamId(transport_version(), id));
- ResetStream(id, error_code, 0);
+ ResetStream(id, error_code);
if (!IsOpenStream(id) && !IsClosedStream(id)) {
MaybeIncreaseLargestPeerStreamId(id);
}
diff --git a/quic/core/http/quic_spdy_client_session_test.cc b/quic/core/http/quic_spdy_client_session_test.cc
index 535ecf5..ea131c9 100644
--- a/quic/core/http/quic_spdy_client_session_test.cc
+++ b/quic/core/http/quic_spdy_client_session_test.cc
@@ -288,7 +288,7 @@
// Close the stream, but without having received a FIN or a RST_STREAM
// or MAX_STREAMS (V99) and check that a new one can not be created.
- session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
+ session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED);
EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
stream = session_->CreateOutgoingBidirectionalStream();
@@ -304,7 +304,7 @@
EXPECT_EQ(nullptr, session_->CreateOutgoingBidirectionalStream());
// Close the stream and receive an RST frame to remove the unfinished stream
- session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
+ session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED);
session_->OnRstStream(QuicRstStreamFrame(kInvalidControlFrameId, stream->id(),
QUIC_RST_ACKNOWLEDGEMENT, 0));
// Check that a new one can be created.
@@ -360,7 +360,7 @@
.Times(AtLeast(1))
.WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, OnStreamReset(_, _)).Times(1);
- session_->ResetStream(stream_id, QUIC_STREAM_PEER_GOING_AWAY, 0);
+ session_->ResetStream(stream_id, QUIC_STREAM_PEER_GOING_AWAY);
// A new stream cannot be created as the reset stream still counts as an open
// outgoing stream until closed by the server.
@@ -412,7 +412,7 @@
.Times(AtLeast(1))
.WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, OnStreamReset(_, _)).Times(1);
- session_->ResetStream(stream_id, QUIC_STREAM_PEER_GOING_AWAY, 0);
+ session_->ResetStream(stream_id, QUIC_STREAM_PEER_GOING_AWAY);
// The stream receives trailers with final byte offset, but the header value
// is non-numeric and should be treated as malformed.
@@ -862,7 +862,7 @@
EXPECT_CALL(*connection_, SendControlFrame(_));
EXPECT_CALL(*connection_,
OnStreamReset(promised_stream_id_, QUIC_STREAM_PEER_GOING_AWAY));
- session_->ResetStream(promised_stream_id_, QUIC_STREAM_PEER_GOING_AWAY, 0);
+ session_->ResetStream(promised_stream_id_, QUIC_STREAM_PEER_GOING_AWAY);
QuicClientPromisedInfo* promised =
session_->GetPromisedById(promised_stream_id_);
EXPECT_NE(promised, nullptr);
diff --git a/quic/core/http/quic_spdy_session_test.cc b/quic/core/http/quic_spdy_session_test.cc
index febbe40..20cc430 100644
--- a/quic/core/http/quic_spdy_session_test.cc
+++ b/quic/core/http/quic_spdy_session_test.cc
@@ -411,7 +411,7 @@
// handle the data.
session_.set_writev_consumes_all_data(true);
- session_.ResetStream(id, QUIC_STREAM_CANCELLED, 0);
+ session_.ResetStream(id, QUIC_STREAM_CANCELLED);
closed_streams_.insert(id);
}
diff --git a/quic/core/quic_session.cc b/quic/core/quic_session.cc
index 9f4de44..97490d6 100644
--- a/quic/core/quic_session.cc
+++ b/quic/core/quic_session.cc
@@ -763,9 +763,7 @@
}
}
-void QuicSession::ResetStream(QuicStreamId id,
- QuicRstStreamErrorCode error,
- QuicStreamOffset bytes_written) {
+void QuicSession::ResetStream(QuicStreamId id, QuicRstStreamErrorCode error) {
QuicStream* stream = GetStream(id);
if (stream != nullptr && stream->is_static()) {
connection()->CloseConnection(
@@ -779,7 +777,7 @@
return;
}
- SendRstStream(id, error, bytes_written);
+ SendRstStream(id, error, 0);
}
void QuicSession::MaybeSendRstStreamFrame(QuicStreamId id,
@@ -1795,7 +1793,7 @@
if (!VersionHasIetfQuicFrames(transport_version()) &&
!stream_id_manager_.CanOpenIncomingStream()) {
// Refuse to open the stream.
- ResetStream(stream_id, QUIC_REFUSED_STREAM, 0);
+ ResetStream(stream_id, QUIC_REFUSED_STREAM);
return nullptr;
}
diff --git a/quic/core/quic_session.h b/quic/core/quic_session.h
index f6f7bb6..c936767 100644
--- a/quic/core/quic_session.h
+++ b/quic/core/quic_session.h
@@ -211,9 +211,7 @@
// Called to send RST_STREAM (and STOP_SENDING) and close stream. If stream
// |id| does not exist, just send RST_STREAM (and STOP_SENDING).
- virtual void ResetStream(QuicStreamId id,
- QuicRstStreamErrorCode error,
- QuicStreamOffset bytes_written);
+ virtual void ResetStream(QuicStreamId id, QuicRstStreamErrorCode error);
// Called when the session wants to go away and not accept any new streams.
virtual void SendGoAway(QuicErrorCode error_code, const std::string& reason);
diff --git a/quic/core/quic_session_test.cc b/quic/core/quic_session_test.cc
index aa937a6..15eaf50 100644
--- a/quic/core/quic_session_test.cc
+++ b/quic/core/quic_session_test.cc
@@ -467,7 +467,7 @@
.WillOnce(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, OnStreamReset(id, _));
}
- session_.ResetStream(id, QUIC_STREAM_CANCELLED, 0);
+ session_.ResetStream(id, QUIC_STREAM_CANCELLED);
closed_streams_.insert(id);
}
@@ -2458,7 +2458,7 @@
// Retransmit stream data causes connection close. Stream has not sent fin
// yet, so an RST is sent.
EXPECT_CALL(*stream, OnCanWrite()).WillOnce(Invoke([this, stream]() {
- session_.ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
+ session_.ResetStream(stream->id(), QUIC_STREAM_CANCELLED);
}));
if (VersionHasIetfQuicFrames(transport_version())) {
// Once for the RST_STREAM, once for the STOP_SENDING
diff --git a/quic/core/quic_stream_test.cc b/quic/core/quic_stream_test.cc
index a991a52..da709d4 100644
--- a/quic/core/quic_stream_test.cc
+++ b/quic/core/quic_stream_test.cc
@@ -130,7 +130,7 @@
StreamSendingState /*state*/,
TransmissionType /*type*/,
quiche::QuicheOptional<EncryptionLevel> /*level*/) {
- session_->ResetStream(id, QUIC_STREAM_CANCELLED, 0);
+ session_->ResetStream(id, QUIC_STREAM_CANCELLED);
return QuicConsumedData(1, false);
}
diff --git a/quic/test_tools/quic_test_client.cc b/quic/test_tools/quic_test_client.cc
index 503f585..f876532 100644
--- a/quic/test_tools/quic_test_client.cc
+++ b/quic/test_tools/quic_test_client.cc
@@ -423,9 +423,7 @@
QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(
session->transport_version(), 0);
- QuicStream* stream = session->GetOrCreateStream(stream_id);
- session->ResetStream(stream_id, QUIC_STREAM_CANCELLED,
- stream->stream_bytes_written());
+ session->ResetStream(stream_id, QUIC_STREAM_CANCELLED);
return ret;
}