From 4cc79259e4ba93bd476446f20cea47c52c31c156 Mon Sep 17 00:00:00 2001 From: Steve Gerbino Date: Fri, 27 Feb 2026 20:22:53 +0100 Subject: [PATCH] Architecture cleanup: header relocation, naming, docs, and formatting Enforce layer boundaries by relocating platform-dependent headers out of the type-erased detail/ scope. Standardize naming across the native layer, fix stale documentation, and apply project-wide formatting. Header relocation: - Move endpoint_convert.hpp and make_err.hpp from detail/ to native/detail/ (both include platform headers, consumed only by native backends) - Rename io_buffer_param.hpp to buffer_param.hpp and move from io/ to detail/ (concrete value type, not an abstract base) - Remove buffer_param from the umbrella header (not user-facing) Naming and API consistency: - Rename impl_type/get_impl() to implementation_type/get() in all native headers to match the convention used at the abstract and concrete layers - Rename io_buffer_param.cpp test to buffer_param.cpp to match the renamed header - Pass std::stop_token and tls_context by const reference where only read (removes 8 unnecessary-value-param suppressions) Code quality: - Remove unused includes detected via clangd/clang-tidy - Fix clang-tidy diagnostics: suppress bugprone-unused-return-value on tls_context setup calls, fix widening conversions, add reserve() before emplace_back loops, add std::move for pass-by-value tls_context - Convert inline NOLINT to NOLINTNEXTLINE where the trailing comment caused clang-format to split lines - Fix stale "Defined in sockets.cpp" comments in op headers to reference actual service headers after header/source merges - Merge duplicate block comments in kqueue_socket_service.hpp and posix_signal_service.hpp - Move includes from posix_resolver.hpp to posix_resolver_service.hpp where they are used Design documentation: - Add "Implementation leaf nodes" subsection to the native layer section covering inheritance chains, leaf node table, common structural patterns, IOCP two-class split, and timer special case - Fix native layer code example to match actual implementation (template, implementation_type/get() naming, backend_type trait aliases) - Add native_resolver to types table, fix backend tag and implementation header paths, update platform source layout Formatting: - Tune .clang-format: BinPackArguments false, AllowAllArgumentsOnNextLine false, AllowAllParametersOfDeclarationOnNextLine false, AlignConsecutiveAssignments false - Apply clang-format project-wide --- .cursor/rules/portable-headers.mdc | 111 +++++-------- doc/design/physical-structure.md | 2 +- .../ROOT/pages/4.guide/4n.buffers.adoc | 8 +- include/boost/corosio.hpp | 1 - include/boost/corosio/cancel.hpp | 34 ++-- .../boost/corosio/detail/acceptor_service.hpp | 12 +- .../buffer_param.hpp} | 48 +++--- .../corosio/detail/cancel_at_awaitable.hpp | 47 +++--- include/boost/corosio/detail/platform.hpp | 6 +- .../boost/corosio/detail/socket_service.hpp | 8 +- .../boost/corosio/detail/thread_local_ptr.hpp | 2 +- include/boost/corosio/detail/timeout_coro.hpp | 45 +++-- .../boost/corosio/detail/timer_service.hpp | 7 +- include/boost/corosio/io/io_read_stream.hpp | 4 +- include/boost/corosio/io/io_stream.hpp | 10 +- include/boost/corosio/io/io_write_stream.hpp | 4 +- include/boost/corosio/ipv6_address.hpp | 1 - .../{ => native}/detail/endpoint_convert.hpp | 44 +++-- .../native/detail/epoll/epoll_acceptor.hpp | 12 +- .../detail/epoll/epoll_acceptor_service.hpp | 37 ++--- .../corosio/native/detail/epoll/epoll_op.hpp | 10 +- .../native/detail/epoll/epoll_scheduler.hpp | 2 +- .../native/detail/epoll/epoll_socket.hpp | 16 +- .../detail/epoll/epoll_socket_service.hpp | 40 +++-- .../native/detail/iocp/win_acceptor.hpp | 12 +- .../detail/iocp/win_acceptor_service.hpp | 116 ++++++------- .../native/detail/iocp/win_overlapped_op.hpp | 4 +- .../native/detail/iocp/win_resolver.hpp | 4 +- .../native/detail/iocp/win_scheduler.hpp | 14 +- .../corosio/native/detail/iocp/win_socket.hpp | 20 ++- .../native/detail/iocp/win_sockets.hpp | 14 +- .../native/detail/iocp/win_wsa_init.hpp | 2 +- .../native/detail/kqueue/kqueue_acceptor.hpp | 12 +- .../detail/kqueue/kqueue_acceptor_service.hpp | 50 +++--- .../native/detail/kqueue/kqueue_scheduler.hpp | 4 +- .../native/detail/kqueue/kqueue_socket.hpp | 18 +- .../detail/kqueue/kqueue_socket_service.hpp | 43 +++-- .../corosio/{ => native}/detail/make_err.hpp | 4 +- .../native/detail/posix/posix_resolver.hpp | 6 +- .../detail/posix/posix_resolver_service.hpp | 6 +- .../native/detail/select/select_acceptor.hpp | 12 +- .../detail/select/select_acceptor_service.hpp | 33 ++-- .../native/detail/select/select_op.hpp | 13 +- .../native/detail/select/select_scheduler.hpp | 2 +- .../native/detail/select/select_socket.hpp | 16 +- .../detail/select/select_socket_service.hpp | 40 +++-- .../boost/corosio/native/native_cancel.hpp | 22 ++- .../corosio/native/native_socket_option.hpp | 143 +++++++++++----- include/boost/corosio/native/native_tcp.hpp | 31 +++- include/boost/corosio/openssl_stream.hpp | 6 +- include/boost/corosio/socket_option.hpp | 92 +++++++---- include/boost/corosio/tcp.hpp | 21 ++- include/boost/corosio/tcp_acceptor.hpp | 46 +++--- include/boost/corosio/tcp_socket.hpp | 35 ++-- include/boost/corosio/test/mocket.hpp | 3 +- include/boost/corosio/wolfssl_stream.hpp | 6 +- src/corosio/src/endpoint.cpp | 1 - src/corosio/src/socket_option.cpp | 138 ++++++++++++---- src/corosio/src/tcp.cpp | 2 +- src/corosio/src/tcp_acceptor.cpp | 4 +- src/corosio/src/tcp_socket.cpp | 10 +- test/unit/acceptor.cpp | 59 ++++--- test/unit/cancel.cpp | 28 ++-- test/unit/endpoint.cpp | 1 - test/unit/io_buffer_param.cpp | 34 ++-- test/unit/io_context.cpp | 27 ++- test/unit/ipv4_address.cpp | 1 - test/unit/ipv6_address.cpp | 1 - test/unit/native/iocp/iocp_shutdown.cpp | 19 +-- test/unit/native/native_cancel.cpp | 10 +- test/unit/openssl_stream.cpp | 4 +- test/unit/resolver.cpp | 1 - test/unit/socket.cpp | 149 ++++++++--------- test/unit/socket_stress.cpp | 2 +- test/unit/stream_tests.hpp | 2 + test/unit/tcp_server.cpp | 9 +- test/unit/test_utils.hpp | 155 ++++++++++++------ test/unit/timer.cpp | 10 +- test/unit/tls_stream_stress.cpp | 5 +- test/unit/tls_stream_tests.hpp | 24 +-- test/unit/wolfssl_stream.cpp | 4 +- 81 files changed, 1111 insertions(+), 950 deletions(-) rename include/boost/corosio/{io_buffer_param.hpp => detail/buffer_param.hpp} (90%) rename include/boost/corosio/{ => native}/detail/endpoint_convert.hpp (85%) rename include/boost/corosio/{ => native}/detail/make_err.hpp (95%) diff --git a/.cursor/rules/portable-headers.mdc b/.cursor/rules/portable-headers.mdc index 28b26c5b..8ff8a249 100644 --- a/.cursor/rules/portable-headers.mdc +++ b/.cursor/rules/portable-headers.mdc @@ -1,116 +1,81 @@ --- -description: No non-portable header includes in public headers +description: No non-portable header includes in type-erased public headers alwaysApply: false --- # Portable Headers Rule -**All headers in `include/boost/corosio/` (including all subdirectories) MUST NOT include platform-specific headers.** +**Headers in `include/boost/corosio/` and `include/boost/corosio/detail/` MUST NOT include platform-specific headers.** -## Scope - -**Public headers**: ANY header file in `include/boost/corosio/` or any of its subdirectories. +The `native/` subtree (`include/boost/corosio/native/`) is exempt — it is the direct/native API that deliberately exposes platform types. -Examples: -- `include/boost/corosio/endpoint.hpp` -- `include/boost/corosio/detail/config.hpp` -- `include/boost/corosio/concept/...` +## Scope -The entire `include/` tree is considered public API. This includes `detail/`, `concept/`, and any other subdirectories. +**Type-erased headers** (platform includes FORBIDDEN): +- `include/boost/corosio/*.hpp` +- `include/boost/corosio/detail/*.hpp` +- `include/boost/corosio/concept/*.hpp` -## Prohibited Headers +**Native/direct headers** (platform includes ALLOWED): +- `include/boost/corosio/native/*.hpp` +- `include/boost/corosio/native/detail/**/*.hpp` -The following types of headers are **FORBIDDEN** in public headers: +## Prohibited Headers (in type-erased scope) ### Windows-specific -- `` -- `` -- `` -- `` +- ``, ``, ``, `` - Any other Windows SDK headers ### Unix/POSIX-specific -- `` -- `` -- `` -- `` -- `` +- ``, ``, ``, ``, `` +- `` when used for platform-specific constants (e.g., `ECANCELED`) - Any other POSIX/Unix-specific headers ### Platform-specific macros and types -- Any macros or types that require platform-specific headers -- Platform-specific constants (e.g., `AF_INET`, `INADDR_ANY`) +- Constants like `AF_INET`, `INADDR_ANY`, `ECANCELED`, `ERROR_OPERATION_ABORTED` +- Types like `sockaddr_in`, `sockaddr_in6`, `sockaddr_storage`, `SOCKET` -## Allowed Locations +## Allowed Locations for Platform-Specific Code -Platform-specific code is **ONLY** allowed in: - -- Implementation files in `src/` -- Platform abstraction layers in `src/` +- `include/boost/corosio/native/` and `include/boost/corosio/native/detail/` (direct API) +- Implementation files in `src/` (compilation firewall) ## Rationale -1. **Portability**: Public headers should compile on any platform without platform-specific dependencies -2. **Maintainability**: Platform-specific code should be isolated in implementation files -3. **User Experience**: Users should not be exposed to platform-specific types or headers -4. **Clean API**: The public API should be platform-agnostic +The library has two API layers: +1. **Type-erased** (`corosio/` and `corosio/detail/`): portable, no platform headers leak to users +2. **Native/direct** (`corosio/native/`): opt-in, exposes platform types for zero-overhead access ## Examples -### ❌ Bad (in public header) +### Bad (platform header in type-erased scope) ```cpp -// include/boost/corosio/endpoint.hpp -#ifdef _WIN32 -#include -#else +// include/boost/corosio/detail/endpoint_convert.hpp ← WRONG location +#include #include -#endif +``` -class endpoint { - sockaddr_in to_sockaddr_in() const; // Platform-specific type -}; +### Good (platform header in native scope) +```cpp +// include/boost/corosio/native/detail/endpoint_convert.hpp ← correct +#include +#include ``` -### ✅ Good (in public header) +### Good (type-erased public header) ```cpp // include/boost/corosio/endpoint.hpp -#include #include class endpoint { - urls::ipv4_address v4_address() const noexcept; + ipv4_address v4_address() const noexcept; std::uint16_t port() const noexcept; }; ``` -### ✅ Good (in implementation file) -```cpp -// src/src/detail/endpoint_convert.hpp -#ifdef _WIN32 -#include -#else -#include -#endif - -#include - -namespace boost { -namespace corosio { -namespace detail { - -sockaddr_in to_sockaddr_in(endpoint const& ep) { - // Platform-specific conversion logic -} - -} // namespace detail -} // namespace corosio -} // namespace boost -``` - ## Enforcement -When adding or modifying public headers: +When adding or modifying headers in the type-erased scope: -1. Check all `#include` directives -2. Ensure no platform-specific headers are included -3. Move any platform-specific code to `src/` implementation files -4. Use platform abstraction utilities in `src/src/detail/` for conversions +1. Check all `#include` directives for platform-specific headers +2. If platform types are needed, the header belongs in `native/detail/` +3. Type-erased code reaches platform APIs only through `src/` compiled translation units diff --git a/doc/design/physical-structure.md b/doc/design/physical-structure.md index 972e00af..5dfc0533 100644 --- a/doc/design/physical-structure.md +++ b/doc/design/physical-structure.md @@ -106,7 +106,7 @@ public: virtual std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t* ) = 0; diff --git a/doc/modules/ROOT/pages/4.guide/4n.buffers.adoc b/doc/modules/ROOT/pages/4.guide/4n.buffers.adoc index 24503138..1f08cc35 100644 --- a/doc/modules/ROOT/pages/4.guide/4n.buffers.adoc +++ b/doc/modules/ROOT/pages/4.guide/4n.buffers.adoc @@ -160,15 +160,15 @@ consuming.consume(n); // Advance by bytes read This is used internally by `read()` and `write()` but can be used directly. -== io_buffer_param +== buffer_param -The `io_buffer_param` class type-erases buffer sequences: +The `buffer_param` class type-erases buffer sequences: [source,cpp] ---- -#include +#include -void accept_any_buffer(corosio::io_buffer_param buffers) +void accept_any_buffer(corosio::buffer_param buffers) { capy::mutable_buffer temp[8]; std::size_t n = buffers.copy_to(temp, 8); diff --git a/include/boost/corosio.hpp b/include/boost/corosio.hpp index 214dbafc..8ff521b8 100644 --- a/include/boost/corosio.hpp +++ b/include/boost/corosio.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/corosio/cancel.hpp b/include/boost/corosio/cancel.hpp index 568e77df..8e6901f1 100644 --- a/include/boost/corosio/cancel.hpp +++ b/include/boost/corosio/cancel.hpp @@ -63,13 +63,10 @@ namespace boost::corosio { @see cancel_after */ -auto cancel_at( - capy::IoAwaitable auto&& op, - timer& t, - timer::time_point deadline) +auto +cancel_at(capy::IoAwaitable auto&& op, timer& t, timer::time_point deadline) { - return detail::cancel_at_awaitable< - std::decay_t, timer>( + return detail::cancel_at_awaitable, timer>( std::forward(op), t, deadline); } @@ -110,14 +107,11 @@ auto cancel_at( @see cancel_at */ -auto cancel_after( - capy::IoAwaitable auto&& op, - timer& t, - timer::duration timeout) +auto +cancel_after(capy::IoAwaitable auto&& op, timer& t, timer::duration timeout) { return cancel_at( - std::forward(op), t, - timer::clock_type::now() + timeout); + std::forward(op), t, timer::clock_type::now() + timeout); } /** Cancel an operation if it does not complete by a deadline. @@ -155,12 +149,10 @@ auto cancel_after( @see cancel_after */ -auto cancel_at( - capy::IoAwaitable auto&& op, - timer::time_point deadline) +auto +cancel_at(capy::IoAwaitable auto&& op, timer::time_point deadline) { - return detail::cancel_at_awaitable< - std::decay_t, timer, true>( + return detail::cancel_at_awaitable, timer, true>( std::forward(op), deadline); } @@ -198,13 +190,11 @@ auto cancel_at( @see cancel_at */ -auto cancel_after( - capy::IoAwaitable auto&& op, - timer::duration timeout) +auto +cancel_after(capy::IoAwaitable auto&& op, timer::duration timeout) { return cancel_at( - std::forward(op), - timer::clock_type::now() + timeout); + std::forward(op), timer::clock_type::now() + timeout); } } // namespace boost::corosio diff --git a/include/boost/corosio/detail/acceptor_service.hpp b/include/boost/corosio/detail/acceptor_service.hpp index 072f348d..33135d8e 100644 --- a/include/boost/corosio/detail/acceptor_service.hpp +++ b/include/boost/corosio/detail/acceptor_service.hpp @@ -47,7 +47,9 @@ class BOOST_COROSIO_DECL acceptor_service */ virtual std::error_code open_acceptor_socket( tcp_acceptor::implementation& impl, - int family, int type, int protocol) = 0; + int family, + int type, + int protocol) = 0; /** Bind an open acceptor to a local endpoint. @@ -55,8 +57,8 @@ class BOOST_COROSIO_DECL acceptor_service @param ep The local endpoint to bind to. @return Error code on failure, empty on success. */ - virtual std::error_code bind_acceptor( - tcp_acceptor::implementation& impl, endpoint ep) = 0; + virtual std::error_code + bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) = 0; /** Start listening for incoming connections. @@ -67,8 +69,8 @@ class BOOST_COROSIO_DECL acceptor_service @param backlog The maximum length of the pending connection queue. @return Error code on failure, empty on success. */ - virtual std::error_code listen_acceptor( - tcp_acceptor::implementation& impl, int backlog) = 0; + virtual std::error_code + listen_acceptor(tcp_acceptor::implementation& impl, int backlog) = 0; protected: /// Construct the acceptor service. diff --git a/include/boost/corosio/io_buffer_param.hpp b/include/boost/corosio/detail/buffer_param.hpp similarity index 90% rename from include/boost/corosio/io_buffer_param.hpp rename to include/boost/corosio/detail/buffer_param.hpp index d4dbf1c5..574d722a 100644 --- a/include/boost/corosio/io_buffer_param.hpp +++ b/include/boost/corosio/detail/buffer_param.hpp @@ -7,8 +7,8 @@ // Official repository: https://github.com/cppalliance/corosio // -#ifndef BOOST_COROSIO_IO_BUFFER_PARAM_HPP -#define BOOST_COROSIO_IO_BUFFER_PARAM_HPP +#ifndef BOOST_COROSIO_DETAIL_BUFFER_PARAM_HPP +#define BOOST_COROSIO_DETAIL_BUFFER_PARAM_HPP #include #include @@ -55,7 +55,7 @@ namespace boost::corosio { The referenced buffer sequence is valid ONLY while the calling coroutine remains suspended at the exact suspension point where - `io_buffer_param` was created. Once the coroutine resumes, + `buffer_param` was created. Once the coroutine resumes, returns, or is destroyed, all referenced data becomes invalid. @par Const Buffer Handling @@ -75,7 +75,7 @@ namespace boost::corosio { @code // For write operations (const buffers): - void submit_write(io_buffer_param p) + void submit_write(buffer_param p) { capy::mutable_buffer bufs[8]; auto n = p.copy_to(bufs, 8); @@ -84,7 +84,7 @@ namespace boost::corosio { } // For read operations (mutable buffers): - void submit_read(io_buffer_param p) + void submit_read(buffer_param p) { capy::mutable_buffer bufs[8]; auto n = p.copy_to(bufs, 8); @@ -95,11 +95,11 @@ namespace boost::corosio { @par Correct Usage - The implementation receiving `io_buffer_param` MUST: + The implementation receiving `buffer_param` MUST: @li Call `copy_to` immediately upon receiving the parameter @li Use the unrolled buffer descriptors for the I/O operation - @li Never store the `io_buffer_param` object itself + @li Never store the `buffer_param` object itself @li Never store pointers obtained from `copy_to` beyond the immediate I/O operation @@ -128,7 +128,7 @@ namespace boost::corosio { // Virtual implementation - unrolls immediately void stream_impl::async_write_some_impl( - io_buffer_param p, + buffer_param p, std::coroutine_handle<> h) { // CORRECT: Unroll immediately into platform structure @@ -145,16 +145,16 @@ namespace boost::corosio { } @endcode - @par UNSAFE USAGE: Storing io_buffer_param + @par UNSAFE USAGE: Storing buffer_param - @warning Never store `io_buffer_param` for later use. + @warning Never store `buffer_param` for later use. @code class broken_stream { - io_buffer_param saved_param_; // UNSAFE: member storage + buffer_param saved_param_; // UNSAFE: member storage - void async_write_impl(io_buffer_param p, ...) + void async_write_impl(buffer_param p, ...) { saved_param_ = p; // UNSAFE: storing for later schedule_write_later(); @@ -183,7 +183,7 @@ namespace boost::corosio { capy::mutable_buffer saved_bufs_[8]; // UNSAFE std::size_t saved_count_; - void async_write_impl(io_buffer_param p, ...) + void async_write_impl(buffer_param p, ...) { // This copies pointer/size pairs into saved_bufs_ saved_count_ = p.copy_to(saved_bufs_, 8); @@ -226,11 +226,11 @@ namespace boost::corosio { @par UNSAFE USAGE: Passing to Another Coroutine - @warning Do not pass `io_buffer_param` to a different coroutine + @warning Do not pass `buffer_param` to a different coroutine or spawn a new coroutine that captures it. @code - void broken_impl(io_buffer_param p, std::coroutine_handle<> h) + void broken_impl(buffer_param p, std::coroutine_handle<> h) { // UNSAFE: Spawning a new coroutine that captures 'p'. // The original coroutine may resume before this new @@ -247,18 +247,18 @@ namespace boost::corosio { @par UNSAFE USAGE: Multiple Virtual Hops @warning Minimize indirection. Each virtual call that passes - `io_buffer_param` without immediately unrolling it increases + `buffer_param` without immediately unrolling it increases the risk of misuse. @code // Risky: multiple hops before unrolling - void layer1(io_buffer_param p) { + void layer1(buffer_param p) { layer2(p); // Still haven't unrolled... } - void layer2(io_buffer_param p) { + void layer2(buffer_param p) { layer3(p); // Still haven't unrolled... } - void layer3(io_buffer_param p) { + void layer3(buffer_param p) { // Finally unrolling, but the chain is fragile. // Any intermediate layer storing 'p' breaks everything. } @@ -290,15 +290,15 @@ namespace boost::corosio { @code // Preferred: pass by value - void process(io_buffer_param buffers); + void process(buffer_param buffers); // Also acceptable: pass by const reference - void process(io_buffer_param const& buffers); + void process(buffer_param const& buffers); @endcode @see capy::ConstBufferSequence, capy::MutableBufferSequence */ -class io_buffer_param +class buffer_param { public: /** Construct from a const buffer sequence. @@ -306,8 +306,8 @@ class io_buffer_param @param bs The buffer sequence to adapt. */ template - io_buffer_param(BS const& bs) noexcept : bs_(&bs) - , fn_(©_impl) + buffer_param(BS const& bs) noexcept : bs_(&bs) + , fn_(©_impl) { } diff --git a/include/boost/corosio/detail/cancel_at_awaitable.hpp b/include/boost/corosio/detail/cancel_at_awaitable.hpp index 4f3bfee4..b7cf559b 100644 --- a/include/boost/corosio/detail/cancel_at_awaitable.hpp +++ b/include/boost/corosio/detail/cancel_at_awaitable.hpp @@ -69,10 +69,10 @@ struct cancel_at_awaitable } }; - using time_point = std::chrono::steady_clock::time_point; + using time_point = std::chrono::steady_clock::time_point; using stop_cb_type = std::stop_callback; - using timer_storage = std::conditional_t< - Owning, std::optional, Timer*>; + using timer_storage = + std::conditional_t, Timer*>; A inner_; timer_storage timer_; @@ -83,11 +83,8 @@ struct cancel_at_awaitable bool cb_active_ = false; /// Construct with a caller-supplied timer reference. - cancel_at_awaitable( - A&& inner, - Timer& timer, - time_point deadline) - requires (!Owning) + cancel_at_awaitable(A&& inner, Timer& timer, time_point deadline) + requires(!Owning) : inner_(std::move(inner)) , timer_(&timer) , deadline_(deadline) @@ -95,9 +92,7 @@ struct cancel_at_awaitable } /// Construct without a timer (created in `await_suspend`). - cancel_at_awaitable( - A&& inner, - time_point deadline) + cancel_at_awaitable(A&& inner, time_point deadline) requires Owning : inner_(std::move(inner)) , deadline_(deadline) @@ -119,15 +114,16 @@ struct cancel_at_awaitable { } - cancel_at_awaitable(cancel_at_awaitable const&) = delete; + cancel_at_awaitable(cancel_at_awaitable const&) = delete; cancel_at_awaitable& operator=(cancel_at_awaitable const&) = delete; - cancel_at_awaitable& operator=(cancel_at_awaitable&&) = delete; + cancel_at_awaitable& operator=(cancel_at_awaitable&&) = delete; - bool await_ready() const noexcept { return false; } + bool await_ready() const noexcept + { + return false; + } - auto await_suspend( - std::coroutine_handle<> h, - capy::io_env const* env) + auto await_suspend(std::coroutine_handle<> h, capy::io_env const* env) { if constexpr (Owning) timer_.emplace(env->executor.context()); @@ -136,25 +132,20 @@ struct cancel_at_awaitable // Launch fire-and-forget timeout (starts suspended) auto timeout = make_timeout(*timer_, stop_src_); - timeout.h_.promise().set_env_owned({ - env->executor, - stop_src_.get_token(), - env->frame_allocator}); + timeout.h_.promise().set_env_owned( + {env->executor, stop_src_.get_token(), env->frame_allocator}); // Runs synchronously until timer.wait() suspends timeout.h_.resume(); // timeout goes out of scope; destructor is a no-op, // the coroutine self-destroys via suspend_never // Forward parent cancellation - new (cb_buf_) stop_cb_type( - env->stop_token, stop_forwarder{&stop_src_}); + new (cb_buf_) stop_cb_type(env->stop_token, stop_forwarder{&stop_src_}); cb_active_ = true; // Start the inner op with our interposed stop_token inner_env_ = { - env->executor, - stop_src_.get_token(), - env->frame_allocator}; + env->executor, stop_src_.get_token(), env->frame_allocator}; return inner_.await_suspend(h, &inner_env_); } @@ -170,8 +161,8 @@ struct cancel_at_awaitable { if (cb_active_) { - std::launder(reinterpret_cast( - cb_buf_))->~stop_cb_type(); + std::launder(reinterpret_cast(cb_buf_)) + ->~stop_cb_type(); cb_active_ = false; } } diff --git a/include/boost/corosio/detail/platform.hpp b/include/boost/corosio/detail/platform.hpp index c5dd1379..cc0ae48d 100644 --- a/include/boost/corosio/detail/platform.hpp +++ b/include/boost/corosio/detail/platform.hpp @@ -20,11 +20,11 @@ // generated reference. The native_* headers skip the real // implementation includes under this guard, so no platform // system headers are required. -#define BOOST_COROSIO_HAS_IOCP 1 -#define BOOST_COROSIO_HAS_EPOLL 1 +#define BOOST_COROSIO_HAS_IOCP 1 +#define BOOST_COROSIO_HAS_EPOLL 1 #define BOOST_COROSIO_HAS_KQUEUE 1 #define BOOST_COROSIO_HAS_SELECT 1 -#define BOOST_COROSIO_POSIX 1 +#define BOOST_COROSIO_POSIX 1 #else // !BOOST_COROSIO_MRDOCS diff --git a/include/boost/corosio/detail/socket_service.hpp b/include/boost/corosio/detail/socket_service.hpp index 3695701c..307b822f 100644 --- a/include/boost/corosio/detail/socket_service.hpp +++ b/include/boost/corosio/detail/socket_service.hpp @@ -43,9 +43,11 @@ class BOOST_COROSIO_DECL socket_service @param protocol Protocol number (e.g. `IPPROTO_TCP`). @return Error code on failure, empty on success. */ - virtual std::error_code - open_socket( tcp_socket::implementation& impl, - int family, int type, int protocol ) = 0; + virtual std::error_code open_socket( + tcp_socket::implementation& impl, + int family, + int type, + int protocol) = 0; protected: /// Construct the socket service. diff --git a/include/boost/corosio/detail/thread_local_ptr.hpp b/include/boost/corosio/detail/thread_local_ptr.hpp index 0895c22f..55280cfc 100644 --- a/include/boost/corosio/detail/thread_local_ptr.hpp +++ b/include/boost/corosio/detail/thread_local_ptr.hpp @@ -1,6 +1,6 @@ // // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2026 Steve Gerbino +// 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) diff --git a/include/boost/corosio/detail/timeout_coro.hpp b/include/boost/corosio/detail/timeout_coro.hpp index 5326aaf9..905af539 100644 --- a/include/boost/corosio/detail/timeout_coro.hpp +++ b/include/boost/corosio/detail/timeout_coro.hpp @@ -46,8 +46,7 @@ namespace boost::corosio::detail { */ struct timeout_coro { - struct promise_type - : capy::io_awaitable_promise_base + struct promise_type : capy::io_awaitable_promise_base { capy::io_env env_storage_; @@ -66,12 +65,17 @@ struct timeout_coro timeout_coro get_return_object() noexcept { return timeout_coro{ - std::coroutine_handle::from_promise( - *this)}; + std::coroutine_handle::from_promise(*this)}; } - std::suspend_always initial_suspend() noexcept { return {}; } - std::suspend_never final_suspend() noexcept { return {}; } + std::suspend_always initial_suspend() noexcept + { + return {}; + } + std::suspend_never final_suspend() noexcept + { + return {}; + } void return_void() noexcept {} void unhandled_exception() noexcept {} @@ -94,19 +98,14 @@ struct timeout_coro } template - auto await_suspend( - std::coroutine_handle h) noexcept + auto await_suspend(std::coroutine_handle h) noexcept { #ifdef _MSC_VER - using R = decltype( - a_.await_suspend(h, p_->environment())); - if constexpr (std::is_same_v< - R, std::coroutine_handle<>>) - a_.await_suspend(h, p_->environment()) - .resume(); + using R = decltype(a_.await_suspend(h, p_->environment())); + if constexpr (std::is_same_v>) + a_.await_suspend(h, p_->environment()).resume(); else - return a_.await_suspend( - h, p_->environment()); + return a_.await_suspend(h, p_->environment()); #else return a_.await_suspend(h, p_->environment()); #endif @@ -124,8 +123,7 @@ struct timeout_coro } else { - static_assert( - sizeof(A) == 0, "requires IoAwaitable"); + static_assert(sizeof(A) == 0, "requires IoAwaitable"); } } }; @@ -134,8 +132,7 @@ struct timeout_coro timeout_coro() noexcept : h_(nullptr) {} - explicit timeout_coro( - std::coroutine_handle h) noexcept + explicit timeout_coro(std::coroutine_handle h) noexcept : h_(h) { } @@ -143,11 +140,10 @@ struct timeout_coro // Self-destroying via suspend_never at final_suspend ~timeout_coro() = default; - timeout_coro(timeout_coro const&) = delete; + timeout_coro(timeout_coro const&) = delete; timeout_coro& operator=(timeout_coro const&) = delete; - timeout_coro(timeout_coro&& o) noexcept - : h_(o.h_) + timeout_coro(timeout_coro&& o) noexcept : h_(o.h_) { o.h_ = nullptr; } @@ -171,7 +167,8 @@ struct timeout_coro @param src Stop source to signal on timeout. */ template -timeout_coro make_timeout(Timer& t, std::stop_source src) +timeout_coro +make_timeout(Timer& t, std::stop_source src) { auto [ec] = co_await t.wait(); if (!ec) diff --git a/include/boost/corosio/detail/timer_service.hpp b/include/boost/corosio/detail/timer_service.hpp index 063f8101..fd061d47 100644 --- a/include/boost/corosio/detail/timer_service.hpp +++ b/include/boost/corosio/detail/timer_service.hpp @@ -729,7 +729,10 @@ waiter_node::canceller::operator()() const inline void waiter_node::completion_op::do_complete( - [[maybe_unused]] void* owner, scheduler_op* base, std::uint32_t, std::uint32_t) + [[maybe_unused]] void* owner, + scheduler_op* base, + std::uint32_t, + std::uint32_t) { // owner is always non-null here. The destroy path (owner == nullptr) // is unreachable because completion_op overrides destroy() directly, @@ -773,7 +776,7 @@ waiter_node::completion_op::destroy() // which drains waiters still in the timer heap (the other path). auto* w = waiter_; w->stop_cb_.reset(); - auto h = std::exchange(w->h_, {}); + auto h = std::exchange(w->h_, {}); auto& sched = w->svc_->get_scheduler(); delete w; sched.work_finished(); diff --git a/include/boost/corosio/io/io_read_stream.hpp b/include/boost/corosio/io/io_read_stream.hpp index 798a7d81..5ac36039 100644 --- a/include/boost/corosio/io/io_read_stream.hpp +++ b/include/boost/corosio/io/io_read_stream.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ class BOOST_COROSIO_DECL io_read_stream : virtual public io_object virtual std::coroutine_handle<> do_read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) = 0; diff --git a/include/boost/corosio/io/io_stream.hpp b/include/boost/corosio/io/io_stream.hpp index 2d77899b..5eb3bfe5 100644 --- a/include/boost/corosio/io/io_stream.hpp +++ b/include/boost/corosio/io/io_stream.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -88,7 +88,7 @@ class BOOST_COROSIO_DECL io_stream virtual std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) = 0; @@ -97,7 +97,7 @@ class BOOST_COROSIO_DECL io_stream virtual std::coroutine_handle<> write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) = 0; @@ -113,7 +113,7 @@ class BOOST_COROSIO_DECL io_stream std::coroutine_handle<> do_read_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param buffers, + buffer_param buffers, std::stop_token token, std::error_code* ec, std::size_t* bytes) override @@ -125,7 +125,7 @@ class BOOST_COROSIO_DECL io_stream std::coroutine_handle<> do_write_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param buffers, + buffer_param buffers, std::stop_token token, std::error_code* ec, std::size_t* bytes) override diff --git a/include/boost/corosio/io/io_write_stream.hpp b/include/boost/corosio/io/io_write_stream.hpp index 9cbe19a5..3b628755 100644 --- a/include/boost/corosio/io/io_write_stream.hpp +++ b/include/boost/corosio/io/io_write_stream.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ class BOOST_COROSIO_DECL io_write_stream : virtual public io_object virtual std::coroutine_handle<> do_write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) = 0; diff --git a/include/boost/corosio/ipv6_address.hpp b/include/boost/corosio/ipv6_address.hpp index 6240415d..155df418 100644 --- a/include/boost/corosio/ipv6_address.hpp +++ b/include/boost/corosio/ipv6_address.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/include/boost/corosio/detail/endpoint_convert.hpp b/include/boost/corosio/native/detail/endpoint_convert.hpp similarity index 85% rename from include/boost/corosio/detail/endpoint_convert.hpp rename to include/boost/corosio/native/detail/endpoint_convert.hpp index ea66522b..590a6db9 100644 --- a/include/boost/corosio/detail/endpoint_convert.hpp +++ b/include/boost/corosio/native/detail/endpoint_convert.hpp @@ -7,8 +7,8 @@ // Official repository: https://github.com/cppalliance/corosio // -#ifndef BOOST_COROSIO_DETAIL_ENDPOINT_CONVERT_HPP -#define BOOST_COROSIO_DETAIL_ENDPOINT_CONVERT_HPP +#ifndef BOOST_COROSIO_NATIVE_DETAIL_ENDPOINT_CONVERT_HPP +#define BOOST_COROSIO_NATIVE_DETAIL_ENDPOINT_CONVERT_HPP #include #include @@ -107,7 +107,7 @@ to_v4_mapped_sockaddr_in6(endpoint const& ep) noexcept // ::ffff:0:0/96 prefix sa.sin6_addr.s6_addr[10] = 0xff; sa.sin6_addr.s6_addr[11] = 0xff; - auto bytes = ep.v4_address().to_bytes(); + auto bytes = ep.v4_address().to_bytes(); std::memcpy(&sa.sin6_addr.s6_addr[12], bytes.data(), 4); return sa; } @@ -122,18 +122,18 @@ to_v4_mapped_sockaddr_in6(endpoint const& ep) noexcept @return The length of the filled sockaddr structure. */ inline socklen_t -to_sockaddr( endpoint const& ep, sockaddr_storage& storage ) noexcept +to_sockaddr(endpoint const& ep, sockaddr_storage& storage) noexcept { - std::memset( &storage, 0, sizeof( storage ) ); - if( ep.is_v4() ) + std::memset(&storage, 0, sizeof(storage)); + if (ep.is_v4()) { - auto sa = to_sockaddr_in( ep ); - std::memcpy( &storage, &sa, sizeof( sa ) ); - return sizeof( sa ); + auto sa = to_sockaddr_in(ep); + std::memcpy(&storage, &sa, sizeof(sa)); + return sizeof(sa); } - auto sa6 = to_sockaddr_in6( ep ); - std::memcpy( &storage, &sa6, sizeof( sa6 ) ); - return sizeof( sa6 ); + auto sa6 = to_sockaddr_in6(ep); + std::memcpy(&storage, &sa6, sizeof(sa6)); + return sizeof(sa6); } /** Convert endpoint to sockaddr_storage for a specific socket family. @@ -150,9 +150,7 @@ to_sockaddr( endpoint const& ep, sockaddr_storage& storage ) noexcept */ inline socklen_t to_sockaddr( - endpoint const& ep, - int socket_family, - sockaddr_storage& storage) noexcept + endpoint const& ep, int socket_family, sockaddr_storage& storage) noexcept { // IPv4 endpoint on IPv6 socket: use IPv4-mapped address if (ep.is_v4() && socket_family == AF_INET6) @@ -174,19 +172,19 @@ to_sockaddr( @return An endpoint with address and port extracted from storage. */ inline endpoint -from_sockaddr( sockaddr_storage const& storage ) noexcept +from_sockaddr(sockaddr_storage const& storage) noexcept { - if( storage.ss_family == AF_INET ) + if (storage.ss_family == AF_INET) { sockaddr_in sa; - std::memcpy( &sa, &storage, sizeof( sa ) ); - return from_sockaddr_in( sa ); + std::memcpy(&sa, &storage, sizeof(sa)); + return from_sockaddr_in(sa); } - if( storage.ss_family == AF_INET6 ) + if (storage.ss_family == AF_INET6) { sockaddr_in6 sa6; - std::memcpy( &sa6, &storage, sizeof( sa6 ) ); - return from_sockaddr_in6( sa6 ); + std::memcpy(&sa6, &storage, sizeof(sa6)); + return from_sockaddr_in6(sa6); } return endpoint{}; } @@ -197,7 +195,7 @@ from_sockaddr( sockaddr_storage const& storage ) noexcept @return `AF_INET` for IPv4, `AF_INET6` for IPv6. */ inline int -endpoint_family( endpoint const& ep ) noexcept +endpoint_family(endpoint const& ep) noexcept { return ep.is_v6() ? AF_INET6 : AF_INET; } diff --git a/include/boost/corosio/native/detail/epoll/epoll_acceptor.hpp b/include/boost/corosio/native/detail/epoll/epoll_acceptor.hpp index 530e575c..5e502aaf 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_acceptor.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_acceptor.hpp @@ -59,11 +59,13 @@ class epoll_acceptor final void cancel() noexcept override; std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; void cancel_single_op(epoll_op& op) noexcept; void close_socket() noexcept; void set_local_endpoint(endpoint ep) noexcept diff --git a/include/boost/corosio/native/detail/epoll/epoll_acceptor_service.hpp b/include/boost/corosio/native/detail/epoll/epoll_acceptor_service.hpp index 9227de3e..72e5df56 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_acceptor_service.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_acceptor_service.hpp @@ -22,9 +22,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -76,11 +76,13 @@ class BOOST_COROSIO_DECL epoll_acceptor_service final : public acceptor_service void close(io_object::handle&) override; std::error_code open_acceptor_socket( tcp_acceptor::implementation& impl, - int family, int type, int protocol) override; - std::error_code bind_acceptor( - tcp_acceptor::implementation& impl, endpoint ep) override; - std::error_code listen_acceptor( - tcp_acceptor::implementation& impl, int backlog) override; + int family, + int type, + int protocol) override; + std::error_code + bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) override; + std::error_code + listen_acceptor(tcp_acceptor::implementation& impl, int backlog) override; epoll_scheduler& scheduler() const noexcept { @@ -263,8 +265,8 @@ epoll_acceptor::accept( return dispatch_coro(ex, h); } - op.accepted_fd = accepted; - op.peer_storage = peer_storage; + op.accepted_fd = accepted; + op.peer_storage = peer_storage; op.complete(0, 0); op.impl_ptr = shared_from_this(); svc_.post(&op); @@ -431,19 +433,17 @@ epoll_acceptor_service::close(io_object::handle& h) inline std::error_code epoll_acceptor::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); return {}; } inline std::error_code epoll_acceptor::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -454,8 +454,7 @@ epoll_acceptor::get_option( inline std::error_code epoll_acceptor_service::open_acceptor_socket( - tcp_acceptor::implementation& impl, - int family, int type, int protocol) + tcp_acceptor::implementation& impl, int family, int type, int protocol) { auto* epoll_impl = static_cast(&impl); epoll_impl->close_socket(); @@ -487,7 +486,7 @@ epoll_acceptor_service::bind_acceptor( tcp_acceptor::implementation& impl, endpoint ep) { auto* epoll_impl = static_cast(&impl); - int fd = epoll_impl->fd_; + int fd = epoll_impl->fd_; sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, storage); @@ -508,7 +507,7 @@ epoll_acceptor_service::listen_acceptor( tcp_acceptor::implementation& impl, int backlog) { auto* epoll_impl = static_cast(&impl); - int fd = epoll_impl->fd_; + int fd = epoll_impl->fd_; if (::listen(fd, backlog) < 0) return make_err(errno); diff --git a/include/boost/corosio/native/detail/epoll/epoll_op.hpp b/include/boost/corosio/native/detail/epoll/epoll_op.hpp index 1c588d6b..1a67a2be 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_op.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_op.hpp @@ -22,10 +22,10 @@ #include #include -#include +#include #include #include -#include +#include #include #include @@ -222,8 +222,7 @@ struct epoll_op : scheduler_op cancelled.store(true, std::memory_order_release); } - // NOLINTNEXTLINE(performance-unnecessary-value-param) - void start(std::stop_token token, epoll_socket* impl) + void start(std::stop_token const& token, epoll_socket* impl) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); @@ -234,8 +233,7 @@ struct epoll_op : scheduler_op stop_cb.emplace(token, canceller{this}); } - // NOLINTNEXTLINE(performance-unnecessary-value-param) - void start(std::stop_token token, epoll_acceptor* impl) + void start(std::stop_token const& token, epoll_acceptor* impl) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); diff --git a/include/boost/corosio/native/detail/epoll/epoll_scheduler.hpp b/include/boost/corosio/native/detail/epoll/epoll_scheduler.hpp index 8bca20bc..63ebb0e9 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_scheduler.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_scheduler.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/include/boost/corosio/native/detail/epoll/epoll_socket.hpp b/include/boost/corosio/native/detail/epoll/epoll_socket.hpp index 20243005..b1c8a4d6 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_socket.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_socket.hpp @@ -48,7 +48,7 @@ class epoll_socket final std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -56,7 +56,7 @@ class epoll_socket final std::coroutine_handle<> write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -69,11 +69,13 @@ class epoll_socket final } std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; endpoint local_endpoint() const noexcept override { diff --git a/include/boost/corosio/native/detail/epoll/epoll_socket_service.hpp b/include/boost/corosio/native/detail/epoll/epoll_socket_service.hpp index ccdb62cb..707c6447 100644 --- a/include/boost/corosio/native/detail/epoll/epoll_socket_service.hpp +++ b/include/boost/corosio/native/detail/epoll/epoll_socket_service.hpp @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -124,9 +124,11 @@ class BOOST_COROSIO_DECL epoll_socket_service final : public socket_service io_object::implementation* construct() override; void destroy(io_object::implementation*) override; void close(io_object::handle&) override; - std::error_code - open_socket(tcp_socket::implementation& impl, - int family, int type, int protocol) override; + std::error_code open_socket( + tcp_socket::implementation& impl, + int family, + int type, + int protocol) override; epoll_scheduler& scheduler() const noexcept { @@ -263,8 +265,8 @@ epoll_connect_op::operator()() sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd, reinterpret_cast(&local_storage), - &local_len) == 0) + fd, reinterpret_cast(&local_storage), &local_len) == + 0) local_ep = from_sockaddr(local_storage); static_cast(socket_impl_) ->set_endpoints(local_ep, target_endpoint); @@ -304,16 +306,15 @@ epoll_socket::connect( sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, detail::socket_family(fd_), storage); - int result = - ::connect(fd_, reinterpret_cast(&storage), addrlen); + int result = ::connect(fd_, reinterpret_cast(&storage), addrlen); if (result == 0) { sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd_, reinterpret_cast(&local_storage), - &local_len) == 0) + fd_, reinterpret_cast(&local_storage), &local_len) == + 0) local_endpoint_ = detail::from_sockaddr(local_storage); remote_endpoint_ = ep; } @@ -359,7 +360,7 @@ inline std::coroutine_handle<> epoll_socket::read_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -445,7 +446,7 @@ inline std::coroutine_handle<> epoll_socket::write_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -550,19 +551,17 @@ epoll_socket::shutdown(tcp_socket::shutdown_type what) noexcept inline std::error_code epoll_socket::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); return {}; } inline std::error_code epoll_socket::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -777,8 +776,7 @@ epoll_socket_service::destroy(io_object::implementation* impl) inline std::error_code epoll_socket_service::open_socket( - tcp_socket::implementation& impl, - int family, int type, int protocol) + tcp_socket::implementation& impl, int family, int type, int protocol) { auto* epoll_impl = static_cast(&impl); epoll_impl->close_socket(); diff --git a/include/boost/corosio/native/detail/iocp/win_acceptor.hpp b/include/boost/corosio/native/detail/iocp/win_acceptor.hpp index bb875d58..218e9d50 100644 --- a/include/boost/corosio/native/detail/iocp/win_acceptor.hpp +++ b/include/boost/corosio/native/detail/iocp/win_acceptor.hpp @@ -128,11 +128,13 @@ class win_acceptor final void cancel() noexcept override; std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; win_acceptor_internal* get_internal() const noexcept; }; diff --git a/include/boost/corosio/native/detail/iocp/win_acceptor_service.hpp b/include/boost/corosio/native/detail/iocp/win_acceptor_service.hpp index 8a9ded0a..f8d7ada0 100644 --- a/include/boost/corosio/native/detail/iocp/win_acceptor_service.hpp +++ b/include/boost/corosio/native/detail/iocp/win_acceptor_service.hpp @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -55,16 +55,15 @@ class BOOST_COROSIO_DECL win_acceptor_service final /** Create the acceptor socket without binding or listening. */ std::error_code open_acceptor_socket( - tcp_acceptor::implementation& impl, - int family, int type, int protocol); + tcp_acceptor::implementation& impl, int family, int type, int protocol); /** Bind an open acceptor to a local endpoint. */ - std::error_code bind_acceptor( - tcp_acceptor::implementation& impl, endpoint ep); + std::error_code + bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep); /** Start listening for incoming connections. */ - std::error_code listen_acceptor( - tcp_acceptor::implementation& impl, int backlog); + std::error_code + listen_acceptor(tcp_acceptor::implementation& impl, int backlog); void shutdown() override; @@ -212,13 +211,11 @@ accept_op::do_complete( endpoint local_ep, remote_ep; if (::getsockname( op->accepted_socket, - reinterpret_cast(&local_storage), - &local_len) == 0) + reinterpret_cast(&local_storage), &local_len) == 0) local_ep = from_sockaddr(local_storage); if (::getpeername( op->accepted_socket, - reinterpret_cast(&remote_storage), - &remote_len) == 0) + reinterpret_cast(&remote_storage), &remote_len) == 0) remote_ep = from_sockaddr(remote_storage); op->peer_wrapper->get_internal()->set_endpoints(local_ep, remote_ep); @@ -276,8 +273,8 @@ connect_op::do_complete( { // Required after ConnectEx to enable shutdown(), getsockname(), etc. ::setsockopt( - op->internal.native_handle(), SOL_SOCKET, - SO_UPDATE_CONNECT_CONTEXT, nullptr, 0); + op->internal.native_handle(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, + nullptr, 0); endpoint local_ep; sockaddr_storage local_storage{}; @@ -432,9 +429,8 @@ win_socket_internal::connect( bind_len = sizeof(sa4); } - if (::bind( - socket_, reinterpret_cast(&bind_storage), - bind_len) == SOCKET_ERROR) + if (::bind(socket_, reinterpret_cast(&bind_storage), bind_len) == + SOCKET_ERROR) { svc_.on_completion(&op, ::WSAGetLastError(), 0); return std::noop_coroutine(); @@ -472,7 +468,7 @@ inline std::coroutine_handle<> win_socket_internal::read_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -513,8 +509,7 @@ win_socket_internal::read_some( op.flags = 0; int result = ::WSARecv( - socket_, op.wsabufs, op.wsabuf_count, nullptr, &op.flags, &op, - nullptr); + socket_, op.wsabufs, op.wsabuf_count, nullptr, &op.flags, &op, nullptr); if (result == SOCKET_ERROR) { @@ -539,7 +534,7 @@ inline std::coroutine_handle<> win_socket_internal::write_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -660,7 +655,7 @@ inline std::coroutine_handle<> win_socket::read_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param buf, + buffer_param buf, std::stop_token token, std::error_code* ec, std::size_t* bytes) @@ -672,7 +667,7 @@ inline std::coroutine_handle<> win_socket::write_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param buf, + buffer_param buf, std::stop_token token, std::error_code* ec, std::size_t* bytes) @@ -711,23 +706,22 @@ win_socket::native_handle() const noexcept inline std::error_code win_socket::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(internal_->native_handle(), level, optname, - reinterpret_cast(data), - static_cast(size)) != 0) + if (::setsockopt( + internal_->native_handle(), level, optname, + reinterpret_cast(data), static_cast(size)) != 0) return make_err(WSAGetLastError()); return {}; } inline std::error_code win_socket::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { int len = static_cast(*size); - if (::getsockopt(internal_->native_handle(), level, optname, + if (::getsockopt( + internal_->native_handle(), level, optname, reinterpret_cast(data), &len) != 0) return make_err(WSAGetLastError()); *size = static_cast(len); @@ -861,13 +855,12 @@ win_sockets::unregister_impl(win_socket_internal& impl) inline std::error_code win_sockets::open_socket( - win_socket_internal& impl, - int family, int type, int protocol) + win_socket_internal& impl, int family, int type, int protocol) { impl.close_socket(); - SOCKET sock = ::WSASocketW( - family, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED); + SOCKET sock = + ::WSASocketW(family, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED); if (sock == INVALID_SOCKET) return make_err(::WSAGetLastError()); @@ -876,8 +869,8 @@ win_sockets::open_socket( { DWORD one = 1; ::setsockopt( - sock, IPPROTO_IPV6, IPV6_V6ONLY, - reinterpret_cast(&one), sizeof(one)); + sock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast(&one), + sizeof(one)); } HANDLE result = ::CreateIoCompletionPort( @@ -891,7 +884,7 @@ win_sockets::open_socket( } impl.socket_ = sock; - impl.family_ = family; + impl.family_ = family; return {}; } @@ -988,13 +981,12 @@ win_sockets::unregister_acceptor_impl(win_acceptor_internal& impl) inline std::error_code win_sockets::open_acceptor_socket( - win_acceptor_internal& impl, - int family, int type, int protocol) + win_acceptor_internal& impl, int family, int type, int protocol) { impl.close_socket(); - SOCKET sock = ::WSASocketW( - family, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED); + SOCKET sock = + ::WSASocketW(family, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED); if (sock == INVALID_SOCKET) return make_err(::WSAGetLastError()); @@ -1003,8 +995,8 @@ win_sockets::open_acceptor_socket( { DWORD val = 0; // dual-stack default ::setsockopt( - sock, IPPROTO_IPV6, IPV6_V6ONLY, - reinterpret_cast(&val), sizeof(val)); + sock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast(&val), + sizeof(val)); } HANDLE result = ::CreateIoCompletionPort( @@ -1022,8 +1014,7 @@ win_sockets::open_acceptor_socket( } inline std::error_code -win_sockets::bind_acceptor( - win_acceptor_internal& impl, endpoint ep) +win_sockets::bind_acceptor(win_acceptor_internal& impl, endpoint ep) { SOCKET sock = impl.socket_; @@ -1038,16 +1029,14 @@ win_sockets::bind_acceptor( sockaddr_storage local_storage{}; int local_len = sizeof(local_storage); if (::getsockname( - sock, reinterpret_cast(&local_storage), - &local_len) == 0) + sock, reinterpret_cast(&local_storage), &local_len) == 0) impl.set_local_endpoint(detail::from_sockaddr(local_storage)); return {}; } inline std::error_code -win_sockets::listen_acceptor( - win_acceptor_internal& impl, int backlog) +win_sockets::listen_acceptor(win_acceptor_internal& impl, int backlog) { SOCKET sock = impl.socket_; @@ -1166,14 +1155,13 @@ win_acceptor_internal::accept( } // AcceptEx address buffer sizes must match the socket's address family - DWORD addr_size = - static_cast( - (af == AF_INET6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)) + 16); + DWORD addr_size = static_cast( + (af == AF_INET6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)) + 16); DWORD bytes_received = 0; BOOL ok = accept_ex( - socket_, accepted, op.addr_buf, 0, addr_size, - addr_size, &bytes_received, &op); + socket_, accepted, op.addr_buf, 0, addr_size, addr_size, + &bytes_received, &op); if (!ok) { @@ -1267,23 +1255,22 @@ win_acceptor::cancel() noexcept inline std::error_code win_acceptor::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(internal_->native_handle(), level, optname, - reinterpret_cast(data), - static_cast(size)) != 0) + if (::setsockopt( + internal_->native_handle(), level, optname, + reinterpret_cast(data), static_cast(size)) != 0) return make_err(WSAGetLastError()); return {}; } inline std::error_code win_acceptor::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { int len = static_cast(*size); - if (::getsockopt(internal_->native_handle(), level, optname, + if (::getsockopt( + internal_->native_handle(), level, optname, reinterpret_cast(data), &len) != 0) return make_err(WSAGetLastError()); *size = static_cast(len); @@ -1345,8 +1332,7 @@ win_acceptor_service::close(io_object::handle& h) inline std::error_code win_acceptor_service::open_acceptor_socket( - tcp_acceptor::implementation& impl, - int family, int type, int protocol) + tcp_acceptor::implementation& impl, int family, int type, int protocol) { auto& wrapper = static_cast(impl); return svc_.open_acceptor_socket( diff --git a/include/boost/corosio/native/detail/iocp/win_overlapped_op.hpp b/include/boost/corosio/native/detail/iocp/win_overlapped_op.hpp index fe9c39df..8fd3eafd 100644 --- a/include/boost/corosio/native/detail/iocp/win_overlapped_op.hpp +++ b/include/boost/corosio/native/detail/iocp/win_overlapped_op.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -60,7 +60,7 @@ struct overlapped_op /** Function pointer type for cancellation hook. */ using cancel_func_type = void (*)(overlapped_op*) noexcept; - long ready_ = 0; + long ready_ = 0; std::coroutine_handle<> h; capy::executor_ref ex; std::error_code* ec_out = nullptr; diff --git a/include/boost/corosio/native/detail/iocp/win_resolver.hpp b/include/boost/corosio/native/detail/iocp/win_resolver.hpp index 80c6896e..a178bb34 100644 --- a/include/boost/corosio/native/detail/iocp/win_resolver.hpp +++ b/include/boost/corosio/native/detail/iocp/win_resolver.hpp @@ -35,8 +35,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/include/boost/corosio/native/detail/iocp/win_scheduler.hpp b/include/boost/corosio/native/detail/iocp/win_scheduler.hpp index 3849211e..9f8c9258 100644 --- a/include/boost/corosio/native/detail/iocp/win_scheduler.hpp +++ b/include/boost/corosio/native/detail/iocp/win_scheduler.hpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -226,15 +226,13 @@ win_scheduler::shutdown() ULONG_PTR key; LPOVERLAPPED overlapped; ::GetQueuedCompletionStatus( - iocp_, &bytes, &key, &overlapped, - iocp::max_gqcs_timeout); + iocp_, &bytes, &key, &overlapped, iocp::max_gqcs_timeout); if (overlapped) { ::InterlockedDecrement(&outstanding_work_); if (key == key_posted) { - auto* op = - reinterpret_cast(overlapped); + auto* op = reinterpret_cast(overlapped); op->destroy(); } else @@ -364,8 +362,7 @@ win_scheduler::on_pending(overlapped_op* op) const } inline void -win_scheduler::on_completion( - overlapped_op* op, DWORD error, DWORD bytes) const +win_scheduler::on_completion(overlapped_op* op, DWORD error, DWORD bytes) const { // Sync completion: pack results into op and post for dispatch. op->ready_ = 1; @@ -579,8 +576,7 @@ win_scheduler::do_one(unsigned long timeout_ms) // (on_pending/on_completion set it) — safe to dispatch. // If old value was 0, the initiator hasn't returned yet — // skip dispatch; on_pending() will re-post. - if (::InterlockedCompareExchange( - &ov_op->ready_, 1, 0) == 1) + if (::InterlockedCompareExchange(&ov_op->ready_, 1, 0) == 1) { ov_op->complete(this, bytes, err); work_finished(); diff --git a/include/boost/corosio/native/detail/iocp/win_socket.hpp b/include/boost/corosio/native/detail/iocp/win_socket.hpp index a0156d69..92403d26 100644 --- a/include/boost/corosio/native/detail/iocp/win_socket.hpp +++ b/include/boost/corosio/native/detail/iocp/win_socket.hpp @@ -127,7 +127,7 @@ class win_socket_internal std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*); @@ -135,7 +135,7 @@ class win_socket_internal std::coroutine_handle<> write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*); @@ -182,7 +182,7 @@ class win_socket final std::coroutine_handle<> read_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param buf, + buffer_param buf, std::stop_token token, std::error_code* ec, std::size_t* bytes) override; @@ -190,7 +190,7 @@ class win_socket final std::coroutine_handle<> write_some( std::coroutine_handle<> h, capy::executor_ref d, - io_buffer_param buf, + buffer_param buf, std::stop_token token, std::error_code* ec, std::size_t* bytes) override; @@ -200,11 +200,13 @@ class win_socket final native_handle_type native_handle() const noexcept override; std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; endpoint local_endpoint() const noexcept override; endpoint remote_endpoint() const noexcept override; diff --git a/include/boost/corosio/native/detail/iocp/win_sockets.hpp b/include/boost/corosio/native/detail/iocp/win_sockets.hpp index 8c449f06..4d31b83a 100644 --- a/include/boost/corosio/native/detail/iocp/win_sockets.hpp +++ b/include/boost/corosio/native/detail/iocp/win_sockets.hpp @@ -95,9 +95,8 @@ class BOOST_COROSIO_DECL win_sockets final @param impl The socket implementation internal to initialize. @return Error code, or success. */ - std::error_code open_socket( - win_socket_internal& impl, - int family, int type, int protocol); + std::error_code + open_socket(win_socket_internal& impl, int family, int type, int protocol); /** Destroy an acceptor implementation wrapper. Removes from tracking list and deletes. @@ -122,8 +121,7 @@ class BOOST_COROSIO_DECL win_sockets final @return Error code, or success. */ std::error_code open_acceptor_socket( - win_acceptor_internal& impl, - int family, int type, int protocol); + win_acceptor_internal& impl, int family, int type, int protocol); /** Bind an open acceptor to a local endpoint. @@ -131,8 +129,7 @@ class BOOST_COROSIO_DECL win_sockets final @param ep The local endpoint to bind to. @return Error code, or success. */ - std::error_code bind_acceptor( - win_acceptor_internal& impl, endpoint ep); + std::error_code bind_acceptor(win_acceptor_internal& impl, endpoint ep); /** Start listening for incoming connections. @@ -140,8 +137,7 @@ class BOOST_COROSIO_DECL win_sockets final @param backlog The listen backlog. @return Error code, or success. */ - std::error_code listen_acceptor( - win_acceptor_internal& impl, int backlog); + std::error_code listen_acceptor(win_acceptor_internal& impl, int backlog); /** Return the IOCP handle. */ void* native_handle() const noexcept; diff --git a/include/boost/corosio/native/detail/iocp/win_wsa_init.hpp b/include/boost/corosio/native/detail/iocp/win_wsa_init.hpp index f2b79525..25f3c2fe 100644 --- a/include/boost/corosio/native/detail/iocp/win_wsa_init.hpp +++ b/include/boost/corosio/native/detail/iocp/win_wsa_init.hpp @@ -16,7 +16,7 @@ #if BOOST_COROSIO_HAS_IOCP #include -#include +#include #include #include diff --git a/include/boost/corosio/native/detail/kqueue/kqueue_acceptor.hpp b/include/boost/corosio/native/detail/kqueue/kqueue_acceptor.hpp index 888b63ed..34ed997c 100644 --- a/include/boost/corosio/native/detail/kqueue/kqueue_acceptor.hpp +++ b/include/boost/corosio/native/detail/kqueue/kqueue_acceptor.hpp @@ -82,11 +82,13 @@ class kqueue_acceptor final void cancel() noexcept override; std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; /** Cancel a specific pending operation. diff --git a/include/boost/corosio/native/detail/kqueue/kqueue_acceptor_service.hpp b/include/boost/corosio/native/detail/kqueue/kqueue_acceptor_service.hpp index 4340e45a..8fee98a6 100644 --- a/include/boost/corosio/native/detail/kqueue/kqueue_acceptor_service.hpp +++ b/include/boost/corosio/native/detail/kqueue/kqueue_acceptor_service.hpp @@ -23,9 +23,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -79,11 +79,13 @@ class BOOST_COROSIO_DECL kqueue_acceptor_service final : public acceptor_service void close(io_object::handle&) override; std::error_code open_acceptor_socket( tcp_acceptor::implementation& impl, - int family, int type, int protocol) override; - std::error_code bind_acceptor( - tcp_acceptor::implementation& impl, endpoint ep) override; - std::error_code listen_acceptor( - tcp_acceptor::implementation& impl, int backlog) override; + int family, + int type, + int protocol) override; + std::error_code + bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) override; + std::error_code + listen_acceptor(tcp_acceptor::implementation& impl, int backlog) override; kqueue_scheduler& scheduler() const noexcept { @@ -306,21 +308,25 @@ kqueue_acceptor::accept( auto* socket_svc = svc_.socket_service(); if (socket_svc) { - auto& impl = static_cast(*socket_svc->construct()); + auto& impl = + static_cast(*socket_svc->construct()); impl.set_socket(accepted); impl.desc_state_.fd = accepted; { std::lock_guard lock(impl.desc_state_.mutex); - impl.desc_state_.read_op = nullptr; - impl.desc_state_.write_op = nullptr; + impl.desc_state_.read_op = nullptr; + impl.desc_state_.write_op = nullptr; impl.desc_state_.connect_op = nullptr; } - socket_svc->scheduler().register_descriptor(accepted, &impl.desc_state_); + socket_svc->scheduler().register_descriptor( + accepted, &impl.desc_state_); // Suppress SIGPIPE on the accepted socket; macOS lacks MSG_NOSIGNAL int one = 1; - if (::setsockopt(accepted, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one)) == -1) + if (::setsockopt( + accepted, SOL_SOCKET, SO_NOSIGPIPE, &one, + sizeof(one)) == -1) { int saved_errno = errno; socket_svc->destroy(&impl); @@ -339,8 +345,7 @@ kqueue_acceptor::accept( reinterpret_cast(&local_storage), &local_len) == 0) local_ep = from_sockaddr(local_storage); - impl.set_endpoints( - local_ep, from_sockaddr(peer_storage)); + impl.set_endpoints(local_ep, from_sockaddr(peer_storage)); if (ec) *ec = {}; if (impl_out) @@ -568,19 +573,17 @@ kqueue_acceptor_service::close(io_object::handle& h) inline std::error_code kqueue_acceptor::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); return {}; } inline std::error_code kqueue_acceptor::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -591,8 +594,7 @@ kqueue_acceptor::get_option( inline std::error_code kqueue_acceptor_service::open_acceptor_socket( - tcp_acceptor::implementation& impl, - int family, int type, int protocol) + tcp_acceptor::implementation& impl, int family, int type, int protocol) { auto* kq_impl = static_cast(&impl); kq_impl->close_socket(); @@ -651,7 +653,7 @@ kqueue_acceptor_service::bind_acceptor( tcp_acceptor::implementation& impl, endpoint ep) { auto* kq_impl = static_cast(&impl); - int fd = kq_impl->fd_; + int fd = kq_impl->fd_; sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, storage); @@ -672,7 +674,7 @@ kqueue_acceptor_service::listen_acceptor( tcp_acceptor::implementation& impl, int backlog) { auto* kq_impl = static_cast(&impl); - int fd = kq_impl->fd_; + int fd = kq_impl->fd_; if (::listen(fd, backlog) < 0) return make_err(errno); diff --git a/include/boost/corosio/native/detail/kqueue/kqueue_scheduler.hpp b/include/boost/corosio/native/detail/kqueue/kqueue_scheduler.hpp index 3408b4dd..4da95cc8 100644 --- a/include/boost/corosio/native/detail/kqueue/kqueue_scheduler.hpp +++ b/include/boost/corosio/native/detail/kqueue/kqueue_scheduler.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -492,7 +492,7 @@ kqueue_scheduler::reset_inline_budget() const noexcept if (ctx->unassisted) { ctx->inline_budget_max = 4; - ctx->inline_budget = 4; + ctx->inline_budget = 4; return; } // Ramp up when previous cycle fully consumed budget. diff --git a/include/boost/corosio/native/detail/kqueue/kqueue_socket.hpp b/include/boost/corosio/native/detail/kqueue/kqueue_socket.hpp index 3bf27b32..02655765 100644 --- a/include/boost/corosio/native/detail/kqueue/kqueue_socket.hpp +++ b/include/boost/corosio/native/detail/kqueue/kqueue_socket.hpp @@ -49,7 +49,7 @@ class kqueue_socket final std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -57,7 +57,7 @@ class kqueue_socket final std::coroutine_handle<> write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -71,11 +71,13 @@ class kqueue_socket final // Socket options std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; endpoint local_endpoint() const noexcept override { @@ -120,7 +122,7 @@ class kqueue_socket final private: kqueue_socket_service& svc_; - int fd_ = -1; + int fd_ = -1; bool user_set_linger_ = false; endpoint local_endpoint_; endpoint remote_endpoint_; diff --git a/include/boost/corosio/native/detail/kqueue/kqueue_socket_service.hpp b/include/boost/corosio/native/detail/kqueue/kqueue_socket_service.hpp index fcbf9ef8..2a74aebf 100644 --- a/include/boost/corosio/native/detail/kqueue/kqueue_socket_service.hpp +++ b/include/boost/corosio/native/detail/kqueue/kqueue_socket_service.hpp @@ -22,9 +22,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -154,9 +154,11 @@ class BOOST_COROSIO_DECL kqueue_socket_service final : public socket_service io_object::implementation* construct() override; void destroy(io_object::implementation*) override; void close(io_object::handle&) override; - std::error_code - open_socket(tcp_socket::implementation& impl, - int family, int type, int protocol) override; + std::error_code open_socket( + tcp_socket::implementation& impl, + int family, + int type, + int protocol) override; kqueue_scheduler& scheduler() const noexcept { @@ -254,8 +256,8 @@ kqueue_connect_op::operator()() sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd, reinterpret_cast(&local_storage), - &local_len) == 0) + fd, reinterpret_cast(&local_storage), &local_len) == + 0) local_ep = from_sockaddr(local_storage); static_cast(socket_impl_) ->set_endpoints(local_ep, target_endpoint); @@ -301,8 +303,7 @@ kqueue_socket::connect( sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, detail::socket_family(fd_), storage); - int result = - ::connect(fd_, reinterpret_cast(&storage), addrlen); + int result = ::connect(fd_, reinterpret_cast(&storage), addrlen); // Cache endpoints on sync success if (result == 0) @@ -310,8 +311,8 @@ kqueue_socket::connect( sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd_, reinterpret_cast(&local_storage), - &local_len) == 0) + fd_, reinterpret_cast(&local_storage), &local_len) == + 0) local_endpoint_ = detail::from_sockaddr(local_storage); remote_endpoint_ = ep; } @@ -399,7 +400,7 @@ inline std::coroutine_handle<> kqueue_socket::read_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -491,7 +492,7 @@ inline std::coroutine_handle<> kqueue_socket::write_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -597,11 +598,10 @@ kqueue_socket::shutdown(tcp_socket::shutdown_type what) noexcept inline std::error_code kqueue_socket::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); if (level == SOL_SOCKET && optname == SO_LINGER && size >= sizeof(struct ::linger)) @@ -612,8 +612,7 @@ kqueue_socket::set_option( inline std::error_code kqueue_socket::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -849,8 +848,7 @@ kqueue_socket_service::destroy(io_object::implementation* impl) inline std::error_code kqueue_socket_service::open_socket( - tcp_socket::implementation& impl, - int family, int type, int protocol) + tcp_socket::implementation& impl, int family, int type, int protocol) { auto* kq_impl = static_cast(&impl); kq_impl->close_socket(); @@ -862,8 +860,7 @@ kqueue_socket_service::open_socket( if (family == AF_INET6) { int v6only = 1; - ::setsockopt( - fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)); + ::setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)); } // Set non-blocking diff --git a/include/boost/corosio/detail/make_err.hpp b/include/boost/corosio/native/detail/make_err.hpp similarity index 95% rename from include/boost/corosio/detail/make_err.hpp rename to include/boost/corosio/native/detail/make_err.hpp index 7b0e1c47..db994c15 100644 --- a/include/boost/corosio/detail/make_err.hpp +++ b/include/boost/corosio/native/detail/make_err.hpp @@ -8,8 +8,8 @@ // Official repository: https://github.com/cppalliance/corosio // -#ifndef BOOST_COROSIO_DETAIL_MAKE_ERR_HPP -#define BOOST_COROSIO_DETAIL_MAKE_ERR_HPP +#ifndef BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP +#define BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP #include #include diff --git a/include/boost/corosio/native/detail/posix/posix_resolver.hpp b/include/boost/corosio/native/detail/posix/posix_resolver.hpp index 4937c3d8..5f5f4a83 100644 --- a/include/boost/corosio/native/detail/posix/posix_resolver.hpp +++ b/include/boost/corosio/native/detail/posix/posix_resolver.hpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -221,7 +221,7 @@ class posix_resolver final void operator()() override; void destroy() override; void request_cancel() noexcept; - void start(std::stop_token token); + void start(std::stop_token const& token); }; // reverse_resolve_op - operation state for reverse DNS resolution @@ -265,7 +265,7 @@ class posix_resolver final void operator()() override; void destroy() override; void request_cancel() noexcept; - void start(std::stop_token token); + void start(std::stop_token const& token); }; explicit posix_resolver(posix_resolver_service& svc) noexcept; diff --git a/include/boost/corosio/native/detail/posix/posix_resolver_service.hpp b/include/boost/corosio/native/detail/posix/posix_resolver_service.hpp index dba4af14..568d5dfd 100644 --- a/include/boost/corosio/native/detail/posix/posix_resolver_service.hpp +++ b/include/boost/corosio/native/detail/posix/posix_resolver_service.hpp @@ -277,8 +277,7 @@ posix_resolver::resolve_op::request_cancel() noexcept } inline void -// NOLINTNEXTLINE(performance-unnecessary-value-param) -posix_resolver::resolve_op::start(std::stop_token token) +posix_resolver::resolve_op::start(std::stop_token const& token) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); @@ -343,8 +342,7 @@ posix_resolver::reverse_resolve_op::request_cancel() noexcept } inline void -// NOLINTNEXTLINE(performance-unnecessary-value-param) -posix_resolver::reverse_resolve_op::start(std::stop_token token) +posix_resolver::reverse_resolve_op::start(std::stop_token const& token) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); diff --git a/include/boost/corosio/native/detail/select/select_acceptor.hpp b/include/boost/corosio/native/detail/select/select_acceptor.hpp index 504a2af3..c4f74043 100644 --- a/include/boost/corosio/native/detail/select/select_acceptor.hpp +++ b/include/boost/corosio/native/detail/select/select_acceptor.hpp @@ -60,11 +60,13 @@ class select_acceptor final void cancel() noexcept override; std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; void cancel_single_op(select_op& op) noexcept; void close_socket() noexcept; void set_local_endpoint(endpoint ep) noexcept diff --git a/include/boost/corosio/native/detail/select/select_acceptor_service.hpp b/include/boost/corosio/native/detail/select/select_acceptor_service.hpp index a7b573a9..4de3c87e 100644 --- a/include/boost/corosio/native/detail/select/select_acceptor_service.hpp +++ b/include/boost/corosio/native/detail/select/select_acceptor_service.hpp @@ -22,9 +22,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -75,11 +75,13 @@ class BOOST_COROSIO_DECL select_acceptor_service final : public acceptor_service void close(io_object::handle&) override; std::error_code open_acceptor_socket( tcp_acceptor::implementation& impl, - int family, int type, int protocol) override; - std::error_code bind_acceptor( - tcp_acceptor::implementation& impl, endpoint ep) override; - std::error_code listen_acceptor( - tcp_acceptor::implementation& impl, int backlog) override; + int family, + int type, + int protocol) override; + std::error_code + bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) override; + std::error_code + listen_acceptor(tcp_acceptor::implementation& impl, int backlog) override; select_scheduler& scheduler() const noexcept { @@ -463,19 +465,17 @@ select_acceptor_service::close(io_object::handle& h) inline std::error_code select_acceptor::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); return {}; } inline std::error_code select_acceptor::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -486,8 +486,7 @@ select_acceptor::get_option( inline std::error_code select_acceptor_service::open_acceptor_socket( - tcp_acceptor::implementation& impl, - int family, int type, int protocol) + tcp_acceptor::implementation& impl, int family, int type, int protocol) { auto* select_impl = static_cast(&impl); select_impl->close_socket(); @@ -538,7 +537,7 @@ select_acceptor_service::bind_acceptor( tcp_acceptor::implementation& impl, endpoint ep) { auto* select_impl = static_cast(&impl); - int fd = select_impl->fd_; + int fd = select_impl->fd_; sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, storage); @@ -559,7 +558,7 @@ select_acceptor_service::listen_acceptor( tcp_acceptor::implementation& impl, int backlog) { auto* select_impl = static_cast(&impl); - int fd = select_impl->fd_; + int fd = select_impl->fd_; if (::listen(fd, backlog) < 0) return make_err(errno); diff --git a/include/boost/corosio/native/detail/select/select_op.hpp b/include/boost/corosio/native/detail/select/select_op.hpp index a9bae60b..b9e9912f 100644 --- a/include/boost/corosio/native/detail/select/select_op.hpp +++ b/include/boost/corosio/native/detail/select/select_op.hpp @@ -22,10 +22,10 @@ #include #include -#include +#include #include #include -#include +#include #include #include @@ -194,8 +194,7 @@ struct select_op : scheduler_op cancelled.store(true, std::memory_order_release); } - // NOLINTNEXTLINE(performance-unnecessary-value-param) - void start(std::stop_token token) + void start(std::stop_token const& token) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); @@ -206,8 +205,7 @@ struct select_op : scheduler_op stop_cb.emplace(token, canceller{this}); } - // NOLINTNEXTLINE(performance-unnecessary-value-param) - void start(std::stop_token token, select_socket* impl) + void start(std::stop_token const& token, select_socket* impl) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); @@ -218,8 +216,7 @@ struct select_op : scheduler_op stop_cb.emplace(token, canceller{this}); } - // NOLINTNEXTLINE(performance-unnecessary-value-param) - void start(std::stop_token token, select_acceptor* impl) + void start(std::stop_token const& token, select_acceptor* impl) { cancelled.store(false, std::memory_order_release); stop_cb.reset(); diff --git a/include/boost/corosio/native/detail/select/select_scheduler.hpp b/include/boost/corosio/native/detail/select/select_scheduler.hpp index 823c7bfc..14e2ef7d 100644 --- a/include/boost/corosio/native/detail/select/select_scheduler.hpp +++ b/include/boost/corosio/native/detail/select/select_scheduler.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/include/boost/corosio/native/detail/select/select_socket.hpp b/include/boost/corosio/native/detail/select/select_socket.hpp index ee940bb5..ff0c295e 100644 --- a/include/boost/corosio/native/detail/select/select_socket.hpp +++ b/include/boost/corosio/native/detail/select/select_socket.hpp @@ -47,7 +47,7 @@ class select_socket final std::coroutine_handle<> read_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -55,7 +55,7 @@ class select_socket final std::coroutine_handle<> write_some( std::coroutine_handle<>, capy::executor_ref, - io_buffer_param, + buffer_param, std::stop_token, std::error_code*, std::size_t*) override; @@ -68,11 +68,13 @@ class select_socket final } std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept override; - std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept override; + int level, + int optname, + void const* data, + std::size_t size) noexcept override; + std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept override; endpoint local_endpoint() const noexcept override { diff --git a/include/boost/corosio/native/detail/select/select_socket_service.hpp b/include/boost/corosio/native/detail/select/select_socket_service.hpp index 6fa801f0..0a752e30 100644 --- a/include/boost/corosio/native/detail/select/select_socket_service.hpp +++ b/include/boost/corosio/native/detail/select/select_socket_service.hpp @@ -21,9 +21,9 @@ #include #include -#include +#include #include -#include +#include #include @@ -115,9 +115,11 @@ class BOOST_COROSIO_DECL select_socket_service final : public socket_service io_object::implementation* construct() override; void destroy(io_object::implementation*) override; void close(io_object::handle&) override; - std::error_code - open_socket(tcp_socket::implementation& impl, - int family, int type, int protocol) override; + std::error_code open_socket( + tcp_socket::implementation& impl, + int family, + int type, + int protocol) override; select_scheduler& scheduler() const noexcept { @@ -181,8 +183,8 @@ select_connect_op::operator()() sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd, reinterpret_cast(&local_storage), - &local_len) == 0) + fd, reinterpret_cast(&local_storage), &local_len) == + 0) local_ep = from_sockaddr(local_storage); static_cast(socket_impl_) ->set_endpoints(local_ep, target_endpoint); @@ -233,8 +235,7 @@ select_socket::connect( sockaddr_storage storage{}; socklen_t addrlen = detail::to_sockaddr(ep, detail::socket_family(fd_), storage); - int result = - ::connect(fd_, reinterpret_cast(&storage), addrlen); + int result = ::connect(fd_, reinterpret_cast(&storage), addrlen); if (result == 0) { @@ -242,8 +243,8 @@ select_socket::connect( sockaddr_storage local_storage{}; socklen_t local_len = sizeof(local_storage); if (::getsockname( - fd_, reinterpret_cast(&local_storage), - &local_len) == 0) + fd_, reinterpret_cast(&local_storage), &local_len) == + 0) local_endpoint_ = detail::from_sockaddr(local_storage); remote_endpoint_ = ep; @@ -310,7 +311,7 @@ inline std::coroutine_handle<> select_socket::read_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -413,7 +414,7 @@ inline std::coroutine_handle<> select_socket::write_some( std::coroutine_handle<> h, capy::executor_ref ex, - io_buffer_param param, + buffer_param param, std::stop_token token, std::error_code* ec, std::size_t* bytes_out) @@ -532,19 +533,17 @@ select_socket::shutdown(tcp_socket::shutdown_type what) noexcept inline std::error_code select_socket::set_option( - int level, int optname, - void const* data, std::size_t size) noexcept + int level, int optname, void const* data, std::size_t size) noexcept { - if (::setsockopt(fd_, level, optname, data, - static_cast(size)) != 0) + if (::setsockopt(fd_, level, optname, data, static_cast(size)) != + 0) return make_err(errno); return {}; } inline std::error_code select_socket::get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept + int level, int optname, void* data, std::size_t* size) const noexcept { socklen_t len = static_cast(*size); if (::getsockopt(fd_, level, optname, data, &len) != 0) @@ -695,8 +694,7 @@ select_socket_service::destroy(io_object::implementation* impl) inline std::error_code select_socket_service::open_socket( - tcp_socket::implementation& impl, - int family, int type, int protocol) + tcp_socket::implementation& impl, int family, int type, int protocol) { auto* select_impl = static_cast(&impl); select_impl->close_socket(); diff --git a/include/boost/corosio/native/native_cancel.hpp b/include/boost/corosio/native/native_cancel.hpp index efacc8a3..a652065c 100644 --- a/include/boost/corosio/native/native_cancel.hpp +++ b/include/boost/corosio/native/native_cancel.hpp @@ -67,7 +67,8 @@ namespace boost::corosio { @see cancel_after, native_timer */ template -auto cancel_at( +auto +cancel_at( capy::IoAwaitable auto&& op, native_timer& t, timer::time_point deadline) @@ -118,14 +119,14 @@ auto cancel_at( @see cancel_at, native_timer */ template -auto cancel_after( +auto +cancel_after( capy::IoAwaitable auto&& op, native_timer& t, timer::duration timeout) { return cancel_at( - std::forward(op), t, - timer::clock_type::now() + timeout); + std::forward(op), t, timer::clock_type::now() + timeout); } /** Cancel an operation if it does not complete by a deadline. @@ -167,9 +168,8 @@ auto cancel_after( @see cancel_after, native_timer */ template -auto cancel_at( - capy::IoAwaitable auto&& op, - timer::time_point deadline) +auto +cancel_at(capy::IoAwaitable auto&& op, timer::time_point deadline) { return detail::cancel_at_awaitable< std::decay_t, native_timer, true>( @@ -213,13 +213,11 @@ auto cancel_at( @see cancel_at, native_timer */ template -auto cancel_after( - capy::IoAwaitable auto&& op, - timer::duration timeout) +auto +cancel_after(capy::IoAwaitable auto&& op, timer::duration timeout) { return cancel_at( - std::forward(op), - timer::clock_type::now() + timeout); + std::forward(op), timer::clock_type::now() + timeout); } } // namespace boost::corosio diff --git a/include/boost/corosio/native/native_socket_option.hpp b/include/boost/corosio/native/native_socket_option.hpp index 9b542b13..757a1957 100644 --- a/include/boost/corosio/native/native_socket_option.hpp +++ b/include/boost/corosio/native/native_socket_option.hpp @@ -76,38 +76,62 @@ class boolean @param v `true` to enable the option, `false` to disable. */ - explicit boolean( bool v ) noexcept : value_( v ? 1 : 0 ) {} + explicit boolean(bool v) noexcept : value_(v ? 1 : 0) {} /// Assign a new value. - boolean& operator=( bool v ) noexcept + boolean& operator=(bool v) noexcept { value_ = v ? 1 : 0; return *this; } /// Return the option value. - bool value() const noexcept { return value_ != 0; } + bool value() const noexcept + { + return value_ != 0; + } /// Return the option value. - explicit operator bool() const noexcept { return value_ != 0; } + explicit operator bool() const noexcept + { + return value_ != 0; + } /// Return the negated option value. - bool operator!() const noexcept { return value_ == 0; } + bool operator!() const noexcept + { + return value_ == 0; + } /// Return the protocol level for `setsockopt`/`getsockopt`. - static constexpr int level() noexcept { return Level; } + static constexpr int level() noexcept + { + return Level; + } /// Return the option name for `setsockopt`/`getsockopt`. - static constexpr int name() noexcept { return Name; } + static constexpr int name() noexcept + { + return Name; + } /// Return a pointer to the underlying storage. - void* data() noexcept { return &value_; } + void* data() noexcept + { + return &value_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return &value_; } + void const* data() const noexcept + { + return &value_; + } /// Return the size of the underlying storage. - std::size_t size() const noexcept { return sizeof( value_ ); } + std::size_t size() const noexcept + { + return sizeof(value_); + } /** Normalize after `getsockopt` returns fewer bytes than expected. @@ -115,10 +139,10 @@ class boolean @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t s ) noexcept + void resize(std::size_t s) noexcept { - if ( s == sizeof( char ) ) - value_ = *reinterpret_cast( &value_ ) ? 1 : 0; + if (s == sizeof(char)) + value_ = *reinterpret_cast(&value_) ? 1 : 0; } }; @@ -155,42 +179,60 @@ class integer @param v The option value. */ - explicit integer( int v ) noexcept : value_( v ) {} + explicit integer(int v) noexcept : value_(v) {} /// Assign a new value. - integer& operator=( int v ) noexcept + integer& operator=(int v) noexcept { value_ = v; return *this; } /// Return the option value. - int value() const noexcept { return value_; } + int value() const noexcept + { + return value_; + } /// Return the protocol level for `setsockopt`/`getsockopt`. - static constexpr int level() noexcept { return Level; } + static constexpr int level() noexcept + { + return Level; + } /// Return the option name for `setsockopt`/`getsockopt`. - static constexpr int name() noexcept { return Name; } + static constexpr int name() noexcept + { + return Name; + } /// Return a pointer to the underlying storage. - void* data() noexcept { return &value_; } + void* data() noexcept + { + return &value_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return &value_; } + void const* data() const noexcept + { + return &value_; + } /// Return the size of the underlying storage. - std::size_t size() const noexcept { return sizeof( value_ ); } + std::size_t size() const noexcept + { + return sizeof(value_); + } /** Normalize after `getsockopt` returns fewer bytes than expected. @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t s ) noexcept + void resize(std::size_t s) noexcept { - if ( s == sizeof( char ) ) - value_ = static_cast( - *reinterpret_cast( &value_ ) ); + if (s == sizeof(char)) + value_ = + static_cast(*reinterpret_cast(&value_)); } }; @@ -225,46 +267,65 @@ class linger @param enabled `true` to enable linger behavior on close. @param timeout The linger timeout in seconds. */ - linger( bool enabled, int timeout ) noexcept + linger(bool enabled, int timeout) noexcept { - value_.l_onoff = enabled ? 1 : 0; - value_.l_linger = - static_cast( timeout ); + value_.l_onoff = enabled ? 1 : 0; + value_.l_linger = static_cast(timeout); } /// Return whether linger is enabled. - bool enabled() const noexcept { return value_.l_onoff != 0; } + bool enabled() const noexcept + { + return value_.l_onoff != 0; + } /// Set whether linger is enabled. - void enabled( bool v ) noexcept { value_.l_onoff = v ? 1 : 0; } + void enabled(bool v) noexcept + { + value_.l_onoff = v ? 1 : 0; + } /// Return the linger timeout in seconds. int timeout() const noexcept { - return static_cast( value_.l_linger ); + return static_cast(value_.l_linger); } /// Set the linger timeout in seconds. - void timeout( int v ) noexcept + void timeout(int v) noexcept { - value_.l_linger = - static_cast( v ); + value_.l_linger = static_cast(v); } /// Return the protocol level for `setsockopt`/`getsockopt`. - static constexpr int level() noexcept { return SOL_SOCKET; } + static constexpr int level() noexcept + { + return SOL_SOCKET; + } /// Return the option name for `setsockopt`/`getsockopt`. - static constexpr int name() noexcept { return SO_LINGER; } + static constexpr int name() noexcept + { + return SO_LINGER; + } /// Return a pointer to the underlying storage. - void* data() noexcept { return &value_; } + void* data() noexcept + { + return &value_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return &value_; } + void const* data() const noexcept + { + return &value_; + } /// Return the size of the underlying storage. - std::size_t size() const noexcept { return sizeof( value_ ); } + std::size_t size() const noexcept + { + return sizeof(value_); + } /** Normalize after `getsockopt`. @@ -272,7 +333,7 @@ class linger @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t ) noexcept {} + void resize(std::size_t) noexcept {} }; /// Disable Nagle's algorithm (TCP_NODELAY). diff --git a/include/boost/corosio/native/native_tcp.hpp b/include/boost/corosio/native/native_tcp.hpp index 9e63b8b5..cba44de6 100644 --- a/include/boost/corosio/native/native_tcp.hpp +++ b/include/boost/corosio/native/native_tcp.hpp @@ -55,17 +55,26 @@ namespace boost::corosio { class native_tcp { bool v6_; - explicit constexpr native_tcp( bool v6 ) noexcept : v6_( v6 ) {} + explicit constexpr native_tcp(bool v6) noexcept : v6_(v6) {} public: /// Construct an IPv4 TCP protocol. - static constexpr native_tcp v4() noexcept { return native_tcp( false ); } + static constexpr native_tcp v4() noexcept + { + return native_tcp(false); + } /// Construct an IPv6 TCP protocol. - static constexpr native_tcp v6() noexcept { return native_tcp( true ); } + static constexpr native_tcp v6() noexcept + { + return native_tcp(true); + } /// Return true if this is IPv6. - constexpr bool is_v6() const noexcept { return v6_; } + constexpr bool is_v6() const noexcept + { + return v6_; + } /// Return the address family (AF_INET or AF_INET6). int family() const noexcept @@ -74,10 +83,16 @@ class native_tcp } /// Return the socket type (SOCK_STREAM). - static constexpr int type() noexcept { return SOCK_STREAM; } + static constexpr int type() noexcept + { + return SOCK_STREAM; + } /// Return the IP protocol (IPPROTO_TCP). - static constexpr int protocol() noexcept { return IPPROTO_TCP; } + static constexpr int protocol() noexcept + { + return IPPROTO_TCP; + } /// The associated socket type. using socket = tcp_socket; @@ -85,12 +100,12 @@ class native_tcp /// The associated acceptor type. using acceptor = tcp_acceptor; - friend constexpr bool operator==( native_tcp a, native_tcp b ) noexcept + friend constexpr bool operator==(native_tcp a, native_tcp b) noexcept { return a.v6_ == b.v6_; } - friend constexpr bool operator!=( native_tcp a, native_tcp b ) noexcept + friend constexpr bool operator!=(native_tcp a, native_tcp b) noexcept { return a.v6_ != b.v6_; } diff --git a/include/boost/corosio/openssl_stream.hpp b/include/boost/corosio/openssl_stream.hpp index dd56abc1..10c21067 100644 --- a/include/boost/corosio/openssl_stream.hpp +++ b/include/boost/corosio/openssl_stream.hpp @@ -84,8 +84,7 @@ class BOOST_COROSIO_DECL openssl_stream final : public tls_stream */ template requires(!std::same_as, openssl_stream>) - // NOLINTNEXTLINE(performance-unnecessary-value-param) - openssl_stream(S stream, tls_context ctx) + openssl_stream(S stream, tls_context const& ctx) : stream_(std::move(stream)) , impl_(make_impl(stream_, ctx)) { @@ -102,8 +101,7 @@ class BOOST_COROSIO_DECL openssl_stream final : public tls_stream @param ctx The TLS context containing configuration. */ template - // NOLINTNEXTLINE(performance-unnecessary-value-param) - openssl_stream(S* stream, tls_context ctx) + openssl_stream(S* stream, tls_context const& ctx) : stream_(stream) , impl_(make_impl(stream_, ctx)) { diff --git a/include/boost/corosio/socket_option.hpp b/include/boost/corosio/socket_option.hpp index 44df37ed..cd85b0aa 100644 --- a/include/boost/corosio/socket_option.hpp +++ b/include/boost/corosio/socket_option.hpp @@ -50,32 +50,50 @@ class boolean_option @param v `true` to enable the option, `false` to disable. */ - explicit boolean_option( bool v ) noexcept : value_( v ? 1 : 0 ) {} + explicit boolean_option(bool v) noexcept : value_(v ? 1 : 0) {} /// Assign a new value. - boolean_option& operator=( bool v ) noexcept + boolean_option& operator=(bool v) noexcept { value_ = v ? 1 : 0; return *this; } /// Return the option value. - bool value() const noexcept { return value_ != 0; } + bool value() const noexcept + { + return value_ != 0; + } /// Return the option value. - explicit operator bool() const noexcept { return value_ != 0; } + explicit operator bool() const noexcept + { + return value_ != 0; + } /// Return the negated option value. - bool operator!() const noexcept { return value_ == 0; } + bool operator!() const noexcept + { + return value_ == 0; + } /// Return a pointer to the underlying storage. - void* data() noexcept { return &value_; } + void* data() noexcept + { + return &value_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return &value_; } + void const* data() const noexcept + { + return &value_; + } /// Return the size of the underlying storage. - std::size_t size() const noexcept { return sizeof( value_ ); } + std::size_t size() const noexcept + { + return sizeof(value_); + } /** Normalize after `getsockopt` returns fewer bytes than expected. @@ -83,10 +101,10 @@ class boolean_option @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t s ) noexcept + void resize(std::size_t s) noexcept { - if ( s == sizeof( char ) ) - value_ = *reinterpret_cast( &value_ ) ? 1 : 0; + if (s == sizeof(char)) + value_ = *reinterpret_cast(&value_) ? 1 : 0; } }; @@ -107,36 +125,48 @@ class integer_option @param v The option value. */ - explicit integer_option( int v ) noexcept : value_( v ) {} + explicit integer_option(int v) noexcept : value_(v) {} /// Assign a new value. - integer_option& operator=( int v ) noexcept + integer_option& operator=(int v) noexcept { value_ = v; return *this; } /// Return the option value. - int value() const noexcept { return value_; } + int value() const noexcept + { + return value_; + } /// Return a pointer to the underlying storage. - void* data() noexcept { return &value_; } + void* data() noexcept + { + return &value_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return &value_; } + void const* data() const noexcept + { + return &value_; + } /// Return the size of the underlying storage. - std::size_t size() const noexcept { return sizeof( value_ ); } + std::size_t size() const noexcept + { + return sizeof(value_); + } /** Normalize after `getsockopt` returns fewer bytes than expected. @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t s ) noexcept + void resize(std::size_t s) noexcept { - if ( s == sizeof( char ) ) - value_ = static_cast( - *reinterpret_cast( &value_ ) ); + if (s == sizeof(char)) + value_ = + static_cast(*reinterpret_cast(&value_)); } }; @@ -315,7 +345,7 @@ class BOOST_COROSIO_DECL linger // POSIX: { int, int } = 8 bytes. // Windows: { u_short, u_short } = 4 bytes. static constexpr std::size_t max_storage_ = 8; - alignas( 4 ) unsigned char storage_[max_storage_]{}; + alignas(4) unsigned char storage_[max_storage_]{}; public: /// Construct with default values (disabled, zero timeout). @@ -326,19 +356,19 @@ class BOOST_COROSIO_DECL linger @param enabled `true` to enable linger behavior on close. @param timeout The linger timeout in seconds. */ - linger( bool enabled, int timeout ) noexcept; + linger(bool enabled, int timeout) noexcept; /// Return whether linger is enabled. bool enabled() const noexcept; /// Set whether linger is enabled. - void enabled( bool v ) noexcept; + void enabled(bool v) noexcept; /// Return the linger timeout in seconds. int timeout() const noexcept; /// Set the linger timeout in seconds. - void timeout( int v ) noexcept; + void timeout(int v) noexcept; /// Return the protocol level. static int level() noexcept; @@ -347,10 +377,16 @@ class BOOST_COROSIO_DECL linger static int name() noexcept; /// Return a pointer to the underlying storage. - void* data() noexcept { return storage_; } + void* data() noexcept + { + return storage_; + } /// Return a pointer to the underlying storage. - void const* data() const noexcept { return storage_; } + void const* data() const noexcept + { + return storage_; + } /// Return the size of the underlying storage. std::size_t size() const noexcept; @@ -361,7 +397,7 @@ class BOOST_COROSIO_DECL linger @param s The number of bytes actually written by `getsockopt`. */ - void resize( std::size_t ) noexcept {} + void resize(std::size_t) noexcept {} }; } // namespace boost::corosio::socket_option diff --git a/include/boost/corosio/tcp.hpp b/include/boost/corosio/tcp.hpp index 1e554b1a..711ac2c6 100644 --- a/include/boost/corosio/tcp.hpp +++ b/include/boost/corosio/tcp.hpp @@ -42,17 +42,26 @@ class tcp_acceptor; class BOOST_COROSIO_DECL tcp { bool v6_; - explicit constexpr tcp( bool v6 ) noexcept : v6_( v6 ) {} + explicit constexpr tcp(bool v6) noexcept : v6_(v6) {} public: /// Construct an IPv4 TCP protocol. - static constexpr tcp v4() noexcept { return tcp( false ); } + static constexpr tcp v4() noexcept + { + return tcp(false); + } /// Construct an IPv6 TCP protocol. - static constexpr tcp v6() noexcept { return tcp( true ); } + static constexpr tcp v6() noexcept + { + return tcp(true); + } /// Return true if this is IPv6. - constexpr bool is_v6() const noexcept { return v6_; } + constexpr bool is_v6() const noexcept + { + return v6_; + } /// Return the address family (AF_INET or AF_INET6). int family() const noexcept; @@ -69,12 +78,12 @@ class BOOST_COROSIO_DECL tcp /// The associated acceptor type. using acceptor = tcp_acceptor; - friend constexpr bool operator==( tcp a, tcp b ) noexcept + friend constexpr bool operator==(tcp a, tcp b) noexcept { return a.v6_ == b.v6_; } - friend constexpr bool operator!=( tcp a, tcp b ) noexcept + friend constexpr bool operator!=(tcp a, tcp b) noexcept { return a.v6_ != b.v6_; } diff --git a/include/boost/corosio/tcp_acceptor.hpp b/include/boost/corosio/tcp_acceptor.hpp index d5f093eb..702543e1 100644 --- a/include/boost/corosio/tcp_acceptor.hpp +++ b/include/boost/corosio/tcp_acceptor.hpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -143,8 +142,7 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @throws std::system_error on bind or listen failure. */ - tcp_acceptor( - capy::execution_context& ctx, endpoint ep, int backlog = 128 ); + tcp_acceptor(capy::execution_context& ctx, endpoint ep, int backlog = 128); /** Construct an acceptor from an executor. @@ -169,7 +167,7 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object */ template requires capy::Executor - tcp_acceptor(Ex const& ex, endpoint ep, int backlog = 128 ) + tcp_acceptor(Ex const& ex, endpoint ep, int backlog = 128) : tcp_acceptor(ex.context(), ep, backlog) { } @@ -235,7 +233,7 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @see bind, listen */ - void open( tcp proto = tcp::v4() ); + void open(tcp proto = tcp::v4()); /** Bind to a local endpoint. @@ -257,7 +255,7 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @throws std::logic_error if the acceptor is not open. */ - [[nodiscard]] std::error_code bind( endpoint ep ); + [[nodiscard]] std::error_code bind(endpoint ep); /** Start listening for incoming connections. @@ -272,7 +270,7 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @throws std::logic_error if the acceptor is not open. */ - [[nodiscard]] std::error_code listen( int backlog = 128 ); + [[nodiscard]] std::error_code listen(int backlog = 128); /** Close the acceptor. @@ -379,16 +377,14 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @throws std::system_error on failure. */ template - void set_option( Option const& opt ) + void set_option(Option const& opt) { if (!is_open()) - detail::throw_logic_error( - "set_option: acceptor not open" ); + detail::throw_logic_error("set_option: acceptor not open"); std::error_code ec = get().set_option( - Option::level(), Option::name(), opt.data(), opt.size() ); + Option::level(), Option::name(), opt.data(), opt.size()); if (ec) - detail::throw_system_error( - ec, "tcp_acceptor::set_option" ); + detail::throw_system_error(ec, "tcp_acceptor::set_option"); } /** Get a socket option from the acceptor. @@ -409,16 +405,14 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object Option get_option() const { if (!is_open()) - detail::throw_logic_error( - "get_option: acceptor not open" ); + detail::throw_logic_error("get_option: acceptor not open"); Option opt{}; std::size_t sz = opt.size(); - std::error_code ec = get().get_option( - Option::level(), Option::name(), opt.data(), &sz ); + std::error_code ec = + get().get_option(Option::level(), Option::name(), opt.data(), &sz); if (ec) - detail::throw_system_error( - ec, "tcp_acceptor::get_option" ); - opt.resize( sz ); + detail::throw_system_error(ec, "tcp_acceptor::get_option"); + opt.resize(sz); return opt; } @@ -452,8 +446,10 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object @return Error code on failure, empty on success. */ virtual std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept = 0; + int level, + int optname, + void const* data, + std::size_t size) noexcept = 0; /** Get a socket option. @@ -464,9 +460,9 @@ class BOOST_COROSIO_DECL tcp_acceptor : public io_object the size of the option value. @return Error code on failure, empty on success. */ - virtual std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept = 0; + virtual std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept = 0; }; protected: diff --git a/include/boost/corosio/tcp_socket.hpp b/include/boost/corosio/tcp_socket.hpp index d5dfd8ab..e67ca702 100644 --- a/include/boost/corosio/tcp_socket.hpp +++ b/include/boost/corosio/tcp_socket.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -119,8 +118,10 @@ class BOOST_COROSIO_DECL tcp_socket : public io_stream @return Error code on failure, empty on success. */ virtual std::error_code set_option( - int level, int optname, - void const* data, std::size_t size) noexcept = 0; + int level, + int optname, + void const* data, + std::size_t size) noexcept = 0; /** Get a socket option. @@ -131,9 +132,9 @@ class BOOST_COROSIO_DECL tcp_socket : public io_stream the size of the option value. @return Error code on failure, empty on success. */ - virtual std::error_code get_option( - int level, int optname, - void* data, std::size_t* size) const noexcept = 0; + virtual std::error_code + get_option(int level, int optname, void* data, std::size_t* size) + const noexcept = 0; /// Returns the cached local endpoint. virtual endpoint local_endpoint() const noexcept = 0; @@ -256,7 +257,7 @@ class BOOST_COROSIO_DECL tcp_socket : public io_stream @throws std::system_error on failure. */ - void open( tcp proto = tcp::v4() ); + void open(tcp proto = tcp::v4()); /** Close the socket. @@ -398,14 +399,14 @@ class BOOST_COROSIO_DECL tcp_socket : public io_stream @throws std::system_error on failure. */ template - void set_option( Option const& opt ) + void set_option(Option const& opt) { if (!is_open()) - detail::throw_logic_error( "set_option: socket not open" ); + detail::throw_logic_error("set_option: socket not open"); std::error_code ec = get().set_option( - Option::level(), Option::name(), opt.data(), opt.size() ); + Option::level(), Option::name(), opt.data(), opt.size()); if (ec) - detail::throw_system_error( ec, "tcp_socket::set_option" ); + detail::throw_system_error(ec, "tcp_socket::set_option"); } /** Get a socket option. @@ -428,14 +429,14 @@ class BOOST_COROSIO_DECL tcp_socket : public io_stream Option get_option() const { if (!is_open()) - detail::throw_logic_error( "get_option: socket not open" ); + detail::throw_logic_error("get_option: socket not open"); Option opt{}; std::size_t sz = opt.size(); - std::error_code ec = get().get_option( - Option::level(), Option::name(), opt.data(), &sz ); + std::error_code ec = + get().get_option(Option::level(), Option::name(), opt.data(), &sz); if (ec) - detail::throw_system_error( ec, "tcp_socket::get_option" ); - opt.resize( sz ); + detail::throw_system_error(ec, "tcp_socket::get_option"); + opt.resize(sz); return opt; } diff --git a/include/boost/corosio/test/mocket.hpp b/include/boost/corosio/test/mocket.hpp index 1d763b76..81e01d3a 100644 --- a/include/boost/corosio/test/mocket.hpp +++ b/include/boost/corosio/test/mocket.hpp @@ -522,8 +522,7 @@ make_mocket_pair( acc.open(); acc.set_option(socket_option::reuse_address(true)); if (auto bind_ec = acc.bind(endpoint(ipv4_address::loopback(), 0))) - throw std::runtime_error( - "mocket bind failed: " + bind_ec.message()); + throw std::runtime_error("mocket bind failed: " + bind_ec.message()); if (auto listen_ec = acc.listen()) throw std::runtime_error( "mocket listen failed: " + listen_ec.message()); diff --git a/include/boost/corosio/wolfssl_stream.hpp b/include/boost/corosio/wolfssl_stream.hpp index fbf66199..6f8eab9c 100644 --- a/include/boost/corosio/wolfssl_stream.hpp +++ b/include/boost/corosio/wolfssl_stream.hpp @@ -84,8 +84,7 @@ class BOOST_COROSIO_DECL wolfssl_stream final : public tls_stream */ template requires(!std::same_as, wolfssl_stream>) - // NOLINTNEXTLINE(performance-unnecessary-value-param) - wolfssl_stream(S stream, tls_context ctx) + wolfssl_stream(S stream, tls_context const& ctx) : stream_(std::move(stream)) , impl_(make_impl(stream_, ctx)) { @@ -102,8 +101,7 @@ class BOOST_COROSIO_DECL wolfssl_stream final : public tls_stream @param ctx The TLS context containing configuration. */ template - // NOLINTNEXTLINE(performance-unnecessary-value-param) - wolfssl_stream(S* stream, tls_context ctx) + wolfssl_stream(S* stream, tls_context const& ctx) : stream_(stream) , impl_(make_impl(stream_, ctx)) { diff --git a/src/corosio/src/endpoint.cpp b/src/corosio/src/endpoint.cpp index 02fda095..2acef064 100644 --- a/src/corosio/src/endpoint.cpp +++ b/src/corosio/src/endpoint.cpp @@ -9,7 +9,6 @@ #include -#include #include namespace boost::corosio { diff --git a/src/corosio/src/socket_option.cpp b/src/corosio/src/socket_option.cpp index 06629ea8..e9b971c1 100644 --- a/src/corosio/src/socket_option.cpp +++ b/src/corosio/src/socket_option.cpp @@ -16,91 +16,163 @@ namespace boost::corosio::socket_option { // no_delay -int no_delay::level() noexcept { return native_socket_option::no_delay::level(); } -int no_delay::name() noexcept { return native_socket_option::no_delay::name(); } +int +no_delay::level() noexcept +{ + return native_socket_option::no_delay::level(); +} +int +no_delay::name() noexcept +{ + return native_socket_option::no_delay::name(); +} // keep_alive -int keep_alive::level() noexcept { return native_socket_option::keep_alive::level(); } -int keep_alive::name() noexcept { return native_socket_option::keep_alive::name(); } +int +keep_alive::level() noexcept +{ + return native_socket_option::keep_alive::level(); +} +int +keep_alive::name() noexcept +{ + return native_socket_option::keep_alive::name(); +} // v6_only -int v6_only::level() noexcept { return native_socket_option::v6_only::level(); } -int v6_only::name() noexcept { return native_socket_option::v6_only::name(); } +int +v6_only::level() noexcept +{ + return native_socket_option::v6_only::level(); +} +int +v6_only::name() noexcept +{ + return native_socket_option::v6_only::name(); +} // reuse_address -int reuse_address::level() noexcept { return native_socket_option::reuse_address::level(); } -int reuse_address::name() noexcept { return native_socket_option::reuse_address::name(); } +int +reuse_address::level() noexcept +{ + return native_socket_option::reuse_address::level(); +} +int +reuse_address::name() noexcept +{ + return native_socket_option::reuse_address::name(); +} // reuse_port #ifdef SO_REUSEPORT -int reuse_port::level() noexcept { return native_socket_option::reuse_port::level(); } -int reuse_port::name() noexcept { return native_socket_option::reuse_port::name(); } +int +reuse_port::level() noexcept +{ + return native_socket_option::reuse_port::level(); +} +int +reuse_port::name() noexcept +{ + return native_socket_option::reuse_port::name(); +} #else -int reuse_port::level() noexcept { return SOL_SOCKET; } -int reuse_port::name() noexcept { return -1; } +int +reuse_port::level() noexcept +{ + return SOL_SOCKET; +} +int +reuse_port::name() noexcept +{ + return -1; +} #endif // receive_buffer_size -int receive_buffer_size::level() noexcept { return native_socket_option::receive_buffer_size::level(); } -int receive_buffer_size::name() noexcept { return native_socket_option::receive_buffer_size::name(); } +int +receive_buffer_size::level() noexcept +{ + return native_socket_option::receive_buffer_size::level(); +} +int +receive_buffer_size::name() noexcept +{ + return native_socket_option::receive_buffer_size::name(); +} // send_buffer_size -int send_buffer_size::level() noexcept { return native_socket_option::send_buffer_size::level(); } -int send_buffer_size::name() noexcept { return native_socket_option::send_buffer_size::name(); } +int +send_buffer_size::level() noexcept +{ + return native_socket_option::send_buffer_size::level(); +} +int +send_buffer_size::name() noexcept +{ + return native_socket_option::send_buffer_size::name(); +} // linger -linger::linger( bool enabled, int timeout ) noexcept +linger::linger(bool enabled, int timeout) noexcept { - native_socket_option::linger native( enabled, timeout ); + native_socket_option::linger native(enabled, timeout); static_assert( - sizeof( native ) <= sizeof( storage_ ), - "platform linger exceeds socket_option::linger storage" ); - std::memcpy( storage_, native.data(), native.size() ); + sizeof(native) <= sizeof(storage_), + "platform linger exceeds socket_option::linger storage"); + std::memcpy(storage_, native.data(), native.size()); } bool linger::enabled() const noexcept { native_socket_option::linger native; - std::memcpy( native.data(), storage_, native.size() ); + std::memcpy(native.data(), storage_, native.size()); return native.enabled(); } void -linger::enabled( bool e ) noexcept +linger::enabled(bool e) noexcept { native_socket_option::linger native; - std::memcpy( native.data(), storage_, native.size() ); - native.enabled( e ); - std::memcpy( storage_, native.data(), native.size() ); + std::memcpy(native.data(), storage_, native.size()); + native.enabled(e); + std::memcpy(storage_, native.data(), native.size()); } int linger::timeout() const noexcept { native_socket_option::linger native; - std::memcpy( native.data(), storage_, native.size() ); + std::memcpy(native.data(), storage_, native.size()); return native.timeout(); } void -linger::timeout( int t ) noexcept +linger::timeout(int t) noexcept { native_socket_option::linger native; - std::memcpy( native.data(), storage_, native.size() ); - native.timeout( t ); - std::memcpy( storage_, native.data(), native.size() ); + std::memcpy(native.data(), storage_, native.size()); + native.timeout(t); + std::memcpy(storage_, native.data(), native.size()); } -int linger::level() noexcept { return native_socket_option::linger::level(); } -int linger::name() noexcept { return native_socket_option::linger::name(); } +int +linger::level() noexcept +{ + return native_socket_option::linger::level(); +} +int +linger::name() noexcept +{ + return native_socket_option::linger::name(); +} std::size_t linger::size() const noexcept diff --git a/src/corosio/src/tcp.cpp b/src/corosio/src/tcp.cpp index fbeb1027..96eab3e1 100644 --- a/src/corosio/src/tcp.cpp +++ b/src/corosio/src/tcp.cpp @@ -15,7 +15,7 @@ namespace boost::corosio { int tcp::family() const noexcept { - return native_tcp( v6_ ? native_tcp::v6() : native_tcp::v4() ).family(); + return native_tcp(v6_ ? native_tcp::v6() : native_tcp::v4()).family(); } int diff --git a/src/corosio/src/tcp_acceptor.cpp b/src/corosio/src/tcp_acceptor.cpp index 88a7e417..c8364d2e 100644 --- a/src/corosio/src/tcp_acceptor.cpp +++ b/src/corosio/src/tcp_acceptor.cpp @@ -60,8 +60,8 @@ tcp_acceptor::open(tcp proto) auto& svc = static_cast(h_.service()); #endif std::error_code ec = svc.open_acceptor_socket( - *static_cast(h_.get()), - proto.family(), proto.type(), proto.protocol()); + *static_cast(h_.get()), proto.family(), + proto.type(), proto.protocol()); if (ec) detail::throw_system_error(ec, "tcp_acceptor::open"); } diff --git a/src/corosio/src/tcp_socket.cpp b/src/corosio/src/tcp_socket.cpp index b5f4a78f..344e2f98 100644 --- a/src/corosio/src/tcp_socket.cpp +++ b/src/corosio/src/tcp_socket.cpp @@ -49,13 +49,13 @@ tcp_socket::open_for_family(int family, int type, int protocol) auto& svc = static_cast(h_.service()); auto& wrapper = static_cast(*h_.get()); std::error_code ec = svc.open_socket( - *static_cast(wrapper).get_internal(), - family, type, protocol); + *static_cast(wrapper).get_internal(), family, type, + protocol); #else - auto& svc = static_cast(h_.service()); + auto& svc = static_cast(h_.service()); std::error_code ec = svc.open_socket( - static_cast(*h_.get()), - family, type, protocol); + static_cast(*h_.get()), family, type, + protocol); #endif if (ec) detail::throw_system_error(ec, "tcp_socket::open"); diff --git a/test/unit/acceptor.cpp b/test/unit/acceptor.cpp index 1da29c65..3266b964 100644 --- a/test/unit/acceptor.cpp +++ b/test/unit/acceptor.cpp @@ -249,21 +249,21 @@ struct acceptor_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, peer, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(client, endpoint(ipv6_address::loopback(), port), - connect_ec, connect_done)); + }(client, endpoint(ipv6_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -304,8 +304,8 @@ struct acceptor_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; @@ -313,13 +313,13 @@ struct acceptor_test // Connect with IPv4 client to the dual-stack listener capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(client, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(client, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -361,13 +361,13 @@ struct acceptor_test // IPv4 connect should be refused capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(client, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(client, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); // Cancel lingering accept after connect completes auto cancel_task = [&]() -> capy::task<> { @@ -413,21 +413,21 @@ struct acceptor_test auto port = acc.local_endpoint().port(); auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, peer, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(client, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(client, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -528,21 +528,21 @@ struct acceptor_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, peer, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(client, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(client, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -564,8 +564,7 @@ struct acceptor_test acc.open(); // Bind to an address not assigned to any local interface - auto ec = acc.bind(endpoint( - ipv4_address("1.2.3.4"), 0)); + auto ec = acc.bind(endpoint(ipv4_address("1.2.3.4"), 0)); BOOST_TEST(ec); acc.close(); diff --git a/test/unit/cancel.cpp b/test/unit/cancel.cpp index 579aed37..66231ebb 100644 --- a/test/unit/cancel.cpp +++ b/test/unit/cancel.cpp @@ -64,8 +64,7 @@ struct cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), timeout_timer, - std::chrono::seconds(1)); + inner_timer.wait(), timeout_timer, std::chrono::seconds(1)); result_ec = ec; completed = true; }; @@ -116,8 +115,7 @@ struct cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), timeout_timer, - std::chrono::seconds(60)); + inner_timer.wait(), timeout_timer, std::chrono::seconds(60)); result_ec = ec; completed = true; }; @@ -128,8 +126,7 @@ struct cancel_test stop_src.request_stop(); }; - capy::run_async(ioc.get_executor(), stop_src.get_token())( - task()); + capy::run_async(ioc.get_executor(), stop_src.get_token())(task()); capy::run_async(ioc.get_executor())(canceller()); ioc.run(); @@ -176,8 +173,8 @@ struct cancel_test timer::clock_type::now() + std::chrono::milliseconds(10); auto task = [&]() -> capy::task<> { - auto [ec] = co_await cancel_at( - inner_timer.wait(), timeout_timer, deadline); + auto [ec] = + co_await cancel_at(inner_timer.wait(), timeout_timer, deadline); result_ec = ec; completed = true; }; @@ -200,8 +197,7 @@ struct cancel_test // First: inner completes before timeout inner_timer.expires_after(std::chrono::milliseconds(10)); auto [ec1] = co_await cancel_after( - inner_timer.wait(), timeout_timer, - std::chrono::seconds(1)); + inner_timer.wait(), timeout_timer, std::chrono::seconds(1)); BOOST_TEST(!ec1); ++completed; @@ -216,8 +212,7 @@ struct cancel_test // Third: inner completes again inner_timer.expires_after(std::chrono::milliseconds(10)); auto [ec3] = co_await cancel_after( - inner_timer.wait(), timeout_timer, - std::chrono::seconds(1)); + inner_timer.wait(), timeout_timer, std::chrono::seconds(1)); BOOST_TEST(!ec3); ++completed; }; @@ -241,8 +236,7 @@ struct cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), - std::chrono::milliseconds(10)); + inner_timer.wait(), std::chrono::milliseconds(10)); result_ec = ec; completed = true; }; @@ -265,8 +259,7 @@ struct cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), - std::chrono::seconds(1)); + inner_timer.wait(), std::chrono::seconds(1)); result_ec = ec; completed = true; }; @@ -290,8 +283,7 @@ struct cancel_test timer::clock_type::now() + std::chrono::milliseconds(10); auto task = [&]() -> capy::task<> { - auto [ec] = co_await cancel_at( - inner_timer.wait(), deadline); + auto [ec] = co_await cancel_at(inner_timer.wait(), deadline); result_ec = ec; completed = true; }; diff --git a/test/unit/endpoint.cpp b/test/unit/endpoint.cpp index a40b5420..9ce03d44 100644 --- a/test/unit/endpoint.cpp +++ b/test/unit/endpoint.cpp @@ -10,7 +10,6 @@ // Test that header file is self-contained. #include -#include #include #include "test_suite.hpp" diff --git a/test/unit/io_buffer_param.cpp b/test/unit/io_buffer_param.cpp index 299c132f..e3c7d90e 100644 --- a/test/unit/io_buffer_param.cpp +++ b/test/unit/io_buffer_param.cpp @@ -8,7 +8,7 @@ // // Test that header file is self-contained. -#include +#include #include #include @@ -18,11 +18,11 @@ namespace boost::corosio { -struct io_buffer_param_test +struct buffer_param_test { // Helper to reduce repeated copy_to assertion pattern static void check_copy( - io_buffer_param p, + buffer_param p, std::initializer_list> expected) { capy::mutable_buffer dest[8]; @@ -38,7 +38,7 @@ struct io_buffer_param_test } // Helper for checking empty/zero-byte sequences - static void check_empty(io_buffer_param p) + static void check_empty(buffer_param p) { capy::mutable_buffer dest[8]; BOOST_TEST_EQ(p.copy_to(dest, 8), 0); @@ -119,7 +119,7 @@ struct io_buffer_param_test capy::const_buffer(data1, 3), capy::const_buffer(data2, 3), capy::const_buffer(data3, 5)}; - io_buffer_param ref(arr); + buffer_param ref(arr); // copy only 2 buffers capy::mutable_buffer dest[2]; @@ -222,15 +222,15 @@ struct io_buffer_param_test check_empty(arr); } - // Helper function that accepts io_buffer_param by value - static std::size_t acceptByValue(io_buffer_param p) + // Helper function that accepts buffer_param by value + static std::size_t acceptByValue(buffer_param p) { capy::mutable_buffer dest[8]; return p.copy_to(dest, 8); } - // Helper function that accepts io_buffer_param by const reference - static std::size_t acceptByConstRef(io_buffer_param const& p) + // Helper function that accepts buffer_param by const reference + static std::size_t acceptByConstRef(buffer_param const& p) { capy::mutable_buffer dest[8]; return p.copy_to(dest, 8); @@ -238,7 +238,7 @@ struct io_buffer_param_test void testPassByValue() { - // Test that io_buffer_param works when passed by value + // Test that buffer_param works when passed by value char const data[] = "Hello"; capy::const_buffer cb(data, 5); @@ -246,8 +246,8 @@ struct io_buffer_param_test auto n = acceptByValue(cb); BOOST_TEST_EQ(n, 1); - // Pass io_buffer_param object - io_buffer_param p(cb); + // Pass buffer_param object + buffer_param p(cb); n = acceptByValue(p); BOOST_TEST_EQ(n, 1); @@ -260,16 +260,16 @@ struct io_buffer_param_test void testPassByConstRef() { - // Test that io_buffer_param works when passed by const reference + // Test that buffer_param works when passed by const reference char const data[] = "Hello"; capy::const_buffer cb(data, 5); - // Pass io_buffer_param object by const ref - io_buffer_param p(cb); + // Pass buffer_param object by const ref + buffer_param p(cb); auto n = acceptByConstRef(p); BOOST_TEST_EQ(n, 1); - // Pass buffer sequence directly (creates temporary io_buffer_param) + // Pass buffer sequence directly (creates temporary buffer_param) n = acceptByConstRef( std::array{ {capy::const_buffer(data, 2), @@ -302,6 +302,6 @@ struct io_buffer_param_test } }; -TEST_SUITE(io_buffer_param_test, "boost.corosio.io_buffer_param"); +TEST_SUITE(buffer_param_test, "boost.corosio.buffer_param"); } // namespace boost::corosio diff --git a/test/unit/io_context.cpp b/test/unit/io_context.cpp index 0de60ef0..86795452 100644 --- a/test/unit/io_context.cpp +++ b/test/unit/io_context.cpp @@ -10,7 +10,6 @@ // Test that header file is self-contained. #include -#include #include #include #include @@ -139,10 +138,19 @@ struct destroy_counter_coro return {std::coroutine_handle::from_promise(*this)}; } - std::suspend_always initial_suspend() noexcept { return {}; } - std::suspend_always final_suspend() noexcept { return {}; } + std::suspend_always initial_suspend() noexcept + { + return {}; + } + std::suspend_always final_suspend() noexcept + { + return {}; + } void return_void() {} - void unhandled_exception() { std::terminate(); } + void unhandled_exception() + { + std::terminate(); + } ~promise_type() { @@ -153,7 +161,10 @@ struct destroy_counter_coro std::coroutine_handle h; - operator std::coroutine_handle<>() const { return h; } + operator std::coroutine_handle<>() const + { + return h; + } }; inline destroy_counter_coro @@ -469,6 +480,7 @@ struct io_context_test // Post handlers from multiple threads concurrently std::vector posters; + posters.reserve(num_threads); for (int t = 0; t < num_threads; ++t) { posters.emplace_back([&ex, &counter]() { @@ -483,6 +495,7 @@ struct io_context_test // Run with multiple threads std::vector runners; + runners.reserve(num_threads); for (int t = 0; t < num_threads; ++t) runners.emplace_back([&ioc]() { ioc.run(); }); @@ -512,6 +525,7 @@ struct io_context_test // Run with multiple threads std::vector runners; + runners.reserve(num_threads); for (int t = 0; t < num_threads; ++t) runners.emplace_back([&ioc]() { ioc.run(); }); @@ -619,6 +633,7 @@ struct io_context_shutdown_test } }; -COROSIO_BACKEND_TESTS(io_context_shutdown_test, "boost.corosio.io_context_shutdown") +COROSIO_BACKEND_TESTS( + io_context_shutdown_test, "boost.corosio.io_context_shutdown") } // namespace boost::corosio diff --git a/test/unit/ipv4_address.cpp b/test/unit/ipv4_address.cpp index 7e7d8a24..d7e50277 100644 --- a/test/unit/ipv4_address.cpp +++ b/test/unit/ipv4_address.cpp @@ -11,7 +11,6 @@ #include #include -#include #include "test_suite.hpp" diff --git a/test/unit/ipv6_address.cpp b/test/unit/ipv6_address.cpp index 96565510..6681e1a0 100644 --- a/test/unit/ipv6_address.cpp +++ b/test/unit/ipv6_address.cpp @@ -12,7 +12,6 @@ #include #include -#include #include "test_suite.hpp" diff --git a/test/unit/native/iocp/iocp_shutdown.cpp b/test/unit/native/iocp/iocp_shutdown.cpp index 3b0255db..d048db7c 100644 --- a/test/unit/native/iocp/iocp_shutdown.cpp +++ b/test/unit/native/iocp/iocp_shutdown.cpp @@ -35,10 +35,7 @@ struct test_overlapped_op : detail::overlapped_op int* destroyed_; static void do_complete( - void* owner, - detail::scheduler_op* base, - std::uint32_t, - std::uint32_t) + void* owner, detail::scheduler_op* base, std::uint32_t, std::uint32_t) { auto* self = static_cast(base); if (!owner) @@ -100,9 +97,7 @@ struct iocp_shutdown_test ex.on_work_started(); BOOL ok = ::PostQueuedCompletionStatus( - ioc, - 0, - detail::key_result_stored, + ioc, 0, detail::key_result_stored, static_cast(op)); BOOST_TEST(ok != 0); } @@ -126,15 +121,13 @@ struct iocp_shutdown_test ::PostQueuedCompletionStatus( ioc, 0, detail::key_io, static_cast(io_op)); - auto* stored_op = new test_overlapped_op(stored_destroyed); - stored_op->ready_ = 1; - stored_op->dwError = 0; + auto* stored_op = new test_overlapped_op(stored_destroyed); + stored_op->ready_ = 1; + stored_op->dwError = 0; stored_op->bytes_transferred = 0; ex.on_work_started(); ::PostQueuedCompletionStatus( - ioc, - 0, - detail::key_result_stored, + ioc, 0, detail::key_result_stored, static_cast(stored_op)); } diff --git a/test/unit/native/native_cancel.cpp b/test/unit/native/native_cancel.cpp index 3271aaeb..98f7865d 100644 --- a/test/unit/native/native_cancel.cpp +++ b/test/unit/native/native_cancel.cpp @@ -37,8 +37,7 @@ struct native_cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), - std::chrono::milliseconds(10)); + inner_timer.wait(), std::chrono::milliseconds(10)); result_ec = ec; completed = true; }; @@ -61,8 +60,7 @@ struct native_cancel_test auto task = [&]() -> capy::task<> { auto [ec] = co_await cancel_after( - inner_timer.wait(), - std::chrono::seconds(1)); + inner_timer.wait(), std::chrono::seconds(1)); result_ec = ec; completed = true; }; @@ -86,8 +84,8 @@ struct native_cancel_test timer::clock_type::now() + std::chrono::milliseconds(10); auto task = [&]() -> capy::task<> { - auto [ec] = co_await cancel_at( - inner_timer.wait(), deadline); + auto [ec] = + co_await cancel_at(inner_timer.wait(), deadline); result_ec = ec; completed = true; }; diff --git a/test/unit/openssl_stream.cpp b/test/unit/openssl_stream.cpp index 97235516..34175976 100644 --- a/test/unit/openssl_stream.cpp +++ b/test/unit/openssl_stream.cpp @@ -19,12 +19,12 @@ namespace boost::corosio { // Callable wrapper for passing to test helper templates struct openssl_stream_factory { - auto operator()(tcp_socket& s, tls_context ctx) const + auto operator()(tcp_socket& s, tls_context const& ctx) const { return openssl_stream(&s, ctx); } - auto operator()(corosio::test::mocket& s, tls_context ctx) const + auto operator()(corosio::test::mocket& s, tls_context const& ctx) const { return openssl_stream(&s, ctx); } diff --git a/test/unit/resolver.cpp b/test/unit/resolver.cpp index bf7a6110..2ccc83bf 100644 --- a/test/unit/resolver.cpp +++ b/test/unit/resolver.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/test/unit/socket.cpp b/test/unit/socket.cpp index 32916238..646fa940 100644 --- a/test/unit/socket.cpp +++ b/test/unit/socket.cpp @@ -64,7 +64,8 @@ make_socket_pair_t(io_context& ctx) acc.open(); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv4_address::loopback(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); if (ec) throw std::runtime_error("socket_pair: listen failed"); auto port = acc.local_endpoint().port(); @@ -410,7 +411,7 @@ struct socket_test auto task = [](tcp_socket& a, tcp_socket& b) -> capy::task<> { // 64KB data - larger than typical TCP segment - constexpr std::size_t size = 64 * 1024; + constexpr std::size_t size = std::size_t{64} * 1024; std::vector send_data(size); for (std::size_t i = 0; i < size; ++i) send_data[i] = static_cast(i & 0xFF); @@ -894,16 +895,14 @@ struct socket_test sock.open(); sock.set_option(socket_option::no_delay(true)); - BOOST_TEST_EQ( - sock.get_option().value(), true); + BOOST_TEST_EQ(sock.get_option().value(), true); sock.set_option(socket_option::no_delay(false)); BOOST_TEST_EQ( sock.get_option().value(), false); sock.set_option(socket_option::no_delay(true)); - BOOST_TEST_EQ( - sock.get_option().value(), true); + BOOST_TEST_EQ(sock.get_option().value(), true); sock.close(); } @@ -1002,16 +1001,13 @@ struct socket_test auto [s1, s2] = make_socket_pair_t(ioc); s1.set_option(socket_option::no_delay(true)); - BOOST_TEST_EQ( - s1.get_option().value(), true); + BOOST_TEST_EQ(s1.get_option().value(), true); s2.set_option(socket_option::no_delay(true)); - BOOST_TEST_EQ( - s2.get_option().value(), true); + BOOST_TEST_EQ(s2.get_option().value(), true); s1.set_option(socket_option::keep_alive(true)); - BOOST_TEST_EQ( - s1.get_option().value(), true); + BOOST_TEST_EQ(s1.get_option().value(), true); int recv_size = s1.get_option().value(); @@ -1032,12 +1028,10 @@ struct socket_test sock.open(); sock.set_option(socket_option::no_delay(true)); - BOOST_TEST( - sock.get_option().value()); + BOOST_TEST(sock.get_option().value()); sock.set_option(socket_option::no_delay(false)); - BOOST_TEST( - !sock.get_option().value()); + BOOST_TEST(!sock.get_option().value()); sock.close(); } @@ -1049,8 +1043,7 @@ struct socket_test sock.open(); sock.set_option(socket_option::receive_buffer_size(32768)); - int sz = - sock.get_option().value(); + int sz = sock.get_option().value(); BOOST_TEST(sz >= 32768); sock.close(); @@ -1082,14 +1075,12 @@ struct socket_test nd = true; BOOST_TEST(nd.value()); sock.set_option(nd); - BOOST_TEST( - sock.get_option().value()); + BOOST_TEST(sock.get_option().value()); nd = false; BOOST_TEST(!nd); sock.set_option(nd); - BOOST_TEST( - !sock.get_option().value()); + BOOST_TEST(!sock.get_option().value()); // integer assignment socket_option::receive_buffer_size rbs(0); @@ -1097,8 +1088,8 @@ struct socket_test BOOST_TEST_EQ(rbs.value(), 32768); sock.set_option(rbs); BOOST_TEST( - sock.get_option() - .value() >= 32768); + sock.get_option().value() >= + 32768); // linger setters socket_option::linger lg; @@ -1124,7 +1115,7 @@ struct socket_test auto [s1, s2] = make_socket_pair_t(ioc); // 128KB payload - constexpr std::size_t size = 128 * 1024; + constexpr std::size_t size = std::size_t{128} * 1024; std::vector send_data(size); for (std::size_t i = 0; i < size; ++i) send_data[i] = static_cast((i * 7 + 13) & 0xFF); @@ -1144,8 +1135,7 @@ struct socket_test auto reader = [&]() -> capy::task<> { auto [ec, n] = co_await capy::read( - s2, - capy::mutable_buffer(recv_data.data(), recv_data.size())); + s2, capy::mutable_buffer(recv_data.data(), recv_data.size())); read_ec = ec; read_n = n; }; @@ -1207,7 +1197,8 @@ struct socket_test acc.open(); acc.set_option(socket_option::reuse_address(true)); auto listen_ec = acc.bind(endpoint(ipv4_address::loopback(), 0)); - if (!listen_ec) listen_ec = acc.listen(); + if (!listen_ec) + listen_ec = acc.listen(); BOOST_TEST(!listen_ec); // Acceptor's local endpoint should have a non-zero OS-assigned port @@ -1278,7 +1269,8 @@ struct socket_test { acc.open(); acc.set_option(socket_option::reuse_address(true)); - if (!acc.bind(endpoint(ipv4_address::loopback(), test_port)) && !acc.listen()) + if (!acc.bind(endpoint(ipv4_address::loopback(), test_port)) && + !acc.listen()) { found = true; break; @@ -1577,7 +1569,8 @@ struct socket_test acc.open(tcp::v6()); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv6_address::loopback(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); BOOST_TEST(!ec); BOOST_TEST(acc.local_endpoint().is_v6()); @@ -1592,21 +1585,21 @@ struct socket_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, s1, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(s2, endpoint(ipv6_address::loopback(), port), - connect_ec, connect_done)); + }(s2, endpoint(ipv6_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -1634,7 +1627,8 @@ struct socket_test acc.open(); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv4_address::loopback(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); BOOST_TEST(!ec); auto port = acc.local_endpoint().port(); @@ -1648,21 +1642,21 @@ struct socket_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, s1, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(s2, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(s2, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -1687,7 +1681,8 @@ struct socket_test acc.open(); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv4_address::loopback(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); BOOST_TEST(!ec); auto port = acc.local_endpoint().port(); @@ -1703,21 +1698,21 @@ struct socket_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, s1, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(s2, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(s2, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); @@ -1742,7 +1737,8 @@ struct socket_test acc.open(tcp::v6()); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv6_address::loopback(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); BOOST_TEST(!ec); auto port = acc.local_endpoint().port(); @@ -1755,21 +1751,21 @@ struct socket_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; }(acc, s1, accept_ec, accept_done)); capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(s2, endpoint(ipv6_address::loopback(), port), - connect_ec, connect_done)); + }(s2, endpoint(ipv6_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); ioc.restart(); @@ -1781,8 +1777,8 @@ struct socket_test // Round-trip data over IPv6 std::string const msg = "hello IPv6"; - bool write_done = false; - bool read_done = false; + bool write_done = false; + bool read_done = false; std::error_code write_ec, read_ec; std::size_t write_n = 0, read_n = 0; char buf[64]{}; @@ -1791,8 +1787,8 @@ struct socket_test [](tcp_socket& s, char const* data, std::size_t len, std::error_code& ec_out, std::size_t& n_out, bool& done) -> capy::task<> { - auto [ec, n] = co_await s.write_some( - capy::const_buffer(data, len)); + auto [ec, n] = + co_await s.write_some(capy::const_buffer(data, len)); ec_out = ec; n_out = n; done = true; @@ -1802,8 +1798,8 @@ struct socket_test [](tcp_socket& s, char* data, std::size_t len, std::error_code& ec_out, std::size_t& n_out, bool& done) -> capy::task<> { - auto [ec, n] = co_await s.read_some( - capy::mutable_buffer(data, len)); + auto [ec, n] = + co_await s.read_some(capy::mutable_buffer(data, len)); ec_out = ec; n_out = n; done = true; @@ -1817,8 +1813,7 @@ struct socket_test BOOST_TEST(read_done); BOOST_TEST(!read_ec); BOOST_TEST_EQ(read_n, msg.size()); - BOOST_TEST_EQ( - std::string_view(buf, read_n), std::string_view(msg)); + BOOST_TEST_EQ(std::string_view(buf, read_n), std::string_view(msg)); s1.close(); s2.close(); @@ -1832,16 +1827,13 @@ struct socket_test sock.open(tcp::v6()); // IPv6 // Default is v6only=true (kernel default after open_socket sets it) - BOOST_TEST_EQ( - sock.get_option().value(), true); + BOOST_TEST_EQ(sock.get_option().value(), true); sock.set_option(socket_option::v6_only(false)); - BOOST_TEST_EQ( - sock.get_option().value(), false); + BOOST_TEST_EQ(sock.get_option().value(), false); sock.set_option(socket_option::v6_only(true)); - BOOST_TEST_EQ( - sock.get_option().value(), true); + BOOST_TEST_EQ(sock.get_option().value(), true); sock.close(); } @@ -1855,7 +1847,8 @@ struct socket_test acc.open(tcp::v6()); acc.set_option(socket_option::reuse_address(true)); auto ec = acc.bind(endpoint(ipv6_address::any(), 0)); - if (!ec) ec = acc.listen(); + if (!ec) + ec = acc.listen(); BOOST_TEST(!ec); auto port = acc.local_endpoint().port(); @@ -1870,8 +1863,8 @@ struct socket_test auto ex = ioc.get_executor(); capy::run_async(ex)( - [](tcp_acceptor& a, tcp_socket& s, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_acceptor& a, tcp_socket& s, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await a.accept(s); ec_out = ec; done = true; @@ -1880,13 +1873,13 @@ struct socket_test // IPv6 dual-stack socket connects to IPv4 loopback — // connect maps to ::ffff:127.0.0.1 automatically capy::run_async(ex)( - [](tcp_socket& s, endpoint ep, - std::error_code& ec_out, bool& done) -> capy::task<> { + [](tcp_socket& s, endpoint ep, std::error_code& ec_out, + bool& done) -> capy::task<> { auto [ec] = co_await s.connect(ep); ec_out = ec; done = true; - }(s2, endpoint(ipv4_address::loopback(), port), - connect_ec, connect_done)); + }(s2, endpoint(ipv4_address::loopback(), port), connect_ec, + connect_done)); ioc.run(); diff --git a/test/unit/socket_stress.cpp b/test/unit/socket_stress.cpp index 0baace4a..94bf31f2 100644 --- a/test/unit/socket_stress.cpp +++ b/test/unit/socket_stress.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -536,6 +535,7 @@ struct concurrent_ops_stress_test // Create multiple tcp_socket pairs std::vector> pairs; + pairs.reserve(num_pairs); for (int i = 0; i < num_pairs; ++i) { pairs.push_back(make_stress_pair(ioc)); diff --git a/test/unit/stream_tests.hpp b/test/unit/stream_tests.hpp index c784f2ca..66424b11 100644 --- a/test/unit/stream_tests.hpp +++ b/test/unit/stream_tests.hpp @@ -54,6 +54,7 @@ test_echo(S1& a, S2& b, std::string_view test_data = "hello") if (ec2) co_return; BOOST_TEST_EQ(n2, test_data.size()); + // NOLINTNEXTLINE(bugprone-not-null-terminated-result,bugprone-suspicious-stringview-data-usage) BOOST_TEST(std::memcmp(buf.data(), test_data.data(), n2) == 0); } @@ -72,6 +73,7 @@ test_echo(S1& a, S2& b, std::string_view test_data = "hello") if (ec4) co_return; BOOST_TEST_EQ(n4, test_data.size()); + // NOLINTNEXTLINE(bugprone-not-null-terminated-result,bugprone-suspicious-stringview-data-usage) BOOST_TEST(std::memcmp(buf.data(), test_data.data(), n4) == 0); } } diff --git a/test/unit/tcp_server.cpp b/test/unit/tcp_server.cpp index 053f20aa..64acf2c8 100644 --- a/test/unit/tcp_server.cpp +++ b/test/unit/tcp_server.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -125,8 +124,8 @@ struct tcp_server_test port = static_cast(49152 + (attempt * 7) % 16383); acc.open(); acc.set_option(socket_option::reuse_address(true)); - if (!acc.bind(endpoint(ipv4_address::loopback(), port)) - && !acc.listen()) + if (!acc.bind(endpoint(ipv4_address::loopback(), port)) && + !acc.listen()) break; acc.close(); acc = tcp_acceptor(ioc); @@ -260,8 +259,8 @@ struct tcp_server_test port = static_cast(49152 + (attempt * 7) % 16383); acc.open(); acc.set_option(socket_option::reuse_address(true)); - if (!acc.bind(endpoint(ipv4_address::loopback(), port)) - && !acc.listen()) + if (!acc.bind(endpoint(ipv4_address::loopback(), port)) && + !acc.listen()) break; acc.close(); acc = tcp_acceptor(ioc); diff --git a/test/unit/test_utils.hpp b/test/unit/test_utils.hpp index d3058fc1..29c578b7 100644 --- a/test/unit/test_utils.hpp +++ b/test/unit/test_utils.hpp @@ -569,8 +569,10 @@ inline tls_context make_anon_context() { tls_context ctx; - ctx.set_verify_mode(tls_verify_mode::none); - ctx.set_ciphersuites("aNULL:eNULL:@SECLEVEL=0"); + ctx.set_verify_mode( + tls_verify_mode::none); // NOLINT(bugprone-unused-return-value) + ctx.set_ciphersuites( + "aNULL:eNULL:@SECLEVEL=0"); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -579,9 +581,14 @@ inline tls_context make_server_context() { tls_context ctx; - ctx.use_certificate(server_cert_pem, tls_file_format::pem); - ctx.use_private_key(server_key_pem, tls_file_format::pem); - ctx.set_verify_mode(tls_verify_mode::none); + ctx.use_certificate( + server_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + server_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::none); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -590,8 +597,10 @@ inline tls_context make_client_context() { tls_context ctx; - ctx.add_certificate_authority(ca_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -600,8 +609,10 @@ inline tls_context make_wrong_ca_context() { tls_context ctx; - ctx.add_certificate_authority(wrong_ca_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + wrong_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -610,7 +621,8 @@ inline tls_context make_verify_no_cert_context() { tls_context ctx; - ctx.set_verify_mode(tls_verify_mode::require_peer); + ctx.set_verify_mode( + tls_verify_mode::require_peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -636,7 +648,8 @@ make_contexts(context_mode mode) case context_mode::shared_cert: { auto ctx = make_server_context(); - ctx.add_certificate_authority(ca_cert_pem); + ctx.add_certificate_authority( + ca_cert_pem); // NOLINT(bugprone-unused-return-value) return {ctx, ctx}; } case context_mode::separate_cert: @@ -1161,9 +1174,14 @@ inline tls_context make_chain_server_context() { tls_context ctx; - ctx.use_certificate(chain_server_cert_pem, tls_file_format::pem); - ctx.use_private_key(chain_server_key_pem, tls_file_format::pem); - ctx.set_verify_mode(tls_verify_mode::none); + ctx.use_certificate( + chain_server_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + chain_server_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::none); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1176,9 +1194,13 @@ make_fullchain_server_context() { tls_context ctx; // use_certificate_chain expects entity cert followed by intermediate(s) - ctx.use_certificate_chain(server_fullchain_pem); - ctx.use_private_key(chain_server_key_pem, tls_file_format::pem); - ctx.set_verify_mode(tls_verify_mode::none); + ctx.use_certificate_chain( + server_fullchain_pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + chain_server_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::none); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1188,8 +1210,10 @@ inline tls_context make_rootonly_client_context() { tls_context ctx; - ctx.add_certificate_authority(root_ca_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + root_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1199,9 +1223,12 @@ make_chain_client_context() { tls_context ctx; // Trust both root and intermediate CA for chain verification - ctx.add_certificate_authority(root_ca_cert_pem); - ctx.add_certificate_authority(intermediate_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + root_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.add_certificate_authority( + intermediate_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1211,8 +1238,12 @@ inline tls_context make_expired_server_context() { tls_context ctx; - ctx.use_certificate(expired_cert_pem, tls_file_format::pem); - ctx.use_private_key(expired_key_pem, tls_file_format::pem); + ctx.use_certificate( + expired_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + expired_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1223,8 +1254,10 @@ make_expired_client_context() { tls_context ctx; // Trust the expired cert as its own CA (self-signed) - ctx.add_certificate_authority(expired_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + expired_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1233,9 +1266,14 @@ inline tls_context make_wrong_host_server_context() { tls_context ctx; - ctx.use_certificate(wrong_host_cert_pem, tls_file_format::pem); - ctx.use_private_key(wrong_host_key_pem, tls_file_format::pem); - ctx.set_verify_mode(tls_verify_mode::none); + ctx.use_certificate( + wrong_host_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + wrong_host_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::none); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1244,12 +1282,19 @@ inline tls_context make_mtls_client_context() { tls_context ctx; - ctx.use_certificate(client_cert_pem, tls_file_format::pem); - ctx.use_private_key(client_key_pem, tls_file_format::pem); + ctx.use_certificate( + client_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + client_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) // Trust both root and intermediate CA for chain verification - ctx.add_certificate_authority(root_ca_cert_pem); - ctx.add_certificate_authority(intermediate_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + root_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.add_certificate_authority( + intermediate_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1258,12 +1303,19 @@ inline tls_context make_mtls_server_context() { tls_context ctx; - ctx.use_certificate(chain_server_cert_pem, tls_file_format::pem); - ctx.use_private_key(chain_server_key_pem, tls_file_format::pem); + ctx.use_certificate( + chain_server_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + chain_server_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) // Trust both root and intermediate CA for chain verification - ctx.add_certificate_authority(root_ca_cert_pem); - ctx.add_certificate_authority(intermediate_cert_pem); - ctx.set_verify_mode(tls_verify_mode::require_peer); + ctx.add_certificate_authority( + root_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.add_certificate_authority( + intermediate_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::require_peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1272,8 +1324,10 @@ inline tls_context make_untrusted_ca_client_context() { tls_context ctx; - ctx.add_certificate_authority(untrusted_ca_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + untrusted_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1285,12 +1339,19 @@ make_invalid_mtls_client_context() { tls_context ctx; // Use the self-signed server cert as client cert - server won't trust it - ctx.use_certificate(server_cert_pem, tls_file_format::pem); - ctx.use_private_key(server_key_pem, tls_file_format::pem); + ctx.use_certificate( + server_cert_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) + ctx.use_private_key( + server_key_pem, + tls_file_format::pem); // NOLINT(bugprone-unused-return-value) // Trust the chain CAs so we can verify server - ctx.add_certificate_authority(root_ca_cert_pem); - ctx.add_certificate_authority(intermediate_cert_pem); - ctx.set_verify_mode(tls_verify_mode::peer); + ctx.add_certificate_authority( + root_ca_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.add_certificate_authority( + intermediate_cert_pem); // NOLINT(bugprone-unused-return-value) + ctx.set_verify_mode( + tls_verify_mode::peer); // NOLINT(bugprone-unused-return-value) return ctx; } @@ -1611,7 +1672,7 @@ run_stop_token_write_test( bool write_got_error = false; // Large buffer to fill socket buffer and cause blocking - std::vector large_buf(1024 * 1024, 'X'); + std::vector large_buf(std::size_t{1024} * 1024, 'X'); // Failsafe timeout - 2000ms allows headroom for CI with coverage instrumentation timer failsafe(ioc); diff --git a/test/unit/timer.cpp b/test/unit/timer.cpp index 0e6bc9c7..cd6e06b2 100644 --- a/test/unit/timer.cpp +++ b/test/unit/timer.cpp @@ -936,7 +936,10 @@ struct timer_test struct guard { bool& flag_; - ~guard() { flag_ = true; } + ~guard() + { + flag_ = true; + } }; guard g{destroyed_flag}; started_flag = true; @@ -974,7 +977,10 @@ struct timer_test struct guard { int& c_; - ~guard() { ++c_; } + ~guard() + { + ++c_; + } }; guard g{counter}; auto [ec] = co_await t_ref.wait(); diff --git a/test/unit/tls_stream_stress.cpp b/test/unit/tls_stream_stress.cpp index 05b509c0..503a6e77 100644 --- a/test/unit/tls_stream_stress.cpp +++ b/test/unit/tls_stream_stress.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -419,7 +418,7 @@ namespace { struct openssl_stress_factory { - auto operator()(tcp_socket& s, tls_context ctx) const + auto operator()(tcp_socket& s, tls_context const& ctx) const { return openssl_stream(&s, ctx); } @@ -458,7 +457,7 @@ namespace { struct wolfssl_stress_factory { - auto operator()(tcp_socket& s, tls_context ctx) const + auto operator()(tcp_socket& s, tls_context const& ctx) const { return wolfssl_stream(&s, ctx); } diff --git a/test/unit/tls_stream_tests.hpp b/test/unit/tls_stream_tests.hpp index 65c8de5f..ec44d04d 100644 --- a/test/unit/tls_stream_tests.hpp +++ b/test/unit/tls_stream_tests.hpp @@ -77,8 +77,8 @@ testHandshakeFuse(StreamFactory make_stream) BOOST_TEST(!client_ec); BOOST_TEST(!server_ec); - m1.close(); - m2.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) + m2.close(); // NOLINT(bugprone-unused-return-value) co_return; }); } @@ -154,8 +154,8 @@ testReadWriteFuse(StreamFactory make_stream) capy::run_async(ioc.get_executor())(server_task()); ioc.run(); - m1.close(); - m2.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) + m2.close(); // NOLINT(bugprone-unused-return-value) co_return; }); } @@ -216,7 +216,7 @@ testShutdownFuse(StreamFactory make_stream) capy::run_async(ioc.get_executor())(server_task()); ioc.run(); - m1.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) co_return; }); } @@ -260,7 +260,7 @@ testFailureCases(StreamFactory make_stream) { auto client_ctx = make_client_context(); auto server_ctx = make_anon_context(); - server_ctx.set_ciphersuites(""); + server_ctx.set_ciphersuites(""); // NOLINT(bugprone-unused-return-value) run_tls_test_fail( ioc, client_ctx, server_ctx, make_stream, make_stream); ioc.restart(); @@ -577,8 +577,8 @@ testReset(StreamFactory make_stream, std::array const& modes) // Round 2 do_round("hello2"); - m1.close(); - m2.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) + m2.close(); // NOLINT(bugprone-unused-return-value) } } @@ -666,8 +666,8 @@ testResetViaHandshake( // Round 2 do_round("round2"); - m1.close(); - m2.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) + m2.close(); // NOLINT(bugprone-unused-return-value) } } @@ -755,8 +755,8 @@ testResetFuse(StreamFactory make_stream) BOOST_TEST(!sec); } - m1.close(); - m2.close(); + m1.close(); // NOLINT(bugprone-unused-return-value) + m2.close(); // NOLINT(bugprone-unused-return-value) }); } } diff --git a/test/unit/wolfssl_stream.cpp b/test/unit/wolfssl_stream.cpp index 1e39113d..7b2d338e 100644 --- a/test/unit/wolfssl_stream.cpp +++ b/test/unit/wolfssl_stream.cpp @@ -25,12 +25,12 @@ namespace boost::corosio { // Callable wrapper for passing to test helper templates struct wolfssl_stream_factory { - auto operator()(tcp_socket& s, tls_context ctx) const + auto operator()(tcp_socket& s, tls_context const& ctx) const { return wolfssl_stream(&s, ctx); } - auto operator()(corosio::test::mocket& s, tls_context ctx) const + auto operator()(corosio::test::mocket& s, tls_context const& ctx) const { return wolfssl_stream(&s, ctx); }