Removes DataFrameSource interface methods and related utilities. The `DataFrameSource` parts of the API are no longer used. PiperOrigin-RevId: 700001502
diff --git a/build/source_list.bzl b/build/source_list.bzl index 2492384..933ba80 100644 --- a/build/source_list.bzl +++ b/build/source_list.bzl
@@ -1436,7 +1436,6 @@ "http2/adapter/nghttp2_adapter_test.cc", "http2/adapter/nghttp2_data_provider_test.cc", "http2/adapter/nghttp2_session_test.cc", - "http2/adapter/nghttp2_util_test.cc", ] default_platform_impl_hdrs = [ "common/platform/default/quiche_platform_impl/quiche_bug_tracker_impl.h",
diff --git a/build/source_list.gni b/build/source_list.gni index b9d9c23..db4f4ad 100644 --- a/build/source_list.gni +++ b/build/source_list.gni
@@ -1440,7 +1440,6 @@ "src/quiche/http2/adapter/nghttp2_adapter_test.cc", "src/quiche/http2/adapter/nghttp2_data_provider_test.cc", "src/quiche/http2/adapter/nghttp2_session_test.cc", - "src/quiche/http2/adapter/nghttp2_util_test.cc", ] default_platform_impl_hdrs = [ "src/quiche/common/platform/default/quiche_platform_impl/quiche_bug_tracker_impl.h",
diff --git a/build/source_list.json b/build/source_list.json index 2e77d42..2f041c7 100644 --- a/build/source_list.json +++ b/build/source_list.json
@@ -1438,8 +1438,7 @@ "quiche/http2/adapter/callback_visitor_test.cc", "quiche/http2/adapter/nghttp2_adapter_test.cc", "quiche/http2/adapter/nghttp2_data_provider_test.cc", - "quiche/http2/adapter/nghttp2_session_test.cc", - "quiche/http2/adapter/nghttp2_util_test.cc" + "quiche/http2/adapter/nghttp2_session_test.cc" ], "default_platform_impl_hdrs": [ "quiche/common/platform/default/quiche_platform_impl/quiche_bug_tracker_impl.h",
diff --git a/quiche/http2/adapter/data_source.h b/quiche/http2/adapter/data_source.h index ffd78a0..589e768 100644 --- a/quiche/http2/adapter/data_source.h +++ b/quiche/http2/adapter/data_source.h
@@ -11,26 +11,10 @@ namespace http2 { namespace adapter { -// Represents a source of DATA frames for transmission to the peer. +// TODO(birenroy): move the remaining constants. class QUICHE_EXPORT DataFrameSource { public: - virtual ~DataFrameSource() {} - enum : int64_t { kBlocked = 0, kError = -1 }; - - // Returns the number of bytes to send in the next DATA frame, and whether - // this frame indicates the end of the data. Returns {kBlocked, false} if - // blocked, {kError, false} on error. - virtual std::pair<int64_t, bool> SelectPayloadLength(size_t max_length) = 0; - - // This method is called with a frame header and a payload length to send. The - // source should send or buffer the entire frame and return true, or return - // false without sending or buffering anything. - virtual bool Send(absl::string_view frame_header, size_t payload_length) = 0; - - // If true, the end of this data source indicates the end of the stream. - // Otherwise, this data will be followed by trailers. - virtual bool send_fin() const = 0; }; // Represents a source of metadata frames for transmission to the peer.
diff --git a/quiche/http2/adapter/nghttp2_util.cc b/quiche/http2/adapter/nghttp2_util.cc index c2b8245..f54ca9d 100644 --- a/quiche/http2/adapter/nghttp2_util.cc +++ b/quiche/http2/adapter/nghttp2_util.cc
@@ -163,67 +163,6 @@ return InvalidFrameError::kProtocol; } -class Nghttp2DataFrameSource : public DataFrameSource { - public: - Nghttp2DataFrameSource(nghttp2_data_provider provider, - nghttp2_send_data_callback send_data, void* user_data) - : provider_(std::move(provider)), - send_data_(std::move(send_data)), - user_data_(user_data) {} - - std::pair<int64_t, bool> SelectPayloadLength(size_t max_length) override { - const int32_t stream_id = 0; - uint32_t data_flags = 0; - int64_t result = provider_.read_callback( - nullptr /* session */, stream_id, nullptr /* buf */, max_length, - &data_flags, &provider_.source, nullptr /* user_data */); - if (result == NGHTTP2_ERR_DEFERRED) { - return {kBlocked, false}; - } else if (result < 0) { - return {kError, false}; - } else if ((data_flags & NGHTTP2_DATA_FLAG_NO_COPY) == 0) { - QUICHE_LOG(ERROR) << "Source did not use the zero-copy API!"; - return {kError, false}; - } else { - const bool eof = data_flags & NGHTTP2_DATA_FLAG_EOF; - if (eof && (data_flags & NGHTTP2_DATA_FLAG_NO_END_STREAM) == 0) { - send_fin_ = true; - } - return {result, eof}; - } - } - - bool Send(absl::string_view frame_header, size_t payload_length) override { - nghttp2_frame frame; - frame.hd.type = 0; - frame.hd.length = payload_length; - frame.hd.flags = 0; - frame.hd.stream_id = 0; - frame.data.padlen = 0; - const int result = send_data_( - nullptr /* session */, &frame, ToUint8Ptr(frame_header.data()), - payload_length, &provider_.source, user_data_); - QUICHE_LOG_IF(ERROR, result < 0 && result != NGHTTP2_ERR_WOULDBLOCK) - << "Unexpected error code from send: " << result; - return result == 0; - } - - bool send_fin() const override { return send_fin_; } - - private: - nghttp2_data_provider provider_; - nghttp2_send_data_callback send_data_; - void* user_data_; - bool send_fin_ = false; -}; - -std::unique_ptr<DataFrameSource> MakeZeroCopyDataFrameSource( - nghttp2_data_provider provider, void* user_data, - nghttp2_send_data_callback send_data) { - return std::make_unique<Nghttp2DataFrameSource>( - std::move(provider), std::move(send_data), user_data); -} - absl::string_view ErrorString(uint32_t error_code) { return Http2ErrorCodeToString(static_cast<Http2ErrorCode>(error_code)); }
diff --git a/quiche/http2/adapter/nghttp2_util.h b/quiche/http2/adapter/nghttp2_util.h index 5e08e8c..5b9f468 100644 --- a/quiche/http2/adapter/nghttp2_util.h +++ b/quiche/http2/adapter/nghttp2_util.h
@@ -61,13 +61,6 @@ int ToNgHttp2ErrorCode(Http2VisitorInterface::InvalidFrameError error); Http2VisitorInterface::InvalidFrameError ToInvalidFrameError(int error); -// Transforms a nghttp2_data_provider into a DataFrameSource. Assumes that -// |provider| uses the zero-copy nghttp2_data_source_read_callback API. Unsafe -// otherwise. -std::unique_ptr<DataFrameSource> MakeZeroCopyDataFrameSource( - nghttp2_data_provider provider, void* user_data, - nghttp2_send_data_callback send_data); - void LogBeforeSend(const nghttp2_frame& frame); } // namespace adapter
diff --git a/quiche/http2/adapter/nghttp2_util_test.cc b/quiche/http2/adapter/nghttp2_util_test.cc deleted file mode 100644 index 69b85f5..0000000 --- a/quiche/http2/adapter/nghttp2_util_test.cc +++ /dev/null
@@ -1,112 +0,0 @@ -#include "quiche/http2/adapter/nghttp2_util.h" - -#include <memory> -#include <string> - -#include "quiche/http2/adapter/nghttp2_test_utils.h" -#include "quiche/http2/adapter/test_utils.h" -#include "quiche/common/platform/api/quiche_test.h" - -namespace http2 { -namespace adapter { -namespace test { -namespace { - -// This send callback assumes |source|'s pointer is a TestDataSource, and -// |user_data| is a std::string. -int FakeSendCallback(nghttp2_session*, nghttp2_frame* /*frame*/, - const uint8_t* framehd, size_t length, - nghttp2_data_source* source, void* user_data) { - auto* dest = static_cast<std::string*>(user_data); - // Appends the frame header to the string. - absl::StrAppend(dest, ToStringView(framehd, 9)); - auto* test_source = static_cast<TestDataSource*>(source->ptr); - absl::string_view payload = test_source->ReadNext(length); - // Appends the frame payload to the string. - absl::StrAppend(dest, payload); - return 0; -} - -TEST(MakeZeroCopyDataFrameSource, EmptyPayload) { - std::string result; - - const absl::string_view kEmptyBody = ""; - TestDataSource body1{kEmptyBody}; - // The TestDataSource is wrapped in the nghttp2_data_provider data type. - nghttp2_data_provider provider = body1.MakeDataProvider(); - - // This call transforms it back into a DataFrameSource, which is compatible - // with the Http2Adapter API. - std::unique_ptr<DataFrameSource> frame_source = - MakeZeroCopyDataFrameSource(provider, &result, FakeSendCallback); - auto [length, eof] = frame_source->SelectPayloadLength(100); - EXPECT_EQ(length, 0); - EXPECT_TRUE(eof); - frame_source->Send("ninebytes", 0); - EXPECT_EQ(result, "ninebytes"); -} - -TEST(MakeZeroCopyDataFrameSource, ShortPayload) { - std::string result; - - const absl::string_view kShortBody = - "<html><head><title>Example Page!</title></head>" - "<body><div><span><table><tr><th><blink>Wow!!" - "</blink></th></tr></table></span></div></body>" - "</html>"; - TestDataSource body1{kShortBody}; - // The TestDataSource is wrapped in the nghttp2_data_provider data type. - nghttp2_data_provider provider = body1.MakeDataProvider(); - - // This call transforms it back into a DataFrameSource, which is compatible - // with the Http2Adapter API. - std::unique_ptr<DataFrameSource> frame_source = - MakeZeroCopyDataFrameSource(provider, &result, FakeSendCallback); - auto [length, eof] = frame_source->SelectPayloadLength(200); - EXPECT_EQ(length, kShortBody.size()); - EXPECT_TRUE(eof); - frame_source->Send("ninebytes", length); - EXPECT_EQ(result, absl::StrCat("ninebytes", kShortBody)); -} - -TEST(MakeZeroCopyDataFrameSource, MultiFramePayload) { - std::string result; - - const absl::string_view kShortBody = - "<html><head><title>Example Page!</title></head>" - "<body><div><span><table><tr><th><blink>Wow!!" - "</blink></th></tr></table></span></div></body>" - "</html>"; - TestDataSource body1{kShortBody}; - // The TestDataSource is wrapped in the nghttp2_data_provider data type. - nghttp2_data_provider provider = body1.MakeDataProvider(); - - // This call transforms it back into a DataFrameSource, which is compatible - // with the Http2Adapter API. - std::unique_ptr<DataFrameSource> frame_source = - MakeZeroCopyDataFrameSource(provider, &result, FakeSendCallback); - auto ret = frame_source->SelectPayloadLength(50); - EXPECT_EQ(ret.first, 50); - EXPECT_FALSE(ret.second); - frame_source->Send("ninebyte1", ret.first); - - ret = frame_source->SelectPayloadLength(50); - EXPECT_EQ(ret.first, 50); - EXPECT_FALSE(ret.second); - frame_source->Send("ninebyte2", ret.first); - - ret = frame_source->SelectPayloadLength(50); - EXPECT_EQ(ret.first, 44); - EXPECT_TRUE(ret.second); - frame_source->Send("ninebyte3", ret.first); - - EXPECT_EQ(result, - "ninebyte1<html><head><title>Example Page!</title></head><bo" - "ninebyte2dy><div><span><table><tr><th><blink>Wow!!</blink><" - "ninebyte3/th></tr></table></span></div></body></html>"); -} - -} // namespace -} // namespace test -} // namespace adapter -} // namespace http2