diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f42c3a..b7a1a1b 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}) +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) set(CMAKE_CXX_STANDARD 23) include(FetchContent) FetchContent_Declare( - execution - # for local development, use SOURCE_DIR /execution - GIT_REPOSITORY https://github.com/bemanproject/execution - GIT_TAG e9c3032 + execution26 + # for local development, use SOURCE_DIR /execution26 + GIT_REPOSITORY https://github.com/bemanproject/execution26 + GIT_TAG 752882e ) -FetchContent_MakeAvailable(execution) +FetchContent_MakeAvailable(execution26) include(CTest) if(BUILD_TESTING) @@ -28,7 +28,7 @@ if(BUILD_TESTING) enable_testing() endif() -add_subdirectory(src/beman/${TARGET_NAME}) +add_subdirectory(src/beman/net) add_subdirectory(examples) include(GNUInstallDirs) diff --git a/README.md b/README.md index 9166cb5..f53e335 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It is based on [P2762R2](https://wg21.link/P2762R2). Both the proposal and the implementation are in an early state although basic functionality is provided. -`beman.net` builds on top of [`beman.execution`](https://github.com/bemanproject/execution). The +`beman.net` builds on top of [`beman.execution26`](https://github.com/bemanproject/execution26). The implementation should allow multiple ways how to support asynchronous operations although currently the only implemented approach is based on `poll(2)`. Implementations using `kqueue(2)`, `epoll(2)`, diff --git a/docs/cppcon-2024-slides.pdf b/docs/cppcon-2024-slides.pdf index 2fbf8bb..0ab2d48 100644 Binary files a/docs/cppcon-2024-slides.pdf and b/docs/cppcon-2024-slides.pdf differ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6fb0e3c..851c290 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,5 +18,4 @@ 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 5ba1190..c50783a 100644 --- a/examples/client.cpp +++ b/examples/client.cpp @@ -8,7 +8,7 @@ #include "demo_task.hpp" #include "demo_scope.hpp" -namespace ex = ::beman::execution; +namespace ex = ::beman::execution26; namespace net = ::beman::net; // ---------------------------------------------------------------------------- diff --git a/examples/cppcon-2024.cpp b/examples/cppcon-2024.cpp index 55e9a8c..55e3b3d 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::execution; +namespace ex = beman::execution26; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index e1fc67b..9f9b6e4 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::execution::detail::meta::transform< + return ::beman::execution26::detail::meta::transform< demo::detail::into_error_transform::template type, decltype(ex::get_completion_signatures(::std::declval(), env)) @@ -269,7 +269,6 @@ struct demo::when_any_t::state_base , receiver(::std::forward(receiver)) { } - virtual ~state_base() = default; auto complete() -> bool { if (0u == this->done_count++) @@ -387,7 +386,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::execution::detail::product_type< + using states_type = ::beman::execution26::detail::product_type< decltype( demo::ex::connect(::std::declval(), ::std::declval>()) @@ -415,11 +414,11 @@ struct demo::when_any_t::state<::std::index_sequence, Receiver, Value, Err template struct demo::when_any_t::sender { - ::beman::execution::detail::product_type<::std::remove_cvref_t...> sender; + ::beman::execution26::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< + ::beman::execution26::detail::meta::unique< + ::beman::execution26::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 9c04003..43db567 100644 --- a/examples/demo_scope.hpp +++ b/examples/demo_scope.hpp @@ -57,11 +57,11 @@ namespace demo } auto complete() -> void { - scope* slf{this->self}; + scope* self{this->self}; delete this->state; - if (0u == --slf->count) + if (0u == --self->count) { - slf->complete(); + self->complete(); } } auto get_env() const noexcept -> env { return {this->self}; } diff --git a/examples/demo_task.hpp b/examples/demo_task.hpp index b1a160b..8703c39 100644 --- a/examples/demo_task.hpp +++ b/examples/demo_task.hpp @@ -26,7 +26,6 @@ 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; @@ -42,7 +41,6 @@ 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; @@ -116,12 +114,12 @@ namespace demo this->awaiter->handle.resume(); } template - auto set_error(Error&& err) noexcept -> void + auto set_error(Error&& error) noexcept -> void { if constexpr (::std::same_as<::std::decay_t, ::std::exception_ptr>) - this->awaiter->error = err; + this->awaiter->error = error; else - this->awaiter->error = ::std::make_exception_ptr(::std::forward(err)); + this->awaiter->error = ::std::make_exception_ptr(::std::forward(error)); this->awaiter->handle.resume(); } auto set_stopped() noexcept -> void @@ -148,9 +146,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 hndle) -> void + auto await_suspend(::std::coroutine_handle handle) -> void { - this->handle = hndle; + this->handle = handle; ex::start(this->state); } auto await_resume() diff --git a/examples/empty.cpp b/examples/empty.cpp index efd6fcb..9d08594 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::execution; +namespace ex = beman::execution26; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/http-server.cpp b/examples/http-server.cpp index ce6c399..91ef999 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::execution; +namespace ex = beman::execution26; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/milano.cpp b/examples/milano.cpp index 08a2f6e..7315df6 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::execution; +namespace ex = beman::execution26; namespace net = beman::net; using namespace std::chrono_literals; diff --git a/examples/server.cpp b/examples/server.cpp index 534bc27..6d29036 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::execution; +namespace ex = ::beman::execution26; namespace net = ::beman::net; using namespace std::chrono_literals; diff --git a/examples/task.cpp b/examples/task.cpp index 8f57aec..204a3d0 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::execution; +namespace ex = ::beman::execution26; namespace net = ::beman::net; namespace diff --git a/include/beman/net/detail/context_base.hpp b/include/beman/net/detail/context_base.hpp index 9475666..22d3b8a 100644 --- a/include/beman/net/detail/context_base.hpp +++ b/include/beman/net/detail/context_base.hpp @@ -26,7 +26,6 @@ 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 7a09268..73a3754 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::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::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; } namespace beman::net::detail::ex { - using ::beman::execution::completion_signatures; - using ::beman::execution::detail::decayed_tuple; + using ::beman::execution26::completion_signatures; + using ::beman::execution26::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::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_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::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::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::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::sender_in; + using ::beman::execution26::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::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::connect_t; - using ::beman::execution::connect; - using ::beman::execution::start_t; - using ::beman::execution::start; + using ::beman::execution26::connect_t; + using ::beman::execution26::connect; + using ::beman::execution26::start_t; + using ::beman::execution26::start; - 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::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; } // ---------------------------------------------------------------------------- diff --git a/include/beman/net/detail/io_base.hpp b/include/beman/net/detail/io_base.hpp index 019a2d5..da8e402 100644 --- a/include/beman/net/detail/io_base.hpp +++ b/include/beman/net/detail/io_base.hpp @@ -56,7 +56,6 @@ 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 6f552f0..de39221 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 = int(this->d_buffers.size()); + ::std::get<0>(*base).msg_iovlen = 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 = int(this->d_buffers.size()); + ::std::get<0>(*base).msg_iovlen = 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 4c329dd..54068af 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 int(::std::chrono::duration_cast<::std::chrono::milliseconds>(duration).count()); + return ::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(), nfds_t(this->d_poll.size()), timeout)); + int rc(::poll(this->d_poll.data(), 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::size_t(::std::distance(this->d_outstanding.begin(), it))); + this->remove_outstanding(::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) = ::std::size_t(rc); + ::std::get<2>(completion) = 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) = ::std::size_t(rc); + ::std::get<2>(completion) = 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 e04e766..460cdfd 100644 --- a/include/beman/net/detail/sender.hpp +++ b/include/beman/net/detail/sender.hpp @@ -42,7 +42,6 @@ struct beman::net::detail::sender_state_base : d_receiver(::std::forward(r)) { } - virtual ~sender_state_base() = default; virtual auto start() & noexcept -> void = 0; }; @@ -94,7 +93,6 @@ struct beman::net::detail::sender_state , d_state(s) { } - cancel_callback(cancel_callback&&) = default; auto operator()() { if (1 < ++this->d_state->d_outstanding) @@ -155,7 +153,7 @@ struct beman::net::detail::sender_state ); static_assert(not std::same_as); ++this->d_outstanding; - this->d_callback.emplace(token, this); + this->d_callback.emplace(token, cancel_callback(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 ce8b986..503529b 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::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::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; } // ---------------------------------------------------------------------------- diff --git a/src/beman/net/CMakeLists.txt b/src/beman/net/CMakeLists.txt index f67869a..e660764 100644 --- a/src/beman/net/CMakeLists.txt +++ b/src/beman/net/CMakeLists.txt @@ -50,18 +50,16 @@ string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME) install( TARGETS ${TARGET_LIBRARY} - EXPORT ${TARGETS_EXPORT_NAME} + EXPORT ${TARGETS_EXPORT_NAME}1 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::execution) +target_link_libraries(${TARGET_LIBRARY} PUBLIC beman::execution26) -if(FALSE) -install(EXPORT ${TARGETS_EXPORT_NAME} +install(EXPORT ${TARGETS_EXPORT_NAME}1 FILE ${TARGET_LIBRARY}-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_LIBRARY}" NAMESPACE ${TARGET_LIBRARY}:: ) -endif()