diff --git a/include/boost/http/concept/buffer_sink.hpp b/include/boost/http/concept/buffer_sink.hpp index 8f87bdb1..14e90f56 100644 --- a/include/boost/http/concept/buffer_sink.hpp +++ b/include/boost/http/concept/buffer_sink.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_HTTP_CONCEPT_BUFFER_SINK_HPP #define BOOST_HTTP_CONCEPT_BUFFER_SINK_HPP -#include #include #include #include diff --git a/include/boost/http/concept/buffer_source.hpp b/include/boost/http/concept/buffer_source.hpp index a3f73e54..fe02bdab 100644 --- a/include/boost/http/concept/buffer_source.hpp +++ b/include/boost/http/concept/buffer_source.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_HTTP_CONCEPT_BUFFER_SOURCE_HPP #define BOOST_HTTP_CONCEPT_BUFFER_SOURCE_HPP -#include #include #include #include diff --git a/include/boost/http/concept/read_source.hpp b/include/boost/http/concept/read_source.hpp index c2eaf4ce..7ebe6dcb 100644 --- a/include/boost/http/concept/read_source.hpp +++ b/include/boost/http/concept/read_source.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_HTTP_CONCEPT_READ_SOURCE_HPP #define BOOST_HTTP_CONCEPT_READ_SOURCE_HPP -#include #include #include #include diff --git a/include/boost/http/concept/write_sink.hpp b/include/boost/http/concept/write_sink.hpp index 057ccae1..b7085f71 100644 --- a/include/boost/http/concept/write_sink.hpp +++ b/include/boost/http/concept/write_sink.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_HTTP_CONCEPT_WRITE_SINK_HPP #define BOOST_HTTP_CONCEPT_WRITE_SINK_HPP -#include #include #include #include diff --git a/include/boost/http/detail/max_iovec.hpp b/include/boost/http/detail/max_iovec.hpp new file mode 100644 index 00000000..4451462a --- /dev/null +++ b/include/boost/http/detail/max_iovec.hpp @@ -0,0 +1,30 @@ +// +// Copyright (c) 2026 Steve Gerbino +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/http +// + +#ifndef BOOST_HTTP_DETAIL_MAX_IOVEC_HPP +#define BOOST_HTTP_DETAIL_MAX_IOVEC_HPP + +#include + +namespace boost { +namespace http { +namespace detail { + +// Buffers the sources, sinks and transfer loops hand on per call. +// POSIX guarantees an IOV_MAX of at least 16, so one window fits one +// vectored call on any backend. A larger window copies descriptors a +// backend may not use in that call, and each one adds 16 bytes to the +// awaiting frame. +inline constexpr std::size_t max_iovec_ = 16; + +} // detail +} // http +} // boost + +#endif diff --git a/include/boost/http/io/any_buffer_sink.hpp b/include/boost/http/io/any_buffer_sink.hpp index 2427dde8..d0f9acd7 100644 --- a/include/boost/http/io/any_buffer_sink.hpp +++ b/include/boost/http/io/any_buffer_sink.hpp @@ -10,8 +10,8 @@ #ifndef BOOST_HTTP_IO_ANY_BUFFER_SINK_HPP #define BOOST_HTTP_IO_ANY_BUFFER_SINK_HPP -#include #include +#include #include #include #include @@ -1052,7 +1052,7 @@ any_buffer_sink::write_some(CB buffers) co_return co_await write_some_(src); // Synthesized path: prepare + capy::buffer_copy + commit - capy::mutable_buffer arr[capy::detail::max_iovec_]; + capy::mutable_buffer arr[detail::max_iovec_]; auto dst_bufs = prepare(arr); if(dst_bufs.empty()) { @@ -1103,7 +1103,7 @@ any_buffer_sink::write(CB buffers) if(src.empty()) break; - capy::mutable_buffer arr[capy::detail::max_iovec_]; + capy::mutable_buffer arr[detail::max_iovec_]; auto dst_bufs = prepare(arr); if(dst_bufs.empty()) { @@ -1224,7 +1224,7 @@ any_buffer_sink::write_eof(CB buffers) if(src.empty()) break; - capy::mutable_buffer arr[capy::detail::max_iovec_]; + capy::mutable_buffer arr[detail::max_iovec_]; auto dst_bufs = prepare(arr); if(dst_bufs.empty()) { diff --git a/include/boost/http/io/any_buffer_source.hpp b/include/boost/http/io/any_buffer_source.hpp index 6cee1b39..21b208d5 100644 --- a/include/boost/http/io/any_buffer_source.hpp +++ b/include/boost/http/io/any_buffer_source.hpp @@ -10,8 +10,8 @@ #ifndef BOOST_HTTP_IO_ANY_BUFFER_SOURCE_HPP #define BOOST_HTTP_IO_ANY_BUFFER_SOURCE_HPP -#include #include +#include #include #include #include @@ -768,7 +768,7 @@ any_buffer_source::read_some(MB buffers) co_return co_await read_some_(dest); // Synthesized path: pull + capy::buffer_copy + consume - capy::const_buffer arr[capy::detail::max_iovec_]; + capy::const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await pull(arr); if(ec) co_return {ec, 0}; @@ -810,7 +810,7 @@ any_buffer_source::read(MB buffers) if(dest.empty()) break; - capy::const_buffer arr[capy::detail::max_iovec_]; + capy::const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await pull(arr); if(ec) diff --git a/include/boost/http/io/any_read_source.hpp b/include/boost/http/io/any_read_source.hpp index e792b30b..064076b3 100644 --- a/include/boost/http/io/any_read_source.hpp +++ b/include/boost/http/io/any_read_source.hpp @@ -10,8 +10,8 @@ #ifndef BOOST_HTTP_IO_ANY_READ_SOURCE_HPP #define BOOST_HTTP_IO_ANY_READ_SOURCE_HPP -#include #include +#include #include #include #include @@ -473,7 +473,7 @@ any_read_source::read_some(MB buffers) struct awaitable { any_read_source* self_; - capy::detail::mutable_buffer_array ba_; + capy::detail::mutable_buffer_array ba_; awaitable(any_read_source* self, MB const& buffers) : self_(self) diff --git a/include/boost/http/io/any_write_sink.hpp b/include/boost/http/io/any_write_sink.hpp index 429d8d62..b674e160 100644 --- a/include/boost/http/io/any_write_sink.hpp +++ b/include/boost/http/io/any_write_sink.hpp @@ -10,8 +10,8 @@ #ifndef BOOST_HTTP_IO_ANY_WRITE_SINK_HPP #define BOOST_HTTP_IO_ANY_WRITE_SINK_HPP -#include #include +#include #include #include #include @@ -799,7 +799,7 @@ any_write_sink::write_some(CB buffers) struct awaitable { any_write_sink* self_; - capy::detail::const_buffer_array ba_; + capy::detail::const_buffer_array ba_; awaitable( any_write_sink* self, diff --git a/include/boost/http/io/buffer_param.hpp b/include/boost/http/io/buffer_param.hpp index 1c5de9a7..ffff2c09 100644 --- a/include/boost/http/io/buffer_param.hpp +++ b/include/boost/http/io/buffer_param.hpp @@ -29,7 +29,7 @@ #ifndef BOOST_HTTP_IO_BUFFER_PARAM_HPP #define BOOST_HTTP_IO_BUFFER_PARAM_HPP -#include +#include #include #include @@ -151,7 +151,7 @@ class buffer_param decltype(capy::buffer_sequence_end(std::declval())) end_; union { int dummy_; - buffer_type arr_[capy::detail::max_iovec_]; + buffer_type arr_[detail::max_iovec_]; }; std::size_t size_ = 0; std::size_t pos_ = 0; @@ -161,7 +161,7 @@ class buffer_param { pos_ = 0; size_ = 0; - for(; it_ != end_ && size_ < capy::detail::max_iovec_; ++it_) + for(; it_ != end_ && size_ < detail::max_iovec_; ++it_) { buffer_type buf(*it_); if(buf.size() > 0) diff --git a/include/boost/http/io/pull_from.hpp b/include/boost/http/io/pull_from.hpp index 6c70cd85..70fa182e 100644 --- a/include/boost/http/io/pull_from.hpp +++ b/include/boost/http/io/pull_from.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_HTTP_IO_PULL_FROM_HPP #define BOOST_HTTP_IO_PULL_FROM_HPP -#include +#include #include #include #include @@ -64,7 +64,7 @@ template capy::task> pull_from(Src& source, Sink& sink) { - capy::mutable_buffer dst_arr[capy::detail::max_iovec_]; + capy::mutable_buffer dst_arr[detail::max_iovec_]; std::size_t total = 0; for(;;) @@ -144,7 +144,7 @@ template capy::task> pull_from(Src& source, Sink& sink) { - capy::mutable_buffer dst_arr[capy::detail::max_iovec_]; + capy::mutable_buffer dst_arr[detail::max_iovec_]; std::size_t total = 0; for(;;) diff --git a/include/boost/http/io/push_to.hpp b/include/boost/http/io/push_to.hpp index 21dcbbd9..e36ba122 100644 --- a/include/boost/http/io/push_to.hpp +++ b/include/boost/http/io/push_to.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_HTTP_IO_PUSH_TO_HPP #define BOOST_HTTP_IO_PUSH_TO_HPP -#include +#include #include #include #include @@ -63,7 +63,7 @@ template capy::task> push_to(Src& source, Sink& sink) { - capy::const_buffer arr[capy::detail::max_iovec_]; + capy::const_buffer arr[detail::max_iovec_]; std::size_t total = 0; for(;;) @@ -128,7 +128,7 @@ template capy::task> push_to(Src& source, Stream& stream) { - capy::const_buffer arr[capy::detail::max_iovec_]; + capy::const_buffer arr[detail::max_iovec_]; std::size_t total = 0; for(;;) diff --git a/include/boost/http/test/buffer_sink.hpp b/include/boost/http/test/buffer_sink.hpp index e41bf2c4..ad431ac7 100644 --- a/include/boost/http/test/buffer_sink.hpp +++ b/include/boost/http/test/buffer_sink.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_HTTP_TEST_BUFFER_SINK_HPP #define BOOST_HTTP_TEST_BUFFER_SINK_HPP -#include #include #include #include @@ -172,7 +171,7 @@ class buffer_sink // The operation completes synchronously, but await_suspend is // the only place capy::await_context is delivered (the promise's - // transform_awaiter forwards it here). Returning false means + // awaiter forwards it here). Returning false means // the coroutine does not actually suspend; it resumes // immediately, having observed the stop token. See capy::await_context, // ContextAwaitable. diff --git a/include/boost/http/test/buffer_source.hpp b/include/boost/http/test/buffer_source.hpp index 8c2749d7..5ea1f680 100644 --- a/include/boost/http/test/buffer_source.hpp +++ b/include/boost/http/test/buffer_source.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_HTTP_TEST_BUFFER_SOURCE_HPP #define BOOST_HTTP_TEST_BUFFER_SOURCE_HPP -#include #include #include #include @@ -162,7 +161,7 @@ class buffer_source // The operation completes synchronously, but await_suspend is // the only place capy::await_context is delivered (the promise's - // transform_awaiter forwards it here). Returning false means + // awaiter forwards it here). Returning false means // the coroutine does not actually suspend; it resumes // immediately, having observed the stop token. See capy::await_context, // ContextAwaitable. diff --git a/include/boost/http/test/read_source.hpp b/include/boost/http/test/read_source.hpp index 86113294..388757cd 100644 --- a/include/boost/http/test/read_source.hpp +++ b/include/boost/http/test/read_source.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_HTTP_TEST_READ_SOURCE_HPP #define BOOST_HTTP_TEST_READ_SOURCE_HPP -#include #include #include #include @@ -146,7 +145,7 @@ class read_source // The operation completes synchronously, but await_suspend is // the only place capy::await_context is delivered (the promise's - // transform_awaiter forwards it here). Returning false means + // awaiter forwards it here). Returning false means // the coroutine does not actually suspend; it resumes // immediately, having observed the stop token. See capy::await_context, // ContextAwaitable. diff --git a/include/boost/http/test/write_sink.hpp b/include/boost/http/test/write_sink.hpp index 5616c515..3873ba4c 100644 --- a/include/boost/http/test/write_sink.hpp +++ b/include/boost/http/test/write_sink.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_HTTP_TEST_WRITE_SINK_HPP #define BOOST_HTTP_TEST_WRITE_SINK_HPP -#include #include #include #include @@ -179,7 +178,7 @@ class write_sink // The operation completes synchronously, but await_suspend is // the only place capy::await_context is delivered (the promise's - // transform_awaiter forwards it here). Returning false means + // awaiter forwards it here). Returning false means // the coroutine does not actually suspend; it resumes // immediately, having observed the stop token. See capy::await_context, // ContextAwaitable. diff --git a/test/unit/io/any_buffer_sink.cpp b/test/unit/io/any_buffer_sink.cpp index b428a9e1..9a696e5b 100644 --- a/test/unit/io/any_buffer_sink.cpp +++ b/test/unit/io/any_buffer_sink.cpp @@ -9,6 +9,7 @@ // Test that header file is self-contained. #include +#include #include // Test that pull_from header is self-contained. @@ -405,7 +406,7 @@ class any_buffer_sink_test test::buffer_sink bs(f); any_buffer_sink abs(std::move(bs)); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -466,7 +467,7 @@ class any_buffer_sink_test test::buffer_sink bs(f); any_buffer_sink abs(&bs); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); BOOST_TEST(bufs[0].size() > 0); @@ -491,7 +492,7 @@ class any_buffer_sink_test test::buffer_sink bs(f); any_buffer_sink abs(&bs); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -515,7 +516,7 @@ class any_buffer_sink_test test::buffer_sink bs(f); any_buffer_sink abs(&bs); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -545,7 +546,7 @@ class any_buffer_sink_test // First write { - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -558,7 +559,7 @@ class any_buffer_sink_test // Second write { - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -711,7 +712,7 @@ class any_buffer_sink_test test::buffer_sink bs(f); any_buffer_sink abs(&bs); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); std::memcpy(bufs[0].data(), "data", 4); @@ -1149,7 +1150,7 @@ class any_buffer_sink_test buffer_write_sink bws(f); any_buffer_sink abs(&bws); - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; auto bufs = abs.prepare(arr); BOOST_TEST_EQ(bufs.size(), 1u); @@ -1360,7 +1361,7 @@ class any_buffer_sink_test any_buffer_sink abs(&sink); auto coro = [&]() -> capy::task { - mutable_buffer arr[capy::detail::max_iovec_]; + mutable_buffer arr[detail::max_iovec_]; abs.prepare(arr); auto [ec1] = co_await abs.commit(1); diff --git a/test/unit/io/any_buffer_source.cpp b/test/unit/io/any_buffer_source.cpp index 0f7cda23..19a7b5a2 100644 --- a/test/unit/io/any_buffer_source.cpp +++ b/test/unit/io/any_buffer_source.cpp @@ -9,6 +9,7 @@ // Test that header file is self-contained. #include +#include #include // Test that push_to header is self-contained. @@ -390,7 +391,7 @@ class any_buffer_source_test any_buffer_source abs(&src); auto coro = [&]() -> capy::task { - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; auto [ec1, bufs] = co_await abs.pull(arr); if(ec1) co_return 0; @@ -422,7 +423,7 @@ class any_buffer_source_test any_buffer_source abs(&bs); - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await abs.pull(arr); if(ec) co_return; @@ -444,7 +445,7 @@ class any_buffer_source_test any_buffer_source abs(&bs); - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; // First pull returns all data auto [ec1, bufs1] = co_await abs.pull(arr); @@ -485,7 +486,7 @@ class any_buffer_source_test any_buffer_source abs(&bs); - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; // Pull returns data auto [ec1, bufs1] = co_await abs.pull(arr); @@ -519,7 +520,7 @@ class any_buffer_source_test std::size_t total = 0; for(;;) { - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await abs.pull(arr); if(ec == capy::cond::eof) break; @@ -547,7 +548,7 @@ class any_buffer_source_test any_buffer_source abs(&bs); - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await abs.pull(arr); if(ec != capy::cond::eof) co_return; @@ -714,7 +715,7 @@ class any_buffer_source_test any_buffer_source abs(&brs); - const_buffer arr[capy::detail::max_iovec_]; + const_buffer arr[detail::max_iovec_]; auto [ec, bufs] = co_await abs.pull(arr); if(ec) co_return; diff --git a/test/unit/io/any_read_source.cpp b/test/unit/io/any_read_source.cpp index 94cab573..123d513e 100644 --- a/test/unit/io/any_read_source.cpp +++ b/test/unit/io/any_read_source.cpp @@ -9,6 +9,7 @@ // Test that header file is self-contained. #include +#include #include #include @@ -21,8 +22,6 @@ #include "test_helpers.hpp" -#include - #include #include #include @@ -695,7 +694,7 @@ class any_read_source_test { // Buffer sequence exceeds max_iovec_ -- verifies the // windowed loop fills every buffer in the sequence. - constexpr unsigned N = capy::detail::max_iovec_ + 4; + constexpr unsigned N = detail::max_iovec_ + 4; capy::test::fuse f; auto r = f.armed([&](capy::test::fuse&) -> capy::task<> { @@ -730,8 +729,8 @@ class any_read_source_test { // Buffer sequence exceeds max_iovec_ but data runs out // mid-way through the second window. - constexpr unsigned N = capy::detail::max_iovec_ + 4; - constexpr unsigned avail = capy::detail::max_iovec_ + 2; + constexpr unsigned N = detail::max_iovec_ + 4; + constexpr unsigned avail = detail::max_iovec_ + 2; capy::test::fuse f; auto r = f.armed([&](capy::test::fuse&) -> capy::task<> { diff --git a/test/unit/io/any_write_sink.cpp b/test/unit/io/any_write_sink.cpp index 606a028d..38b34dfd 100644 --- a/test/unit/io/any_write_sink.cpp +++ b/test/unit/io/any_write_sink.cpp @@ -9,6 +9,7 @@ // Test that header file is self-contained. #include +#include #include #include @@ -20,8 +21,6 @@ #include "test_helpers.hpp" -#include - #include #include #include @@ -556,7 +555,7 @@ class any_write_sink_test { // Buffer sequence exceeds max_iovec_ -- verifies the // windowed loop writes every buffer in the sequence. - constexpr unsigned N = capy::detail::max_iovec_ + 4; + constexpr unsigned N = detail::max_iovec_ + 4; capy::test::fuse f; auto r = f.armed([&](capy::test::fuse&) -> capy::task<> { @@ -591,7 +590,7 @@ class any_write_sink_test { // Buffer sequence exceeds max_iovec_ -- verifies the // last window is sent atomically with EOF via write_eof(buffers). - constexpr unsigned N = capy::detail::max_iovec_ + 4; + constexpr unsigned N = detail::max_iovec_ + 4; capy::test::fuse f; auto r = f.armed([&](capy::test::fuse&) -> capy::task<> { diff --git a/test/unit/io/buffer_param.cpp b/test/unit/io/buffer_param.cpp index cd2a5602..37481b7a 100644 --- a/test/unit/io/buffer_param.cpp +++ b/test/unit/io/buffer_param.cpp @@ -9,6 +9,7 @@ // Test that header file is self-contained. #include +#include #include "test_helpers.hpp" @@ -308,7 +309,7 @@ struct buffer_param_test // Exactly max_iovec_ buffers — fits in one window { - std::vector strings(capy::detail::max_iovec_, "x"); + std::vector strings(detail::max_iovec_, "x"); std::vector bufs; for(auto const& s : strings) bufs.emplace_back(s.data(), s.size()); @@ -322,7 +323,7 @@ struct buffer_param_test // One more than max_iovec_ — needs two windows { std::vector strings( - capy::detail::max_iovec_ + 1, "x"); + detail::max_iovec_ + 1, "x"); std::vector bufs; for(auto const& s : strings) bufs.emplace_back(s.data(), s.size());