From 00c934f3982ca8b65c90f24bd8ff8b17e5fc00b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Mon, 27 Jan 2025 23:29:25 +0000 Subject: [PATCH 1/8] move code to use execution instead of execution26 --- CMakeLists.txt | 14 +-- examples/CMakeLists.txt | 1 + examples/client.cpp | 2 +- examples/cppcon-2024.cpp | 4 +- examples/demo_algorithm.hpp | 11 ++- examples/demo_scope.hpp | 6 +- examples/demo_task.hpp | 12 ++- examples/empty.cpp | 4 +- examples/http-server.cpp | 4 +- examples/milano.cpp | 4 +- examples/server.cpp | 4 +- examples/task.cpp | 4 +- include/beman/net/detail/context_base.hpp | 1 + include/beman/net/detail/execution.hpp | 108 +++++++++++----------- include/beman/net/detail/io_base.hpp | 1 + include/beman/net/detail/operations.hpp | 4 +- include/beman/net/detail/poll_context.hpp | 10 +- include/beman/net/detail/sender.hpp | 4 +- include/beman/net/detail/stop_token.hpp | 12 +-- src/beman/net/CMakeLists.txt | 8 +- 20 files changed, 114 insertions(+), 104 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7a1a1b..4f42c3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,18 +9,18 @@ set(TARGET_NAME net) set(TARGET_PREFIX beman.${TARGET_NAME}) set(TARGET_LIBRARY beman_${TARGET_NAME}) set(TARGET_ALIAS beman::${TARGET_NAME}) -set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}) set(CMAKE_CXX_STANDARD 23) include(FetchContent) FetchContent_Declare( - execution26 - # for local development, use SOURCE_DIR /execution26 - GIT_REPOSITORY https://github.com/bemanproject/execution26 - GIT_TAG 752882e + execution + # for local development, use SOURCE_DIR /execution + GIT_REPOSITORY https://github.com/bemanproject/execution + GIT_TAG e9c3032 ) -FetchContent_MakeAvailable(execution26) +FetchContent_MakeAvailable(execution) include(CTest) if(BUILD_TESTING) @@ -28,7 +28,7 @@ if(BUILD_TESTING) enable_testing() endif() -add_subdirectory(src/beman/net) +add_subdirectory(src/beman/${TARGET_NAME}) add_subdirectory(examples) include(GNUInstallDirs) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 851c290..6fb0e3c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,4 +18,5 @@ foreach(EXAMPLE ${EXAMPLES}) add_executable(${EXAMPLE_TARGET}) target_sources(${EXAMPLE_TARGET} PRIVATE ${EXAMPLE}.cpp) target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${TARGET_LIBRARY}) + target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman::execution) endforeach() diff --git a/examples/client.cpp b/examples/client.cpp index c50783a..5ba1190 100644 --- a/examples/client.cpp +++ b/examples/client.cpp @@ -8,7 +8,7 @@ #include "demo_task.hpp" #include "demo_scope.hpp" -namespace ex = ::beman::execution26; +namespace ex = ::beman::execution; namespace net = ::beman::net; // ---------------------------------------------------------------------------- diff --git a/examples/cppcon-2024.cpp b/examples/cppcon-2024.cpp index 55e3b3d..55e9a8c 100644 --- a/examples/cppcon-2024.cpp +++ b/examples/cppcon-2024.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include +#include #include "demo_algorithm.hpp" #include "demo_error.hpp" #include "demo_scope.hpp" @@ -14,7 +14,7 @@ #include #include -namespace ex = beman::execution26; +namespace ex = beman::execution; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index 9f9b6e4..e1fc67b 100644 --- a/examples/demo_algorithm.hpp +++ b/examples/demo_algorithm.hpp @@ -184,7 +184,7 @@ struct demo::into_error_t::sender using sender_concept = ex::sender_t; template auto get_completion_signatures(Env const& env) const { - return ::beman::execution26::detail::meta::transform< + return ::beman::execution::detail::meta::transform< demo::detail::into_error_transform::template type, decltype(ex::get_completion_signatures(::std::declval(), env)) @@ -269,6 +269,7 @@ struct demo::when_any_t::state_base , receiver(::std::forward(receiver)) { } + virtual ~state_base() = default; auto complete() -> bool { if (0u == this->done_count++) @@ -386,7 +387,7 @@ struct demo::when_any_t::state<::std::index_sequence, Receiver, Value, Err template <::std::size_t J> using receiver_type = when_any_t::receiver; using operation_state_concept = ex::operation_state_t; - using states_type = ::beman::execution26::detail::product_type< + using states_type = ::beman::execution::detail::product_type< decltype( demo::ex::connect(::std::declval(), ::std::declval>()) @@ -414,11 +415,11 @@ struct demo::when_any_t::state<::std::index_sequence, Receiver, Value, Err template struct demo::when_any_t::sender { - ::beman::execution26::detail::product_type<::std::remove_cvref_t...> sender; + ::beman::execution::detail::product_type<::std::remove_cvref_t...> sender; using sender_concept = ex::sender_t; using completion_signatures = - ::beman::execution26::detail::meta::unique< - ::beman::execution26::detail::meta::combine< + ::beman::execution::detail::meta::unique< + ::beman::execution::detail::meta::combine< decltype(ex::get_completion_signatures(::std::declval(), ex::empty_env{}))... > diff --git a/examples/demo_scope.hpp b/examples/demo_scope.hpp index 43db567..9c04003 100644 --- a/examples/demo_scope.hpp +++ b/examples/demo_scope.hpp @@ -57,11 +57,11 @@ namespace demo } auto complete() -> void { - scope* self{this->self}; + scope* slf{this->self}; delete this->state; - if (0u == --self->count) + if (0u == --slf->count) { - self->complete(); + slf->complete(); } } auto get_env() const noexcept -> env { return {this->self}; } diff --git a/examples/demo_task.hpp b/examples/demo_task.hpp index 8703c39..b1a160b 100644 --- a/examples/demo_task.hpp +++ b/examples/demo_task.hpp @@ -26,6 +26,7 @@ namespace demo struct task_state_base { ::std::optional task_result; + virtual ~task_state_base() = default; virtual auto complete_value() -> void = 0; virtual auto complete_error(::std::exception_ptr) -> void = 0; virtual auto complete_stopped() -> void = 0; @@ -41,6 +42,7 @@ namespace demo template <> struct task_state_base { + virtual ~task_state_base() = default; virtual auto complete_value() -> void = 0; virtual auto complete_error(::std::exception_ptr) -> void = 0; virtual auto complete_stopped() -> void = 0; @@ -114,12 +116,12 @@ namespace demo this->awaiter->handle.resume(); } template - auto set_error(Error&& error) noexcept -> void + auto set_error(Error&& err) noexcept -> void { if constexpr (::std::same_as<::std::decay_t, ::std::exception_ptr>) - this->awaiter->error = error; + this->awaiter->error = err; else - this->awaiter->error = ::std::make_exception_ptr(::std::forward(error)); + this->awaiter->error = ::std::make_exception_ptr(::std::forward(err)); this->awaiter->handle.resume(); } auto set_stopped() noexcept -> void @@ -146,9 +148,9 @@ namespace demo auto stop() -> void; auto get_token() const noexcept -> ex::inplace_stop_token; constexpr auto await_ready() const noexcept -> bool { return false; } - auto await_suspend(::std::coroutine_handle handle) -> void + auto await_suspend(::std::coroutine_handle hndle) -> void { - this->handle = handle; + this->handle = hndle; ex::start(this->state); } auto await_resume() diff --git a/examples/empty.cpp b/examples/empty.cpp index 9d08594..efd6fcb 100644 --- a/examples/empty.cpp +++ b/examples/empty.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include +#include #include "demo_algorithm.hpp" #include "demo_error.hpp" #include "demo_scope.hpp" @@ -14,7 +14,7 @@ #include #include -namespace ex = beman::execution26; +namespace ex = beman::execution; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/http-server.cpp b/examples/http-server.cpp index 91ef999..ce6c399 100644 --- a/examples/http-server.cpp +++ b/examples/http-server.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include +#include #include "demo_algorithm.hpp" #include "demo_scope.hpp" #include "demo_task.hpp" @@ -13,7 +13,7 @@ #include #include -namespace ex = beman::execution26; +namespace ex = beman::execution; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/milano.cpp b/examples/milano.cpp index 7315df6..08a2f6e 100644 --- a/examples/milano.cpp +++ b/examples/milano.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include +#include #include "demo_algorithm.hpp" #include "demo_error.hpp" #include "demo_scope.hpp" @@ -14,7 +14,7 @@ #include #include -namespace ex = beman::execution26; +namespace ex = beman::execution; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/server.cpp b/examples/server.cpp index 6d29036..534bc27 100644 --- a/examples/server.cpp +++ b/examples/server.cpp @@ -4,13 +4,13 @@ #include #include #include -#include +#include #include #include "demo_algorithm.hpp" #include "demo_scope.hpp" #include "demo_task.hpp" -namespace ex = ::beman::execution26; +namespace ex = ::beman::execution; namespace net = ::beman::net; using namespace std::chrono_literals; diff --git a/examples/task.cpp b/examples/task.cpp index 204a3d0..8f57aec 100644 --- a/examples/task.cpp +++ b/examples/task.cpp @@ -4,12 +4,12 @@ #include #include #include -#include +#include #include #include "demo_scope.hpp" #include "demo_task.hpp" -namespace ex = ::beman::execution26; +namespace ex = ::beman::execution; namespace net = ::beman::net; namespace diff --git a/include/beman/net/detail/context_base.hpp b/include/beman/net/detail/context_base.hpp index 22d3b8a..9475666 100644 --- a/include/beman/net/detail/context_base.hpp +++ b/include/beman/net/detail/context_base.hpp @@ -26,6 +26,7 @@ struct beman::net::detail::context_base struct task { task* next; + virtual ~task() = default; virtual auto complete() -> void = 0; }; diff --git a/include/beman/net/detail/execution.hpp b/include/beman/net/detail/execution.hpp index 73a3754..7a09268 100644 --- a/include/beman/net/detail/execution.hpp +++ b/include/beman/net/detail/execution.hpp @@ -4,76 +4,76 @@ #ifndef INCLUDED_INCLUDE_BEMAN_NET_DETAIL_EXECUTION #define INCLUDED_INCLUDE_BEMAN_NET_DETAIL_EXECUTION -#include +#include // ---------------------------------------------------------------------------- namespace beman::net::detail::ex::detail { - using ::beman::execution26::detail::type_list; - using ::beman::execution26::detail::variant_or_empty; - using ::beman::execution26::detail::meta::combine; - using ::beman::execution26::detail::meta::filter; - using ::beman::execution26::detail::meta::unique; - using ::beman::execution26::detail::meta::transform; - using ::beman::execution26::detail::sender_adaptor; - using ::beman::execution26::detail::forward_like; + using ::beman::execution::detail::type_list; + using ::beman::execution::detail::variant_or_empty; + using ::beman::execution::detail::meta::combine; + using ::beman::execution::detail::meta::filter; + using ::beman::execution::detail::meta::unique; + using ::beman::execution::detail::meta::transform; + using ::beman::execution::detail::sender_adaptor; + using ::beman::execution::detail::forward_like; } namespace beman::net::detail::ex { - using ::beman::execution26::completion_signatures; - using ::beman::execution26::detail::decayed_tuple; + using ::beman::execution::completion_signatures; + using ::beman::execution::detail::decayed_tuple; - using ::beman::execution26::get_env; - using ::beman::execution26::empty_env; - using ::beman::execution26::env_of_t; - using ::beman::execution26::value_types_of_t; - using ::beman::execution26::error_types_of_t; + using ::beman::execution::get_env; + using ::beman::execution::empty_env; + using ::beman::execution::env_of_t; + using ::beman::execution::value_types_of_t; + using ::beman::execution::error_types_of_t; - using ::beman::execution26::get_stop_token_t; - using ::beman::execution26::get_stop_token; - using ::beman::execution26::get_completion_signatures_t; - using ::beman::execution26::get_completion_signatures; - using ::beman::execution26::get_completion_scheduler_t; - using ::beman::execution26::get_completion_scheduler; - using ::beman::execution26::get_delegation_scheduler_t; - using ::beman::execution26::get_delegation_scheduler; - using ::beman::execution26::get_scheduler_t; - using ::beman::execution26::get_scheduler; + using ::beman::execution::get_stop_token_t; + using ::beman::execution::get_stop_token; + using ::beman::execution::get_completion_signatures_t; + using ::beman::execution::get_completion_signatures; + using ::beman::execution::get_completion_scheduler_t; + using ::beman::execution::get_completion_scheduler; + using ::beman::execution::get_delegation_scheduler_t; + using ::beman::execution::get_delegation_scheduler; + using ::beman::execution::get_scheduler_t; + using ::beman::execution::get_scheduler; - using ::beman::execution26::operation_state_t; - using ::beman::execution26::operation_state; - using ::beman::execution26::receiver_t; - using ::beman::execution26::receiver; - using ::beman::execution26::sender_t; - using ::beman::execution26::sender; - using ::beman::execution26::scheduler_t; - using ::beman::execution26::scheduler; + using ::beman::execution::operation_state_t; + using ::beman::execution::operation_state; + using ::beman::execution::receiver_t; + using ::beman::execution::receiver; + using ::beman::execution::sender_t; + using ::beman::execution::sender; + using ::beman::execution::scheduler_t; + using ::beman::execution::scheduler; - using ::beman::execution26::sender_in; + using ::beman::execution::sender_in; - using ::beman::execution26::set_error_t; - using ::beman::execution26::set_error; - using ::beman::execution26::set_stopped_t; - using ::beman::execution26::set_stopped; - using ::beman::execution26::set_value_t; - using ::beman::execution26::set_value; + using ::beman::execution::set_error_t; + using ::beman::execution::set_error; + using ::beman::execution::set_stopped_t; + using ::beman::execution::set_stopped; + using ::beman::execution::set_value_t; + using ::beman::execution::set_value; - using ::beman::execution26::connect_t; - using ::beman::execution26::connect; - using ::beman::execution26::start_t; - using ::beman::execution26::start; + using ::beman::execution::connect_t; + using ::beman::execution::connect; + using ::beman::execution::start_t; + using ::beman::execution::start; - using ::beman::execution26::read_env; - using ::beman::execution26::detail::write_env; - using ::beman::execution26::just; - using ::beman::execution26::just_error; - using ::beman::execution26::just_stopped; - using ::beman::execution26::then; - using ::beman::execution26::upon_error; - using ::beman::execution26::upon_stopped; - using ::beman::execution26::sync_wait; + using ::beman::execution::read_env; + using ::beman::execution::detail::write_env; + using ::beman::execution::just; + using ::beman::execution::just_error; + using ::beman::execution::just_stopped; + using ::beman::execution::then; + using ::beman::execution::upon_error; + using ::beman::execution::upon_stopped; + using ::beman::execution::sync_wait; } // ---------------------------------------------------------------------------- diff --git a/include/beman/net/detail/io_base.hpp b/include/beman/net/detail/io_base.hpp index da8e402..019a2d5 100644 --- a/include/beman/net/detail/io_base.hpp +++ b/include/beman/net/detail/io_base.hpp @@ -56,6 +56,7 @@ struct beman::net::detail::io_base extra_t extra{nullptr, +[](void*){}}; io_base(::beman::net::detail::socket_id id, int event): id(id), event(event) {} + virtual ~io_base() = default; virtual auto complete() -> void = 0; virtual auto error(::std::error_code) -> void = 0; diff --git a/include/beman/net/detail/operations.hpp b/include/beman/net/detail/operations.hpp index de39221..6f552f0 100644 --- a/include/beman/net/detail/operations.hpp +++ b/include/beman/net/detail/operations.hpp @@ -131,7 +131,7 @@ struct beman::net::detail::send_desc auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base).msg_iov = this->d_buffers.data(); - ::std::get<0>(*base).msg_iovlen = this->d_buffers.size(); + ::std::get<0>(*base).msg_iovlen = int(this->d_buffers.size()); return this->d_stream.get_scheduler().send(base); } }; @@ -188,7 +188,7 @@ struct beman::net::detail::receive_desc auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base).msg_iov = this->d_buffers.data(); - ::std::get<0>(*base).msg_iovlen = this->d_buffers.size(); + ::std::get<0>(*base).msg_iovlen = int(this->d_buffers.size()); return this->d_stream.get_scheduler().receive(base); } }; diff --git a/include/beman/net/detail/poll_context.hpp b/include/beman/net/detail/poll_context.hpp index 54068af..4c329dd 100644 --- a/include/beman/net/detail/poll_context.hpp +++ b/include/beman/net/detail/poll_context.hpp @@ -139,7 +139,7 @@ struct beman::net::detail::poll_context final } auto to_milliseconds(auto duration) -> int { - return ::std::chrono::duration_cast<::std::chrono::milliseconds>(duration).count(); + return int(::std::chrono::duration_cast<::std::chrono::milliseconds>(duration).count()); } auto run_one() -> ::std::size_t override final { @@ -158,7 +158,7 @@ struct beman::net::detail::poll_context final { auto next_time{this->d_timeouts.value_or(now)}; int timeout{now == next_time? -1: this->to_milliseconds(next_time - now)}; - int rc(::poll(this->d_poll.data(), this->d_poll.size(), timeout)); + int rc(::poll(this->d_poll.data(), nfds_t(this->d_poll.size()), timeout)); if (rc < 0) { switch (errno) @@ -215,7 +215,7 @@ struct beman::net::detail::poll_context final auto it(::std::find(this->d_outstanding.begin(), this->d_outstanding.end(), op)); if (it != this->d_outstanding.end()) { - this->remove_outstanding(::std::distance(this->d_outstanding.begin(), it)); + this->remove_outstanding(std::size_t(::std::distance(this->d_outstanding.begin(), it))); op->cancel(); cancel_op->cancel(); } @@ -337,7 +337,7 @@ struct beman::net::detail::poll_context final ::std::get<1>(completion))}; if (0 <= rc) { - ::std::get<2>(completion) = rc; + ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; } @@ -376,7 +376,7 @@ struct beman::net::detail::poll_context final ::std::get<1>(completion))}; if (0 <= rc) { - ::std::get<2>(completion) = rc; + ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; } diff --git a/include/beman/net/detail/sender.hpp b/include/beman/net/detail/sender.hpp index 460cdfd..e04e766 100644 --- a/include/beman/net/detail/sender.hpp +++ b/include/beman/net/detail/sender.hpp @@ -42,6 +42,7 @@ struct beman::net::detail::sender_state_base : d_receiver(::std::forward(r)) { } + virtual ~sender_state_base() = default; virtual auto start() & noexcept -> void = 0; }; @@ -93,6 +94,7 @@ struct beman::net::detail::sender_state , d_state(s) { } + cancel_callback(cancel_callback&&) = default; auto operator()() { if (1 < ++this->d_state->d_outstanding) @@ -153,7 +155,7 @@ struct beman::net::detail::sender_state ); static_assert(not std::same_as); ++this->d_outstanding; - this->d_callback.emplace(token, cancel_callback(this)); + this->d_callback.emplace(token, this); if (token.stop_requested()) { this->d_callback.reset(); diff --git a/include/beman/net/detail/stop_token.hpp b/include/beman/net/detail/stop_token.hpp index 503529b..ce8b986 100644 --- a/include/beman/net/detail/stop_token.hpp +++ b/include/beman/net/detail/stop_token.hpp @@ -4,17 +4,17 @@ #ifndef INCLUDED_BEMAN_NET_DETAIL_STOP_TOKEN #define INCLUDED_BEMAN_NET_DETAIL_STOP_TOKEN -#include +#include // ---------------------------------------------------------------------------- namespace beman::net::detail::ex { - using ::beman::execution26::never_stop_token; - using ::beman::execution26::inplace_stop_source; - using ::beman::execution26::inplace_stop_token; - using ::beman::execution26::stop_callback_for_t; - using ::beman::execution26::detail::stoppable_callback_for; + using ::beman::execution::never_stop_token; + using ::beman::execution::inplace_stop_source; + using ::beman::execution::inplace_stop_token; + using ::beman::execution::stop_callback_for_t; + using ::beman::execution::detail::stoppable_callback_for; } // ---------------------------------------------------------------------------- diff --git a/src/beman/net/CMakeLists.txt b/src/beman/net/CMakeLists.txt index e660764..f67869a 100644 --- a/src/beman/net/CMakeLists.txt +++ b/src/beman/net/CMakeLists.txt @@ -50,16 +50,18 @@ string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME) install( TARGETS ${TARGET_LIBRARY} - EXPORT ${TARGETS_EXPORT_NAME}1 + EXPORT ${TARGETS_EXPORT_NAME} ARCHIVE DESTINATION lib/$ FILE_SET ${TARGET_LIBRARY}_public_headers FILE_SET ${TARGET_LIBRARY}_detail_headers ) target_include_directories(${TARGET_LIBRARY} PUBLIC $) -target_link_libraries(${TARGET_LIBRARY} PUBLIC beman::execution26) +target_link_libraries(${TARGET_LIBRARY} PUBLIC beman::execution) -install(EXPORT ${TARGETS_EXPORT_NAME}1 +if(FALSE) +install(EXPORT ${TARGETS_EXPORT_NAME} FILE ${TARGET_LIBRARY}-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_LIBRARY}" NAMESPACE ${TARGET_LIBRARY}:: ) +endif() From bcc94b57fd5dcef5389d4878aed60a6ed51c8c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Mon, 27 Jan 2025 23:33:41 +0000 Subject: [PATCH 2/8] address some Linux problems (disabling TSAN for now) --- .github/workflows/linux.yml | 2 +- include/beman/net/detail/sorted_list.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 97a5e9c..2846072 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - sanitizer: [none, asan, usan, tsan] + sanitizer: [none, asan, usan] compiler: [g++] steps: - uses: actions/checkout@v4 diff --git a/include/beman/net/detail/sorted_list.hpp b/include/beman/net/detail/sorted_list.hpp index 8cdfed6..963555d 100644 --- a/include/beman/net/detail/sorted_list.hpp +++ b/include/beman/net/detail/sorted_list.hpp @@ -11,7 +11,7 @@ namespace beman::net::detail { - template , typename = decltype([](T* n){ return n->value; })> + template , typename = decltype([](T* node){ return node->value; })> struct sorted_list; } From 179b6386e9aca5b7832bb07525732ccb2cf3517f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Mon, 27 Jan 2025 23:57:30 +0000 Subject: [PATCH 3/8] fixed a bunch of warnings reported --- examples/demo_algorithm.hpp | 61 ++++------- examples/demo_scope.hpp | 3 +- examples/demo_task.hpp | 16 +-- examples/http-server.cpp | 20 ++-- include/beman/net/detail/context_base.hpp | 2 +- include/beman/net/detail/execution.hpp | 106 +++++++++--------- include/beman/net/detail/internet.hpp | 10 +- include/beman/net/detail/io_base.hpp | 9 +- include/beman/net/detail/poll_context.hpp | 126 +++++++++++----------- include/beman/net/detail/sender.hpp | 2 +- include/beman/net/detail/sorted_list.hpp | 4 +- include/beman/net/detail/stop_token.hpp | 10 +- 12 files changed, 166 insertions(+), 203 deletions(-) diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index e1fc67b..fd3fcb0 100644 --- a/examples/demo_algorithm.hpp +++ b/examples/demo_algorithm.hpp @@ -184,11 +184,9 @@ struct demo::into_error_t::sender using sender_concept = ex::sender_t; template auto get_completion_signatures(Env const& env) const { - return ::beman::execution::detail::meta::transform< - demo::detail::into_error_transform::template type, - decltype(ex::get_completion_signatures(::std::declval(), - env)) - >(); + return ::beman::execution::detail::meta::transform::template type, + decltype(ex::get_completion_signatures( + ::std::declval(), env))>(); } template @@ -208,10 +206,9 @@ struct demo::into_error_t::sender }; template -inline auto demo::into_error_t::operator()(Sender&& sender, Fun&& fun) const - -> demo::into_error_t::sender<::std::remove_cvref_t, ::std::remove_cvref_t> -{ - return {::std::forward(sender), ::std::forward(fun)}; +inline auto demo::into_error_t::operator()(Sender&& sndr, Fun&& fun) const + -> demo::into_error_t::sender<::std::remove_cvref_t, ::std::remove_cvref_t> { + return {::std::forward(sndr), ::std::forward(fun)}; } template @@ -264,11 +261,7 @@ struct demo::when_any_t::state_base ::demo::ex::inplace_stop_source source{}; template - state_base(std::size_t total, R&& receiver) - : total(total) - , receiver(::std::forward(receiver)) - { - } + state_base(std::size_t tot, R&& rcvr) : total(tot), receiver(::std::forward(rcvr)) {} virtual ~state_base() = default; auto complete() -> bool { @@ -387,22 +380,15 @@ struct demo::when_any_t::state<::std::index_sequence, Receiver, Value, Err template <::std::size_t J> using receiver_type = when_any_t::receiver; using operation_state_concept = ex::operation_state_t; - using states_type = ::beman::execution::detail::product_type< - decltype( - demo::ex::connect(::std::declval(), - ::std::declval>()) - )...>; + using states_type = ::beman::execution::detail::product_type(), ::std::declval>()))...>; states_type states; - + template - state(R&& receiver, P&& s) - : state_value(sizeof...(Sender), ::std::forward(receiver)) - , states{demo::ex::connect( - ::beman::net::detail::ex::detail::forward_like

(s.template get()), - receiver_type{this} - )...} - { - } + state(R&& rcvr, P&& s) + : state_value(sizeof...(Sender), ::std::forward(rcvr)), + states{demo::ex::connect(::beman::net::detail::ex::detail::forward_like

(s.template get()), + receiver_type{this})...} {} state(state&&) = delete; auto start() & noexcept -> void { @@ -417,14 +403,9 @@ struct demo::when_any_t::sender { ::beman::execution::detail::product_type<::std::remove_cvref_t...> sender; using sender_concept = ex::sender_t; - using completion_signatures = - ::beman::execution::detail::meta::unique< - ::beman::execution::detail::meta::combine< - decltype(ex::get_completion_signatures(::std::declval(), - ex::empty_env{}))... - > - >; - + using completion_signatures = ::beman::execution::detail::meta::unique<::beman::execution::detail::meta::combine< + decltype(ex::get_completion_signatures(::std::declval(), ex::empty_env{}))...>>; + template auto connect(Receiver&& receiver) && -> state<::std::index_sequence_for, @@ -450,11 +431,9 @@ struct demo::when_any_t::sender }; template - requires (0u < sizeof...(Sender)) -inline auto demo::when_any_t::operator()(Sender&&...sender) const - -> ::demo::when_any_t::sender -{ - return {::std::forward(sender)...}; + requires(0u < sizeof...(Sender)) +inline auto demo::when_any_t::operator()(Sender&&... sndr) const -> ::demo::when_any_t::sender { + return {::std::forward(sndr)...}; } // ---------------------------------------------------------------------------- diff --git a/examples/demo_scope.hpp b/examples/demo_scope.hpp index 9c04003..9cdc5b7 100644 --- a/examples/demo_scope.hpp +++ b/examples/demo_scope.hpp @@ -59,8 +59,7 @@ namespace demo { scope* slf{this->self}; delete this->state; - if (0u == --slf->count) - { + if (0u == --slf->count) { slf->complete(); } } diff --git a/examples/demo_task.hpp b/examples/demo_task.hpp index b1a160b..f696ce5 100644 --- a/examples/demo_task.hpp +++ b/examples/demo_task.hpp @@ -26,7 +26,7 @@ namespace demo struct task_state_base { ::std::optional task_result; - virtual ~task_state_base() = default; + virtual ~task_state_base() = default; virtual auto complete_value() -> void = 0; virtual auto complete_error(::std::exception_ptr) -> void = 0; virtual auto complete_stopped() -> void = 0; @@ -42,7 +42,7 @@ namespace demo template <> struct task_state_base { - virtual ~task_state_base() = default; + virtual ~task_state_base() = default; virtual auto complete_value() -> void = 0; virtual auto complete_error(::std::exception_ptr) -> void = 0; virtual auto complete_stopped() -> void = 0; @@ -116,8 +116,7 @@ namespace demo this->awaiter->handle.resume(); } template - auto set_error(Error&& err) noexcept -> void - { + auto set_error(Error&& err) noexcept -> void { if constexpr (::std::same_as<::std::decay_t, ::std::exception_ptr>) this->awaiter->error = err; else @@ -148,8 +147,7 @@ namespace demo auto stop() -> void; auto get_token() const noexcept -> ex::inplace_stop_token; constexpr auto await_ready() const noexcept -> bool { return false; } - auto await_suspend(::std::coroutine_handle hndle) -> void - { + auto await_suspend(::std::coroutine_handle hndle) -> void { this->handle = hndle; ex::start(this->state); } @@ -228,11 +226,7 @@ namespace demo ::std::optional callback; template - state(unique_handle handle, R&& receiver) - : handle(::std::move(handle)) - , receiver(::std::forward(receiver)) - { - } + state(unique_handle hndl, R&& rcvr) : handle(::std::move(hndl)), receiver(::std::forward(rcvr)) {} auto start() & noexcept -> void { diff --git a/examples/http-server.cpp b/examples/http-server.cpp index ce6c399..32b9a2d 100644 --- a/examples/http-server.cpp +++ b/examples/http-server.cpp @@ -87,15 +87,17 @@ auto main() -> int net::ip::tcp::acceptor server(context, ep); std::cout << "listening on " << ep << "\n"; - scope.spawn(std::invoke([](auto scheduler, auto& scope, auto& server) -> demo::task<> { - while (true) - { - auto[stream, address] = co_await net::async_accept(server); - std::cout << "received connection from " << address << "\n"; - scope.spawn(make_client(scheduler, std::move(stream))); - - } - }, context.get_scheduler(), scope, server)); + scope.spawn(std::invoke( + [](auto scheduler, auto& scp, auto& svr) -> demo::task<> { + while (true) { + auto [stream, address] = co_await net::async_accept(svr); + std::cout << "received connection from " << address << "\n"; + scp.spawn(make_client(scheduler, std::move(stream))); + } + }, + context.get_scheduler(), + scope, + server)); context.run(); } diff --git a/include/beman/net/detail/context_base.hpp b/include/beman/net/detail/context_base.hpp index 9475666..500bd3b 100644 --- a/include/beman/net/detail/context_base.hpp +++ b/include/beman/net/detail/context_base.hpp @@ -26,7 +26,7 @@ struct beman::net::detail::context_base struct task { task* next; - virtual ~task() = default; + virtual ~task() = default; virtual auto complete() -> void = 0; }; diff --git a/include/beman/net/detail/execution.hpp b/include/beman/net/detail/execution.hpp index 7a09268..6fbad6b 100644 --- a/include/beman/net/detail/execution.hpp +++ b/include/beman/net/detail/execution.hpp @@ -10,70 +10,70 @@ namespace beman::net::detail::ex::detail { - using ::beman::execution::detail::type_list; - using ::beman::execution::detail::variant_or_empty; - using ::beman::execution::detail::meta::combine; - using ::beman::execution::detail::meta::filter; - using ::beman::execution::detail::meta::unique; - using ::beman::execution::detail::meta::transform; - using ::beman::execution::detail::sender_adaptor; - using ::beman::execution::detail::forward_like; +using ::beman::execution::detail::forward_like; +using ::beman::execution::detail::sender_adaptor; +using ::beman::execution::detail::type_list; +using ::beman::execution::detail::variant_or_empty; +using ::beman::execution::detail::meta::combine; +using ::beman::execution::detail::meta::filter; +using ::beman::execution::detail::meta::transform; +using ::beman::execution::detail::meta::unique; } namespace beman::net::detail::ex { - using ::beman::execution::completion_signatures; - using ::beman::execution::detail::decayed_tuple; +using ::beman::execution::completion_signatures; +using ::beman::execution::detail::decayed_tuple; - using ::beman::execution::get_env; - using ::beman::execution::empty_env; - using ::beman::execution::env_of_t; - using ::beman::execution::value_types_of_t; - using ::beman::execution::error_types_of_t; +using ::beman::execution::empty_env; +using ::beman::execution::env_of_t; +using ::beman::execution::error_types_of_t; +using ::beman::execution::get_env; +using ::beman::execution::value_types_of_t; - using ::beman::execution::get_stop_token_t; - using ::beman::execution::get_stop_token; - using ::beman::execution::get_completion_signatures_t; - using ::beman::execution::get_completion_signatures; - using ::beman::execution::get_completion_scheduler_t; - using ::beman::execution::get_completion_scheduler; - using ::beman::execution::get_delegation_scheduler_t; - using ::beman::execution::get_delegation_scheduler; - using ::beman::execution::get_scheduler_t; - using ::beman::execution::get_scheduler; +using ::beman::execution::get_completion_scheduler; +using ::beman::execution::get_completion_scheduler_t; +using ::beman::execution::get_completion_signatures; +using ::beman::execution::get_completion_signatures_t; +using ::beman::execution::get_delegation_scheduler; +using ::beman::execution::get_delegation_scheduler_t; +using ::beman::execution::get_scheduler; +using ::beman::execution::get_scheduler_t; +using ::beman::execution::get_stop_token; +using ::beman::execution::get_stop_token_t; - using ::beman::execution::operation_state_t; - using ::beman::execution::operation_state; - using ::beman::execution::receiver_t; - using ::beman::execution::receiver; - using ::beman::execution::sender_t; - using ::beman::execution::sender; - using ::beman::execution::scheduler_t; - using ::beman::execution::scheduler; +using ::beman::execution::operation_state; +using ::beman::execution::operation_state_t; +using ::beman::execution::receiver; +using ::beman::execution::receiver_t; +using ::beman::execution::scheduler; +using ::beman::execution::scheduler_t; +using ::beman::execution::sender; +using ::beman::execution::sender_t; - using ::beman::execution::sender_in; +using ::beman::execution::sender_in; - using ::beman::execution::set_error_t; - using ::beman::execution::set_error; - using ::beman::execution::set_stopped_t; - using ::beman::execution::set_stopped; - using ::beman::execution::set_value_t; - using ::beman::execution::set_value; +using ::beman::execution::set_error; +using ::beman::execution::set_error_t; +using ::beman::execution::set_stopped; +using ::beman::execution::set_stopped_t; +using ::beman::execution::set_value; +using ::beman::execution::set_value_t; - using ::beman::execution::connect_t; - using ::beman::execution::connect; - using ::beman::execution::start_t; - using ::beman::execution::start; +using ::beman::execution::connect; +using ::beman::execution::connect_t; +using ::beman::execution::start; +using ::beman::execution::start_t; - using ::beman::execution::read_env; - using ::beman::execution::detail::write_env; - using ::beman::execution::just; - using ::beman::execution::just_error; - using ::beman::execution::just_stopped; - using ::beman::execution::then; - using ::beman::execution::upon_error; - using ::beman::execution::upon_stopped; - using ::beman::execution::sync_wait; +using ::beman::execution::just; +using ::beman::execution::just_error; +using ::beman::execution::just_stopped; +using ::beman::execution::read_env; +using ::beman::execution::sync_wait; +using ::beman::execution::then; +using ::beman::execution::upon_error; +using ::beman::execution::upon_stopped; +using ::beman::execution::detail::write_env; } // ---------------------------------------------------------------------------- diff --git a/include/beman/net/detail/internet.hpp b/include/beman/net/detail/internet.hpp index 0f82b62..6f336dd 100644 --- a/include/beman/net/detail/internet.hpp +++ b/include/beman/net/detail/internet.hpp @@ -231,15 +231,13 @@ class beman::net::ip::address this->d_address.storage.ss_family = PF_INET; } constexpr address(address const&) noexcept = default; - /*-dk:TODO constexpr*/ address(::beman::net::ip::address_v4 const& address) noexcept - { + /*-dk:TODO constexpr*/ address(const ::beman::net::ip::address_v4& addr) noexcept { this->d_address.inet.sin_family = AF_INET; - this->d_address.inet.sin_addr.s_addr = htonl(address.to_uint()); + this->d_address.inet.sin_addr.s_addr = htonl(addr.to_uint()); this->d_address.inet.sin_port = 0xFF'FF; } - /*-dk:TODO constexpr*/ address(::beman::net::ip::address_v6 const& address) noexcept - { - address.get_address(this->d_address.inet6, 0xFF'FF); + /*-dk:TODO constexpr*/ address(const ::beman::net::ip::address_v6& addr) noexcept { + addr.get_address(this->d_address.inet6, 0xFF'FF); } auto operator=(address const&) noexcept -> address& = default; diff --git a/include/beman/net/detail/io_base.hpp b/include/beman/net/detail/io_base.hpp index 019a2d5..42a9a5e 100644 --- a/include/beman/net/detail/io_base.hpp +++ b/include/beman/net/detail/io_base.hpp @@ -55,7 +55,7 @@ struct beman::net::detail::io_base work_t work; extra_t extra{nullptr, +[](void*){}}; - io_base(::beman::net::detail::socket_id id, int event): id(id), event(event) {} + io_base(::beman::net::detail::socket_id i, int ev) : id(i), event(ev) {} virtual ~io_base() = default; virtual auto complete() -> void = 0; @@ -73,11 +73,8 @@ struct beman::net::detail::io_operation , Data { template - io_operation(::beman::net::detail::socket_id id, int event, D&& a = Data()) - : io_base(id, event) - , Data(::std::forward(a)) - { - } + io_operation(::beman::net::detail::socket_id i, int ev, D&& a = Data()) + : io_base(i, ev), Data(::std::forward(a)) {} }; diff --git a/include/beman/net/detail/poll_context.hpp b/include/beman/net/detail/poll_context.hpp index 4c329dd..f4e28c2 100644 --- a/include/beman/net/detail/poll_context.hpp +++ b/include/beman/net/detail/poll_context.hpp @@ -111,9 +111,9 @@ struct beman::net::detail::poll_context final { if (this->d_tasks) { - auto* task{this->d_tasks}; - this->d_tasks = task->next; - task->complete(); + auto* tsk{this->d_tasks}; + this->d_tasks = tsk->next; + tsk->complete(); return 1u; } return 0u; @@ -158,7 +158,13 @@ struct beman::net::detail::poll_context final { auto next_time{this->d_timeouts.value_or(now)}; int timeout{now == next_time? -1: this->to_milliseconds(next_time - now)}; - int rc(::poll(this->d_poll.data(), nfds_t(this->d_poll.size()), timeout)); + nfds_t sz([](auto s) { + if constexpr (::std::same_as) + return s; + else + return nfds_t(s); + }(this->d_poll.size())); + int rc(::poll(this->d_poll.data(), sz, timeout)); if (rc < 0) { switch (errno) @@ -229,10 +235,9 @@ struct beman::net::detail::poll_context final std::cerr << "ERROR: poll_context::cancel(): entity not cancelled!\n"; } } - auto schedule(::beman::net::detail::context_base::task* task) -> void override - { - task->next = this->d_tasks; - this->d_tasks = task; + auto schedule(::beman::net::detail::context_base::task* tsk) -> void override { + tsk->next = this->d_tasks; + this->d_tasks = tsk; } auto accept(::beman::net::detail::context_base::accept_operation* completion) -> ::beman::net::detail::submit_result override final @@ -242,15 +247,15 @@ struct beman::net::detail::poll_context final ::beman::net::detail::io_base* comp) { auto id{comp->id}; - auto& completion(*static_cast(comp)); + auto& cmp(*static_cast(comp)); while (true) { - int rc = ::accept(ctxt.native_handle(id), ::std::get<0>(completion).data(), &::std::get<1>(completion)); + int rc = ::accept(ctxt.native_handle(id), ::std::get<0>(cmp).data(), &::std::get<1>(cmp)); if (0 <= rc) { - ::std::get<2>(completion) = ctxt.make_socket(rc); - completion.complete(); + ::std::get<2>(cmp) = ctxt.make_socket(rc); + cmp.complete(); return ::beman::net::detail::submit_result::ready; } else @@ -258,7 +263,7 @@ struct beman::net::detail::poll_context final switch (errno) { default: - completion.error(::std::error_code(errno, ::std::system_category())); + cmp.error(::std::error_code(errno, ::std::system_category())); return ::beman::net::detail::submit_result::error; case EINTR: break; @@ -296,26 +301,23 @@ struct beman::net::detail::poll_context final } op->context = this; - op->work = [](::beman::net::detail::context_base& ctxt, - ::beman::net::detail::io_base* op) - { - auto handle{ctxt.native_handle(op->id)}; + op->work = [](::beman::net::detail::context_base& ctxt, ::beman::net::detail::io_base* o) { + auto hndl{ctxt.native_handle(o->id)}; int error{}; ::socklen_t len{sizeof(error)}; - if (-1 == ::getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &len)) - { - op->error(::std::error_code(errno, ::std::system_category())); + if (-1 == ::getsockopt(hndl, SOL_SOCKET, SO_ERROR, &error, &len)) { + o->error(::std::error_code(errno, ::std::system_category())); return ::beman::net::detail::submit_result::error; } if (0 == error) { - op->complete(); + o->complete(); return ::beman::net::detail::submit_result::ready; } else { - op->error(::std::error_code(error, ::std::system_category())); + o->error(::std::error_code(error, ::std::system_category())); return ::beman::net::detail::submit_result::error; } }; @@ -326,36 +328,32 @@ struct beman::net::detail::poll_context final -> ::beman::net::detail::submit_result override { op->context = this; - op->work = [](::beman::net::detail::context_base& ctxt, - ::beman::net::detail::io_base* op) - { - auto& completion(*static_cast(op)); + op->work = [](::beman::net::detail::context_base& ctxt, ::beman::net::detail::io_base* o) { + auto& completion(*static_cast(o)); while (true) { - auto rc{::recvmsg(ctxt.native_handle(op->id), - &::std::get<0>(completion), - ::std::get<1>(completion))}; + auto rc{::recvmsg(ctxt.native_handle(o->id), &::std::get<0>(completion), ::std::get<1>(completion))}; if (0 <= rc) { ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; } - else switch (errno) - { - default: - completion.error(::std::error_code(errno, ::std::system_category())); - return ::beman::net::detail::submit_result::error; - case ECONNRESET: - case EPIPE: - ::std::get<2>(completion) = 0u; - completion.complete(); - return ::beman::net::detail::submit_result::ready; - case EINTR: - break; - case EWOULDBLOCK: - return ::beman::net::detail::submit_result::submit; - } + else + switch (errno) { + default: + completion.error(::std::error_code(errno, ::std::system_category())); + return ::beman::net::detail::submit_result::error; + case ECONNRESET: + case EPIPE: + ::std::get<2>(completion) = 0u; + completion.complete(); + return ::beman::net::detail::submit_result::ready; + case EINTR: + break; + case EWOULDBLOCK: + return ::beman::net::detail::submit_result::submit; + } } }; return this->add_outstanding(op); @@ -364,37 +362,33 @@ struct beman::net::detail::poll_context final -> ::beman::net::detail::submit_result override { op->context = this; - op->work = [](::beman::net::detail::context_base& ctxt, - ::beman::net::detail::io_base* op) - { - auto& completion(*static_cast(op)); + op->work = [](::beman::net::detail::context_base& ctxt, ::beman::net::detail::io_base* o) { + auto& completion(*static_cast(o)); while (true) { - auto rc{::sendmsg(ctxt.native_handle(op->id), - &::std::get<0>(completion), - ::std::get<1>(completion))}; + auto rc{::sendmsg(ctxt.native_handle(o->id), &::std::get<0>(completion), ::std::get<1>(completion))}; if (0 <= rc) { ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; } - else switch (errno) - { - default: - completion.error(::std::error_code(errno, ::std::system_category())); - return ::beman::net::detail::submit_result::error; - case ECONNRESET: - case EPIPE: - ::std::get<2>(completion) = 0u; - completion.complete(); - return ::beman::net::detail::submit_result::ready; - case EINTR: - break; - case EWOULDBLOCK: - return ::beman::net::detail::submit_result::submit; - } + else + switch (errno) { + default: + completion.error(::std::error_code(errno, ::std::system_category())); + return ::beman::net::detail::submit_result::error; + case ECONNRESET: + case EPIPE: + ::std::get<2>(completion) = 0u; + completion.complete(); + return ::beman::net::detail::submit_result::ready; + case EINTR: + break; + case EWOULDBLOCK: + return ::beman::net::detail::submit_result::submit; + } } }; return this->add_outstanding(op); diff --git a/include/beman/net/detail/sender.hpp b/include/beman/net/detail/sender.hpp index e04e766..406adbe 100644 --- a/include/beman/net/detail/sender.hpp +++ b/include/beman/net/detail/sender.hpp @@ -42,7 +42,7 @@ struct beman::net::detail::sender_state_base : d_receiver(::std::forward(r)) { } - virtual ~sender_state_base() = default; + virtual ~sender_state_base() = default; virtual auto start() & noexcept -> void = 0; }; diff --git a/include/beman/net/detail/sorted_list.hpp b/include/beman/net/detail/sorted_list.hpp index 963555d..0219c4a 100644 --- a/include/beman/net/detail/sorted_list.hpp +++ b/include/beman/net/detail/sorted_list.hpp @@ -11,8 +11,8 @@ namespace beman::net::detail { - template , typename = decltype([](T* node){ return node->value; })> - struct sorted_list; +template , typename = decltype([](T* node) { return node->value; })> +struct sorted_list; } // ---------------------------------------------------------------------------- diff --git a/include/beman/net/detail/stop_token.hpp b/include/beman/net/detail/stop_token.hpp index ce8b986..f4cdf74 100644 --- a/include/beman/net/detail/stop_token.hpp +++ b/include/beman/net/detail/stop_token.hpp @@ -10,11 +10,11 @@ namespace beman::net::detail::ex { - using ::beman::execution::never_stop_token; - using ::beman::execution::inplace_stop_source; - using ::beman::execution::inplace_stop_token; - using ::beman::execution::stop_callback_for_t; - using ::beman::execution::detail::stoppable_callback_for; +using ::beman::execution::inplace_stop_source; +using ::beman::execution::inplace_stop_token; +using ::beman::execution::never_stop_token; +using ::beman::execution::stop_callback_for_t; +using ::beman::execution::detail::stoppable_callback_for; } // ---------------------------------------------------------------------------- From caa120ae9a30ec742d9bb0a5f8ed5897303db5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 28 Jan 2025 00:04:29 +0000 Subject: [PATCH 4/8] addressed another gcc warning --- include/beman/net/detail/operations.hpp | 16 ++++++++++++++-- include/beman/net/detail/poll_context.hpp | 6 ++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/beman/net/detail/operations.hpp b/include/beman/net/detail/operations.hpp index 6f552f0..80596ec 100644 --- a/include/beman/net/detail/operations.hpp +++ b/include/beman/net/detail/operations.hpp @@ -131,7 +131,13 @@ struct beman::net::detail::send_desc auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base).msg_iov = this->d_buffers.data(); - ::std::get<0>(*base).msg_iovlen = int(this->d_buffers.size()); + ::std::get<0>(*base).msg_iovlen = [](auto x) { + using iovlen = decltype(msghdr().msg_iovlen); + if constexpr (std::same_as) + return x; + else + return iovlen(x); + }(this->d_buffers.size()); return this->d_stream.get_scheduler().send(base); } }; @@ -188,7 +194,13 @@ struct beman::net::detail::receive_desc auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base).msg_iov = this->d_buffers.data(); - ::std::get<0>(*base).msg_iovlen = int(this->d_buffers.size()); + ::std::get<0>(*base).msg_iovlen = [](auto x) { + using iovlen = decltype(msghdr().msg_iovlen); + if constexpr (std::same_as) + return x; + else + return iovlen(x); + }(this->d_buffers.size()); return this->d_stream.get_scheduler().receive(base); } }; diff --git a/include/beman/net/detail/poll_context.hpp b/include/beman/net/detail/poll_context.hpp index f4e28c2..1daa336 100644 --- a/include/beman/net/detail/poll_context.hpp +++ b/include/beman/net/detail/poll_context.hpp @@ -338,8 +338,7 @@ struct beman::net::detail::poll_context final ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; - } - else + } else switch (errno) { default: completion.error(::std::error_code(errno, ::std::system_category())); @@ -373,8 +372,7 @@ struct beman::net::detail::poll_context final ::std::get<2>(completion) = ::std::size_t(rc); completion.complete(); return ::beman::net::detail::submit_result::ready; - } - else + } else switch (errno) { default: completion.error(::std::error_code(errno, ::std::system_category())); From b4510f504e9af2489bbf8c82ea2901cd8e455f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 28 Jan 2025 00:07:27 +0000 Subject: [PATCH 5/8] more shadowed variables --- examples/demo_algorithm.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index fd3fcb0..a9fc6a7 100644 --- a/examples/demo_algorithm.hpp +++ b/examples/demo_algorithm.hpp @@ -290,8 +290,8 @@ struct demo::when_any_t::state_value ::std::optional value{}; template - state_value(::std::size_t total, R&& receiver) - : state_base{total, ::std::forward(receiver)} + state_value(::std::size_t tot, R&& rcvr) + : state_base{tot, ::std::forward(rcvr)} { } From b7abe0fc7682a3d7b68d8f10ceaa01fa73e39f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 28 Jan 2025 00:11:01 +0000 Subject: [PATCH 6/8] more shadowed variables --- examples/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/server.cpp b/examples/server.cpp index 534bc27..8d85d62 100644 --- a/examples/server.cpp +++ b/examples/server.cpp @@ -64,9 +64,9 @@ int main() demo::scope scope; net::io_context context; - scope.spawn(std::invoke([](auto& scope, auto& context)->demo::task<>{ + scope.spawn(std::invoke([](auto& scp, auto& ctxt)->demo::task<>{ net::ip::tcp::endpoint endpoint(net::ip::address_v4::any(), 12345); - net::ip::tcp::acceptor acceptor(context, endpoint); + net::ip::tcp::acceptor acceptor(ctxt, endpoint); while (true) { @@ -75,14 +75,14 @@ int main() auto[stream, ep] = co_await demo::when_any( net::async_accept(acceptor), demo::into_error( - net::resume_after(context.get_scheduler(), 1s), + net::resume_after(ctxt.get_scheduler(), 1s), [](auto&&...){ return ::std::error_code(); } ) ); ::std::cout << "when_any is done\n"; std::cout << "ep=" << ep << "\n"; - scope.spawn(make_client(std::move(stream))); + scp.spawn(make_client(std::move(stream))); } catch(...) { From 08452d310bd8eb490e2bb825a8df70c9a5675e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 28 Jan 2025 00:19:54 +0000 Subject: [PATCH 7/8] more shadowed variables --- examples/client.cpp | 98 ++++++++++++++++++------------------- examples/cppcon-2024.cpp | 19 ++++--- examples/demo_algorithm.hpp | 5 +- examples/milano.cpp | 10 ++-- examples/server.cpp | 42 +++++++--------- 5 files changed, 85 insertions(+), 89 deletions(-) diff --git a/examples/client.cpp b/examples/client.cpp index 5ba1190..00867af 100644 --- a/examples/client.cpp +++ b/examples/client.cpp @@ -23,14 +23,15 @@ auto main() -> int demo::scope scope; scope.spawn(std::invoke( - [](auto& context) -> demo::task<> { + [](auto& ctxt) -> demo::task<> { on_exit msg("5s timer - done"); - co_await net::resume_after(context.get_scheduler(), 5s); + co_await net::resume_after(ctxt.get_scheduler(), 5s); std::cout << "5s timer expired\n"; - } , context) - //net::resume_after(context.get_scheduler(), 5s) - //| ex::then([]{ std::cout << "5s timer expired\n"; }) - //| ex::upon_stopped([]{ std::cout << "5s timer got cancelled\n"; }) + }, + context) + // net::resume_after(context.get_scheduler(), 5s) + //| ex::then([]{ std::cout << "5s timer expired\n"; }) + //| ex::upon_stopped([]{ std::cout << "5s timer got cancelled\n"; }) ); auto stop = [&scope, &context]{ @@ -43,55 +44,54 @@ auto main() -> int }; scope.spawn(std::invoke( - [](auto& context, auto stop)->demo::task<> { + [](auto& ctxt, auto stp) -> demo::task<> { on_exit msg("timer task (enqueing stop task) - done"); - co_await net::resume_after(context.get_scheduler(), 1s); - stop(); - }, context, stop)); + co_await net::resume_after(ctxt.get_scheduler(), 1s); + stp(); + }, + context, + stop)); - scope.spawn(std::invoke([](auto& context)->demo::task<> { - on_exit msg("connecting client - done"); - net::ip::tcp::endpoint ep(net::ip::address_v4::loopback(), 12345); - net::ip::tcp::socket client(context, ep); - - if (false) for (int i{}; i < 5; ++i) - { - std::cout << "i=" << i << "\n"; - co_await net::resume_after(context.get_scheduler(), 1s); - } + scope.spawn(std::invoke( + [](auto& ctxt) -> demo::task<> { + on_exit msg("connecting client - done"); + net::ip::tcp::endpoint ep(net::ip::address_v4::loopback(), 12345); + net::ip::tcp::socket client(ctxt, ep); - if (not co_await (net::async_connect(client) - | ex::then([](auto&&...){ return true; }) - | ex::upon_error([](auto e){ - if constexpr (std::same_as) - { - std::error_code f = e; - std::cout << "error_code=" << f.message() << "\n"; + if (false) + for (int i{}; i < 5; ++i) { + std::cout << "i=" << i << "\n"; + co_await net::resume_after(ctxt.get_scheduler(), 1s); } - else if constexpr (std::same_as) - ; - else - static_assert(std::same_as); - return false; - }))) - { - co_return; - } - std::cout << "connected\n"; - char message[] = "hello, world\n"; - auto b = net::buffer(message); - if (0 < co_await net::async_send(client, b)) { - char buffer[20]; - while (auto size = co_await net::async_receive(client, net::buffer(buffer))) - { - std::string_view response(buffer, size); - std::cout << "received='" << response << "'\n"; - //if (response.find('\n') != response.npos) - // break; + if (not co_await (net::async_connect(client) | ex::then([](auto&&...) { return true; }) | + ex::upon_error([](auto e) { + if constexpr (std::same_as) { + std::error_code f = e; + std::cout << "error_code=" << f.message() << "\n"; + } else if constexpr (std::same_as) + ; + else + static_assert(std::same_as); + return false; + }))) { + co_return; } - } - }, context) + + std::cout << "connected\n"; + char message[] = "hello, world\n"; + auto b = net::buffer(message); + if (0 < co_await net::async_send(client, b)) { + char buffer[20]; + while (auto size = co_await net::async_receive(client, net::buffer(buffer))) { + std::string_view response(buffer, size); + std::cout << "received='" << response << "'\n"; + // if (response.find('\n') != response.npos) + // break; + } + } + }, + context) #if 0 | ex::upon_error([](std::exception_ptr ex) { try { diff --git a/examples/cppcon-2024.cpp b/examples/cppcon-2024.cpp index 55e9a8c..64d6dea 100644 --- a/examples/cppcon-2024.cpp +++ b/examples/cppcon-2024.cpp @@ -95,14 +95,17 @@ auto main() -> int net::ip::tcp::endpoint endpoint(net::ip::address_v4::any(), 12345); net::ip::tcp::acceptor acceptor(context, endpoint); - scope.spawn(std::invoke([](auto scheduler, auto& scope, auto& acceptor)->demo::task<> { - while (true) - { - auto[stream, address] = co_await net::async_accept(acceptor); - std::cout << "received client: " << address << "\n"; - scope.spawn(make_client_handler(scheduler, std::move(stream))); - } - }, context.get_scheduler(), scope, acceptor)); + scope.spawn(std::invoke( + [](auto scheduler, auto& scp, auto& acc) -> demo::task<> { + while (true) { + auto [stream, address] = co_await net::async_accept(acc); + std::cout << "received client: " << address << "\n"; + scp.spawn(make_client_handler(scheduler, std::move(stream))); + } + }, + context.get_scheduler(), + scope, + acceptor)); context.run(); } diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index a9fc6a7..02437db 100644 --- a/examples/demo_algorithm.hpp +++ b/examples/demo_algorithm.hpp @@ -290,10 +290,7 @@ struct demo::when_any_t::state_value ::std::optional value{}; template - state_value(::std::size_t tot, R&& rcvr) - : state_base{tot, ::std::forward(rcvr)} - { - } + state_value(::std::size_t tot, R&& rcvr) : state_base{tot, ::std::forward(rcvr)} {} auto notify_done() -> void override { diff --git a/examples/milano.cpp b/examples/milano.cpp index 08a2f6e..cc350df 100644 --- a/examples/milano.cpp +++ b/examples/milano.cpp @@ -81,13 +81,13 @@ auto main() -> int demo::scope scope; net::io_context context; - scope.spawn([](auto& context, auto& scope)->demo::task<> { + scope.spawn([](auto& ctxt, auto& scp) -> demo::task<> { net::ip::tcp::endpoint ep(net::ip::address_v4::any(), 12345); - net::ip::tcp::acceptor acceptor(context, ep); + net::ip::tcp::acceptor acceptor(ctxt, ep); while (true) { - auto[client, address] = co_await net::async_accept(acceptor); - std::cout << "received a connection from " << address << "\n"; - scope.spawn(run_client(std::move(client), context.get_scheduler())); + auto [client, address] = co_await net::async_accept(acceptor); + std::cout << "received a connection from " << address << "\n"; + scp.spawn(run_client(std::move(client), ctxt.get_scheduler())); } }(context, scope)); diff --git a/examples/server.cpp b/examples/server.cpp index 8d85d62..05c5317 100644 --- a/examples/server.cpp +++ b/examples/server.cpp @@ -64,32 +64,28 @@ int main() demo::scope scope; net::io_context context; - scope.spawn(std::invoke([](auto& scp, auto& ctxt)->demo::task<>{ - net::ip::tcp::endpoint endpoint(net::ip::address_v4::any(), 12345); - net::ip::tcp::acceptor acceptor(ctxt, endpoint); + scope.spawn(std::invoke( + [](auto& scp, auto& ctxt) -> demo::task<> { + net::ip::tcp::endpoint endpoint(net::ip::address_v4::any(), 12345); + net::ip::tcp::acceptor acceptor(ctxt, endpoint); - while (true) - { - try - { - auto[stream, ep] = co_await demo::when_any( - net::async_accept(acceptor), - demo::into_error( - net::resume_after(ctxt.get_scheduler(), 1s), - [](auto&&...){ return ::std::error_code(); } - ) - ); - ::std::cout << "when_any is done\n"; + while (true) { + try { + auto [stream, ep] = + co_await demo::when_any(net::async_accept(acceptor), + demo::into_error(net::resume_after(ctxt.get_scheduler(), 1s), + [](auto&&...) { return ::std::error_code(); })); + ::std::cout << "when_any is done\n"; - std::cout << "ep=" << ep << "\n"; - scp.spawn(make_client(std::move(stream))); + std::cout << "ep=" << ep << "\n"; + scp.spawn(make_client(std::move(stream))); + } catch (...) { + std::cout << "timer fired\n"; + } } - catch(...) - { - std::cout << "timer fired\n"; - } - } - }, scope, context)); + }, + scope, + context)); context.run(); } From f746b241f2112158602e7c7964fd68e0dc027e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Tue, 28 Jan 2025 00:22:29 +0000 Subject: [PATCH 8/8] and another shadowed variable --- examples/task.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/task.cpp b/examples/task.cpp index 8f57aec..d966aae 100644 --- a/examples/task.cpp +++ b/examples/task.cpp @@ -22,7 +22,7 @@ int main(int ac, char*[]) { try { - auto res{ex::sync_wait(::std::invoke([](int ac)-> demo::task + auto res{ex::sync_wait(::std::invoke([](int argc)-> demo::task { int i = co_await ex::just(17); std::cout << "i=" << i << "\n"; @@ -36,9 +36,9 @@ int main(int ac, char*[]) { std::cout << "error=" << e.value << "\n"; } - if (ac == 2) + if (argc == 2) co_await ex::just_stopped(); - if (ac == 3) + if (argc == 3) throw error{42}; co_return result{17}; }, ac))};