diff --git a/CMakeLists.txt b/CMakeLists.txt index fe0d9c8..b7a1a1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ # cmake-format: on cmake_minimum_required(VERSION 3.23) -project(beman_net29 VERSION 0.0.0 LANGUAGES CXX) -set(TARGET_NAME net29) +project(beman_net VERSION 0.0.0 LANGUAGES CXX) +set(TARGET_NAME net) set(TARGET_PREFIX beman.${TARGET_NAME}) set(TARGET_LIBRARY beman_${TARGET_NAME}) set(TARGET_ALIAS beman::${TARGET_NAME}) @@ -24,11 +24,11 @@ FetchContent_MakeAvailable(execution26) include(CTest) if(BUILD_TESTING) - add_subdirectory(src/beman/${TARGET_NAME}/tests) + add_subdirectory(tests/beman/${TARGET_NAME}) enable_testing() endif() -add_subdirectory(src/beman/net29) +add_subdirectory(src/beman/net) add_subdirectory(examples) include(GNUInstallDirs) diff --git a/Makefile b/Makefile index 5f6fcd9..c3738e3 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ ce: @mkdir -p $(BUILD) bin/mk-compiler-explorer.py $(BUILD) -SOURCE_CMAKELISTS = src/beman/net29/CMakeLists.txt +SOURCE_CMAKELISTS = src/beman/net/CMakeLists.txt update: bin/update-cmake-headers.py $(SOURCE_CMAKELISTS) diff --git a/README.md b/README.md index 7665a01..f53e335 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# beman.net29: Senders For Network Operations +# beman.net: Senders For Network Operations -`beman.net29` provides senders for asynchronous network operations. +`beman.net` provides senders for asynchronous network operations. 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.net29` builds on top of [`beman.execution26`](https://github.com/bemanproject/execution26). 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)`, @@ -22,7 +22,7 @@ possible use various libraries for asynchronous operations like ## Help Welcome! There are plenty of things which need to be done. Some of these -are listed in the [issues section](https://github.com/bemanproject/net29/issues). +are listed in the [issues section](https://github.com/bemanproject/net/issues). Other contributions are, of course, also welcome. Aside from contributing code the project welcomes reports on usage experience, code reviews, defect reports, features requests, etc. There are plenty contribution opportunities. @@ -45,7 +45,7 @@ use something akin to the current interface. ## Building Currently, the interfaces are entirely implemented in headers, i.e., -there isn't a library needed. However, using the library `libbeman_net29` +there isn't a library needed. However, using the library `libbeman_net` should make the relevant paths to headers available. The following instructions build the library and the examples (required libraries are obtained and build using these instructions): @@ -57,4 +57,4 @@ The code is working on MacOS building with the system's [`clang`](https://clang.llvm.org/) and recent [`gcc`](http://gcc.gnu.org/). It should hopefully also work on Linux but it isn't tested, yet. Windows isn't supported, yet, primarily because the relevant class -for the networking operations are different. \ No newline at end of file +for the networking operations are different. diff --git a/examples/client.cpp b/examples/client.cpp index 23cdbd4..c50783a 100644 --- a/examples/client.cpp +++ b/examples/client.cpp @@ -1,7 +1,7 @@ // examples/client.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include #include @@ -9,7 +9,7 @@ #include "demo_scope.hpp" namespace ex = ::beman::execution26; -namespace net = ::beman::net29; +namespace net = ::beman::net; // ---------------------------------------------------------------------------- diff --git a/examples/cppcon-2024.cpp b/examples/cppcon-2024.cpp index d1fc6fb..55e3b3d 100644 --- a/examples/cppcon-2024.cpp +++ b/examples/cppcon-2024.cpp @@ -1,7 +1,7 @@ // examples/http-server.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include "demo_algorithm.hpp" #include "demo_error.hpp" @@ -15,7 +15,7 @@ #include namespace ex = beman::execution26; -namespace net = beman::net29; +namespace net = beman::net; using namespace std::chrono_literals; // ---------------------------------------------------------------------------- diff --git a/examples/demo_algorithm.hpp b/examples/demo_algorithm.hpp index 21ac005..9f9b6e4 100644 --- a/examples/demo_algorithm.hpp +++ b/examples/demo_algorithm.hpp @@ -16,7 +16,7 @@ # pragma clang diagnostic ignored "-Wmissing-braces" #endif -#include +#include #include #include #include @@ -32,7 +32,7 @@ namespace demo { - namespace ex = ::beman::net29::detail::ex; + namespace ex = ::beman::net::detail::ex; } namespace demo::detail @@ -225,9 +225,9 @@ inline auto demo::into_error_t::operator()(Fun&& fun) const #if 202202L <= __cpp_lib_expected inline auto demo::into_expected_t::operator()() const { - return beman::net29::detail::ex::detail::sender_adaptor{*this}; + return beman::net::detail::ex::detail::sender_adaptor{*this}; } -template +template inline auto demo::into_expected_t::operator()(Sender&& s) const { using value_type = ex::value_types_of_t< @@ -238,12 +238,12 @@ inline auto demo::into_expected_t::operator()(Sender&& s) const >; using error_type = ex::error_types_of_t; return ::std::forward(s) - | beman::net29::detail::ex::then([](A&&... a)noexcept{ + | beman::net::detail::ex::then([](A&&... a)noexcept{ return std::expected( ::std::in_place_t{}, ::std::forward(a)... ); }) - | beman::net29::detail::ex::upon_error([](E&& e)noexcept{ + | beman::net::detail::ex::upon_error([](E&& e)noexcept{ return std::expected( ::std::unexpect_t{}, ::std::forward(e) ); @@ -397,7 +397,7 @@ struct demo::when_any_t::state<::std::index_sequence, Receiver, Value, Err state(R&& receiver, P&& s) : state_value(sizeof...(Sender), ::std::forward(receiver)) , states{demo::ex::connect( - ::beman::net29::detail::ex::detail::forward_like

(s.template get()), + ::beman::net::detail::ex::detail::forward_like

(s.template get()), receiver_type{this} )...} { diff --git a/examples/demo_scope.hpp b/examples/demo_scope.hpp index 9d19b47..43db567 100644 --- a/examples/demo_scope.hpp +++ b/examples/demo_scope.hpp @@ -4,7 +4,7 @@ #ifndef INCLUDED_EXAMPLES_DEMO_SCOPE #define INCLUDED_EXAMPLES_DEMO_SCOPE -#include +#include #include #include #include @@ -13,7 +13,7 @@ namespace demo { - namespace ex = ::beman::net29::detail::ex; + namespace ex = ::beman::net::detail::ex; class scope { diff --git a/examples/demo_task.hpp b/examples/demo_task.hpp index 89fe958..8703c39 100644 --- a/examples/demo_task.hpp +++ b/examples/demo_task.hpp @@ -4,7 +4,7 @@ #ifndef INCLUDED_EXAMPLES_DEMO_TASK #define INCLUDED_EXAMPLES_DEMO_TASK -#include +#include #include #include #include @@ -20,7 +20,7 @@ namespace demo { - namespace ex = ::beman::net29::detail::ex; + namespace ex = ::beman::net::detail::ex; template struct task_state_base @@ -33,7 +33,7 @@ namespace demo template auto complete_set_value(Receiver& receiver) { - ::beman::net29::detail::ex::set_value( + ::beman::net::detail::ex::set_value( ::std::move(receiver), ::std::move(*this->task_result) ); } @@ -48,7 +48,7 @@ namespace demo template auto complete_set_value(Receiver& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver)); + ::beman::net::detail::ex::set_value(::std::move(receiver)); } }; @@ -85,9 +85,9 @@ namespace demo }; template - struct task_completion { using type = ::beman::net29::detail::ex::set_value_t(T); }; + struct task_completion { using type = ::beman::net::detail::ex::set_value_t(T); }; template <> - struct task_completion { using type = ::beman::net29::detail::ex::set_value_t(); }; + struct task_completion { using type = ::beman::net::detail::ex::set_value_t(); }; template struct task @@ -245,23 +245,23 @@ namespace demo } auto complete_error(::std::exception_ptr error) -> void override { - ::beman::net29::detail::ex::set_error( + ::beman::net::detail::ex::set_error( ::std::move(this->receiver), ::std::move(error) ); } auto complete_stopped() -> void override { - ::beman::net29::detail::ex::set_stopped(::std::move(this->receiver)); + ::beman::net::detail::ex::set_stopped(::std::move(this->receiver)); } }; unique_handle handle; - using sender_concept = ::beman::net29::detail::ex::sender_t; - using completion_signatures = ::beman::net29::detail::ex::completion_signatures< - ::beman::net29::detail::ex::set_error_t(::std::exception_ptr), - ::beman::net29::detail::ex::set_stopped_t(), + using sender_concept = ::beman::net::detail::ex::sender_t; + using completion_signatures = ::beman::net::detail::ex::completion_signatures< + ::beman::net::detail::ex::set_error_t(::std::exception_ptr), + ::beman::net::detail::ex::set_stopped_t(), typename task_completion<::std::decay_t>::type >; diff --git a/examples/empty.cpp b/examples/empty.cpp index 9489180..9d08594 100644 --- a/examples/empty.cpp +++ b/examples/empty.cpp @@ -1,7 +1,7 @@ // examples/http-server.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include "demo_algorithm.hpp" #include "demo_error.hpp" @@ -15,7 +15,7 @@ #include namespace ex = beman::execution26; -namespace net = beman::net29; +namespace net = beman::net; using namespace std::chrono_literals; // ---------------------------------------------------------------------------- diff --git a/examples/http-server.cpp b/examples/http-server.cpp index f335c95..91ef999 100644 --- a/examples/http-server.cpp +++ b/examples/http-server.cpp @@ -1,7 +1,7 @@ // examples/http-server.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include "demo_algorithm.hpp" #include "demo_scope.hpp" @@ -14,7 +14,7 @@ #include namespace ex = beman::execution26; -namespace net = beman::net29; +namespace net = beman::net; using namespace std::chrono_literals; // ---------------------------------------------------------------------------- diff --git a/examples/milano.cpp b/examples/milano.cpp index 358b15a..7315df6 100644 --- a/examples/milano.cpp +++ b/examples/milano.cpp @@ -1,7 +1,7 @@ // examples/http-server.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include "demo_algorithm.hpp" #include "demo_error.hpp" @@ -15,7 +15,7 @@ #include namespace ex = beman::execution26; -namespace net = beman::net29; +namespace net = beman::net; using namespace std::chrono_literals; // ---------------------------------------------------------------------------- diff --git a/examples/server.cpp b/examples/server.cpp index 9ca4cbd..6d29036 100644 --- a/examples/server.cpp +++ b/examples/server.cpp @@ -5,13 +5,13 @@ #include #include #include -#include +#include #include "demo_algorithm.hpp" #include "demo_scope.hpp" #include "demo_task.hpp" namespace ex = ::beman::execution26; -namespace net = ::beman::net29; +namespace net = ::beman::net; using namespace std::chrono_literals; auto use(auto&&) -> void {} diff --git a/examples/task.cpp b/examples/task.cpp index 9e040d1..204a3d0 100644 --- a/examples/task.cpp +++ b/examples/task.cpp @@ -5,12 +5,12 @@ #include #include #include -#include +#include #include "demo_scope.hpp" #include "demo_task.hpp" namespace ex = ::beman::execution26; -namespace net = ::beman::net29; +namespace net = ::beman::net; namespace { diff --git a/include/beman/net/detail/basic_socket.hpp b/include/beman/net/detail/basic_socket.hpp new file mode 100644 index 0000000..f99d098 --- /dev/null +++ b/include/beman/net/detail/basic_socket.hpp @@ -0,0 +1,63 @@ +// include/beman/net/detail/basic_socket.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_NET_DETAIL_BASIC_SOCKET +#define INCLUDED_BEMAN_NET_DETAIL_BASIC_SOCKET + +// ---------------------------------------------------------------------------- + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +template +class beman::net::basic_socket + : public ::beman::net::socket_base +{ +public: + using scheduler_type = ::beman::net::detail::io_context_scheduler; + using protocol_type = Protocol; + +private: + ::beman::net::detail::context_base* d_context; + protocol_type d_protocol{::beman::net::ip::tcp::v6()}; + ::beman::net::detail::socket_id d_id{::beman::net::detail::socket_id::invalid}; + +public: + basic_socket() + : d_context(nullptr) + { + } + basic_socket(::beman::net::detail::context_base* context, ::beman::net::detail::socket_id id) + : d_context(context) + , d_id(id) + { + } + basic_socket(basic_socket&& other) + : d_context(other.d_context) + , d_protocol(other.d_protocol) + , d_id(::std::exchange(other.d_id, ::beman::net::detail::socket_id::invalid)) + { + } + ~basic_socket() + { + if (this->d_id != ::beman::net::detail::socket_id::invalid) + { + ::std::error_code error{}; + this->d_context->release(this->d_id, error); + } + } + auto get_scheduler() noexcept -> scheduler_type + { + return scheduler_type{this->d_context}; + } + auto id() const -> ::beman::net::detail::socket_id { return this->d_id; } +}; + + +// ---------------------------------------------------------------------------- + +#endif diff --git a/include/beman/net29/detail/basic_socket_acceptor.hpp b/include/beman/net/detail/basic_socket_acceptor.hpp similarity index 70% rename from include/beman/net29/detail/basic_socket_acceptor.hpp rename to include/beman/net/detail/basic_socket_acceptor.hpp index 983a5cd..8d14736 100644 --- a/include/beman/net29/detail/basic_socket_acceptor.hpp +++ b/include/beman/net/detail/basic_socket_acceptor.hpp @@ -1,16 +1,16 @@ -// include/beman/net29/detail/basic_socket_acceptor.hpp -*-C++-*- +// include/beman/net/detail/basic_socket_acceptor.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_BASIC_SOCKET_ACCEPTOR -#define INCLUDED_BEMAN_NET29_DETAIL_BASIC_SOCKET_ACCEPTOR +#ifndef INCLUDED_BEMAN_NET_DETAIL_BASIC_SOCKET_ACCEPTOR +#define INCLUDED_BEMAN_NET_DETAIL_BASIC_SOCKET_ACCEPTOR -#include -#include +#include +#include #include // ---------------------------------------------------------------------------- -namespace beman::net29 +namespace beman::net { template class basic_socket_acceptor; @@ -19,21 +19,21 @@ namespace beman::net29 // ---------------------------------------------------------------------------- template -class beman::net29::basic_socket_acceptor - : public ::beman::net29::socket_base +class beman::net::basic_socket_acceptor + : public ::beman::net::socket_base { public: - using scheduler_type = ::beman::net29::io_context::scheduler_type; - using executor_type = ::beman::net29::io_context::executor_type; - using native_handle_type = ::beman::net29::detail::native_handle_type; + using scheduler_type = ::beman::net::io_context::scheduler_type; + using executor_type = ::beman::net::io_context::executor_type; + using native_handle_type = ::beman::net::detail::native_handle_type; using protocol_type = AcceptableProtocol; using endpoint_type = typename protocol_type::endpoint; using socket_type = typename protocol_type::socket; private: - ::beman::net29::io_context& d_context; + ::beman::net::io_context& d_context; protocol_type d_protocol; - ::beman::net29::detail::socket_id d_id{}; + ::beman::net::detail::socket_id d_id{}; private: template @@ -48,32 +48,32 @@ class beman::net29::basic_socket_acceptor } public: - //explicit basic_socket_acceptor(::beman::net29::io_context&); - basic_socket_acceptor(::beman::net29::io_context&, protocol_type const& protocol); - basic_socket_acceptor(::beman::net29::io_context& context, endpoint_type const& endpoint, bool reuse = true) - : ::beman::net29::socket_base() + //explicit basic_socket_acceptor(::beman::net::io_context&); + basic_socket_acceptor(::beman::net::io_context&, protocol_type const& protocol); + basic_socket_acceptor(::beman::net::io_context& context, endpoint_type const& endpoint, bool reuse = true) + : ::beman::net::socket_base() , d_context(context) , d_protocol(endpoint.protocol()) - , d_id(::beman::net29::detail::socket_id::invalid) + , d_id(::beman::net::detail::socket_id::invalid) { this->open(endpoint.protocol()); if (reuse) { - this->set_option(::beman::net29::socket_base::reuse_address(true)); + this->set_option(::beman::net::socket_base::reuse_address(true)); } this->bind(endpoint); this->listen(); } - basic_socket_acceptor(::beman::net29::io_context&, protocol_type const&, native_handle_type const&); + basic_socket_acceptor(::beman::net::io_context&, protocol_type const&, native_handle_type const&); basic_socket_acceptor(basic_socket_acceptor const&) = delete; basic_socket_acceptor(basic_socket_acceptor&& other) - : ::beman::net29::socket_base() + : ::beman::net::socket_base() , d_protocol(other.d_protocol) - , d_id(::std::exchange(other.d_id, ::beman::net29::detail::socket_id::invalid)) + , d_id(::std::exchange(other.d_id, ::beman::net::detail::socket_id::invalid)) { } template - basic_socket_acceptor(::beman::net29::basic_socket_acceptor&&); + basic_socket_acceptor(::beman::net::basic_socket_acceptor&&); ~basic_socket_acceptor() { //-dk:TODO assert that there is no outstanding work? @@ -83,9 +83,9 @@ class beman::net29::basic_socket_acceptor basic_socket_acceptor& operator=(basic_socket_acceptor const&) = delete; basic_socket_acceptor& operator=(basic_socket_acceptor&&); template - basic_socket_acceptor& operator=(::beman::net29::basic_socket_acceptor&&); + basic_socket_acceptor& operator=(::beman::net::basic_socket_acceptor&&); - auto get_context() -> ::beman::net29::io_context& { return this->d_context; } + auto get_context() -> ::beman::net::io_context& { return this->d_context; } auto get_scheduler() noexcept -> scheduler_type { return this->d_context.get_scheduler(); @@ -93,7 +93,7 @@ class beman::net29::basic_socket_acceptor executor_type get_executor() noexcept; auto native_handle() -> native_handle_type { return this->d_context.native_handle(this->d_id); } auto _native_handle() const -> native_handle_type { return this->d_context.native_handle(this->d_id); } - auto id() const -> ::beman::net29::detail::socket_id { return this->d_id; } + auto id() const -> ::beman::net::detail::socket_id { return this->d_id; } auto open(protocol_type const& p = protocol_type()) -> void { dispatch([this, &p](::std::error_code& error){ this->open(p, error); }); @@ -102,7 +102,7 @@ class beman::net29::basic_socket_acceptor { if (this->is_open()) { - error = ::std::error_code(int(socket_errc::already_open), ::beman::net29::socket_category()); + error = ::std::error_code(int(socket_errc::already_open), ::beman::net::socket_category()); } this->d_id = this->d_context.make_socket(p.family(), p.type(), p.protocol(), error); } @@ -110,7 +110,7 @@ class beman::net29::basic_socket_acceptor void assign(protocol_type const&, native_handle_type const&, ::std::error_code&); native_handle_type release(); native_handle_type release(::std::error_code&); - auto is_open() const noexcept -> bool { return this->d_id != ::beman::net29::detail::socket_id::invalid; } + auto is_open() const noexcept -> bool { return this->d_id != ::beman::net::detail::socket_id::invalid; } auto close() -> void { dispatch([this](auto& error){ return this->close(error); }); @@ -121,7 +121,7 @@ class beman::net29::basic_socket_acceptor if (this->is_open()) { this->d_context.release(this->id(), error); - this->d_id = ::beman::net29::detail::socket_id::invalid; + this->d_id = ::beman::net::detail::socket_id::invalid; } } void cancel(); @@ -165,7 +165,7 @@ class beman::net29::basic_socket_acceptor { this->d_context.bind(this->d_id, endpoint, error); } - auto listen(int no = ::beman::net29::socket_base::max_listen_connections) -> void + auto listen(int no = ::beman::net::socket_base::max_listen_connections) -> void { dispatch([this, no](auto& error){ this->listen(no, error); }); } @@ -183,10 +183,10 @@ class beman::net29::basic_socket_acceptor socket_type accept(io_context&, ::std::error_code&); socket_type accept(endpoint_type&); socket_type accept(endpoint_type&, ::std::error_code&); - socket_type accept(::beman::net29::io_context&, endpoint_type&); - socket_type accept(::beman::net29::io_context&, endpoint_type&, ::std::error_code&); - void wait(::beman::net29::socket_base::wait_type); - void wait(::beman::net29::socket_base::wait_type, ::std::error_code&); + socket_type accept(::beman::net::io_context&, endpoint_type&); + socket_type accept(::beman::net::io_context&, endpoint_type&, ::std::error_code&); + void wait(::beman::net::socket_base::wait_type); + void wait(::beman::net::socket_base::wait_type, ::std::error_code&); }; // ---------------------------------------------------------------------------- diff --git a/include/beman/net29/detail/basic_stream_socket.hpp b/include/beman/net/detail/basic_stream_socket.hpp similarity index 63% rename from include/beman/net29/detail/basic_stream_socket.hpp rename to include/beman/net/detail/basic_stream_socket.hpp index 8bf9c54..6e0105d 100644 --- a/include/beman/net29/detail/basic_stream_socket.hpp +++ b/include/beman/net/detail/basic_stream_socket.hpp @@ -1,25 +1,25 @@ -// include/beman/net29/detail/basic_stream_socket.hpp -*-C++-*- +// include/beman/net/detail/basic_stream_socket.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_BASIC_STREAM_SOCKET -#define INCLUDED_BEMAN_NET29_DETAIL_BASIC_STREAM_SOCKET +#ifndef INCLUDED_BEMAN_NET_DETAIL_BASIC_STREAM_SOCKET +#define INCLUDED_BEMAN_NET_DETAIL_BASIC_STREAM_SOCKET // ---------------------------------------------------------------------------- -#include -#include -#include +#include +#include +#include #include #include // ---------------------------------------------------------------------------- template -class beman::net29::basic_stream_socket +class beman::net::basic_stream_socket : public basic_socket { public: - using native_handle_type = ::beman::net29::detail::native_handle_type; + using native_handle_type = ::beman::net::detail::native_handle_type; using protocol_type = Protocol; using endpoint_type = typename protocol_type::endpoint; @@ -29,12 +29,12 @@ class beman::net29::basic_stream_socket public: basic_stream_socket(basic_stream_socket&&) = default; basic_stream_socket& operator= (basic_stream_socket&&) = default; - basic_stream_socket(::beman::net29::detail::context_base* context, ::beman::net29::detail::socket_id id) + basic_stream_socket(::beman::net::detail::context_base* context, ::beman::net::detail::socket_id id) : basic_socket(context, id) { } - basic_stream_socket(::beman::net29::io_context& context, endpoint_type const& endpoint) - : beman::net29::basic_socket(context.get_scheduler().get_context(), + basic_stream_socket(::beman::net::io_context& context, endpoint_type const& endpoint) + : beman::net::basic_socket(context.get_scheduler().get_context(), ::std::invoke([p = endpoint.protocol(), &context]{ ::std::error_code error{}; auto rc(context.make_socket(p.family(), p.type(), p.protocol(), error)); diff --git a/include/beman/net29/detail/buffer.hpp b/include/beman/net/detail/buffer.hpp similarity index 60% rename from include/beman/net29/detail/buffer.hpp rename to include/beman/net/detail/buffer.hpp index 7e6906a..888ceac 100644 --- a/include/beman/net29/detail/buffer.hpp +++ b/include/beman/net/detail/buffer.hpp @@ -1,8 +1,8 @@ -// include/beman/net29/detail/buffer.hpp -*-C++-*- +// include/beman/net/detail/buffer.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_BUFFER -#define INCLUDED_BEMAN_NET29_DETAIL_BUFFER +#ifndef INCLUDED_BEMAN_NET_DETAIL_BUFFER +#define INCLUDED_BEMAN_NET_DETAIL_BUFFER #include #include @@ -12,14 +12,14 @@ // ---------------------------------------------------------------------------- -namespace beman::net29 +namespace beman::net { enum class stream_errc: int; auto stream_category() noexcept -> ::std::error_category const&; - auto make_error_code(::beman::net29::stream_errc) noexcept -> ::std::error_code; - auto make_error_condition(::beman::net29::stream_errc) noexcept -> ::std::error_condition; + auto make_error_code(::beman::net::stream_errc) noexcept -> ::std::error_code; + auto make_error_condition(::beman::net::stream_errc) noexcept -> ::std::error_condition; struct mutable_buffer; struct const_buffer; @@ -31,20 +31,20 @@ namespace beman::net29 struct buffer_sequence; template <::std::size_t _S> - auto buffer(char (&)[_S]) -> ::beman::net29::mutable_buffer; - auto buffer(char*, ::std::size_t) -> ::beman::net29::mutable_buffer; - auto buffer(char const*, ::std::size_t) -> ::beman::net29::const_buffer; + auto buffer(char (&)[_S]) -> ::beman::net::mutable_buffer; + auto buffer(char*, ::std::size_t) -> ::beman::net::mutable_buffer; + auto buffer(char const*, ::std::size_t) -> ::beman::net::const_buffer; template requires requires(_CT&& _C){ _C.data(); _C.size(); } auto buffer(_CT&& _C) { - return beman::net29::buffer(_C.data(), _C.size()); + return beman::net::buffer(_C.data(), _C.size()); } } // ---------------------------------------------------------------------------- -enum class beman::net29::stream_errc: int +enum class beman::net::stream_errc: int { eof, not_found @@ -52,7 +52,7 @@ enum class beman::net29::stream_errc: int // ---------------------------------------------------------------------------- -inline auto beman::net29::stream_category() noexcept -> ::std::error_category const& +inline auto beman::net::stream_category() noexcept -> ::std::error_category const& { struct _Category : ::std::error_category @@ -72,7 +72,7 @@ inline auto beman::net29::stream_category() noexcept -> ::std::error_category co // ---------------------------------------------------------------------------- -struct beman::net29::mutable_buffer +struct beman::net::mutable_buffer { ::iovec _Vec; mutable_buffer(void* _B, ::std::size_t _L): _Vec{ .iov_base = _B, .iov_len = _L } {} @@ -81,7 +81,7 @@ struct beman::net29::mutable_buffer auto size() -> ::std::size_t { return 1u; } }; -struct beman::net29::const_buffer +struct beman::net::const_buffer { ::iovec _Vec; const_buffer(void const* _B, ::std::size_t _L): _Vec{ .iov_base = const_cast(_B), .iov_len = _L } {} @@ -91,19 +91,19 @@ struct beman::net29::const_buffer }; template <::std::size_t _S> -inline auto beman::net29::buffer(char (&_B)[_S]) -> ::beman::net29::mutable_buffer +inline auto beman::net::buffer(char (&_B)[_S]) -> ::beman::net::mutable_buffer { - return ::beman::net29::mutable_buffer(_B, _S); + return ::beman::net::mutable_buffer(_B, _S); } -inline auto beman::net29::buffer(char* _B, ::std::size_t _Size) -> ::beman::net29::mutable_buffer +inline auto beman::net::buffer(char* _B, ::std::size_t _Size) -> ::beman::net::mutable_buffer { - return ::beman::net29::mutable_buffer(_B, _Size); + return ::beman::net::mutable_buffer(_B, _Size); } -inline auto beman::net29::buffer(char const* _B, ::std::size_t _Size) -> ::beman::net29::const_buffer +inline auto beman::net::buffer(char const* _B, ::std::size_t _Size) -> ::beman::net::const_buffer { - return ::beman::net29::const_buffer(_B, _Size); + return ::beman::net::const_buffer(_B, _Size); } // ---------------------------------------------------------------------------- diff --git a/include/beman/net29/detail/container.hpp b/include/beman/net/detail/container.hpp similarity index 57% rename from include/beman/net29/detail/container.hpp rename to include/beman/net/detail/container.hpp index 2c79713..df3c98f 100644 --- a/include/beman/net29/detail/container.hpp +++ b/include/beman/net/detail/container.hpp @@ -1,17 +1,17 @@ -// include/beman/net29/detail/container.hpp -*-C++-*- +// include/beman/net/detail/container.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_CONTAINER -#define INCLUDED_BEMAN_NET29_DETAIL_CONTAINER +#ifndef INCLUDED_BEMAN_NET_DETAIL_CONTAINER +#define INCLUDED_BEMAN_NET_DETAIL_CONTAINER -#include +#include #include #include #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { template class container; } @@ -19,44 +19,44 @@ namespace beman::net29::detail // ---------------------------------------------------------------------------- template -class beman::net29::detail::container +class beman::net::detail::container { private: ::std::vector<::std::variant<::std::size_t, Record>> records; ::std::size_t free{}; public: - auto insert(Record r) -> ::beman::net29::detail::socket_id; - auto erase(::beman::net29::detail::socket_id id) -> void; - auto operator[](::beman::net29::detail::socket_id id) -> Record&; + auto insert(Record r) -> ::beman::net::detail::socket_id; + auto erase(::beman::net::detail::socket_id id) -> void; + auto operator[](::beman::net::detail::socket_id id) -> Record&; }; // ---------------------------------------------------------------------------- template -inline auto beman::net29::detail::container::insert(Record r) -> ::beman::net29::detail::socket_id +inline auto beman::net::detail::container::insert(Record r) -> ::beman::net::detail::socket_id { if (this->free == this->records.size()) { this->records.emplace_back(::std::move(r)); - return ::beman::net29::detail::socket_id(this->free++); + return ::beman::net::detail::socket_id(this->free++); } else { ::std::size_t rc(std::exchange(this->free, ::std::get<0>(this->records[this->free]))); this->records[rc] = ::std::move(r); - return ::beman::net29::detail::socket_id(rc); + return ::beman::net::detail::socket_id(rc); } } template -inline auto beman::net29::detail::container::erase(::beman::net29::detail::socket_id id) -> void +inline auto beman::net::detail::container::erase(::beman::net::detail::socket_id id) -> void { this->records[::std::size_t(id)] = std::exchange(this->free, ::std::size_t(id)); } template -inline auto beman::net29::detail::container::operator[](::beman::net29::detail::socket_id id) -> Record& +inline auto beman::net::detail::container::operator[](::beman::net::detail::socket_id id) -> Record& { assert(this->records[::std::size_t(id)].index() == 1u); return ::std::get<1>(this->records[::std::size_t(id)]); diff --git a/include/beman/net/detail/context_base.hpp b/include/beman/net/detail/context_base.hpp new file mode 100644 index 0000000..22d3b8a --- /dev/null +++ b/include/beman/net/detail/context_base.hpp @@ -0,0 +1,81 @@ +// include/beman/net/detail/context_base.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_NET_DETAIL_CONTEXT_BASE +#define INCLUDED_BEMAN_NET_DETAIL_CONTEXT_BASE + +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace beman::net::detail +{ + struct context_base; +} + +// ---------------------------------------------------------------------------- + +struct beman::net::detail::context_base +{ + struct task + { + task* next; + virtual auto complete() -> void = 0; + }; + + using accept_operation = ::beman::net::detail::io_operation< + ::std::tuple<::beman::net::detail::endpoint, + ::socklen_t, + ::std::optional<::beman::net::detail::socket_id> + > + >; + using connect_operation = ::beman::net::detail::io_operation< + ::std::tuple<::beman::net::detail::endpoint> + >; + using receive_operation = ::beman::net::detail::io_operation< + ::std::tuple<::msghdr, int, ::std::size_t> + >; + using send_operation = ::beman::net::detail::io_operation< + ::std::tuple<::msghdr, int, ::std::size_t> + >; + using resume_after_operation = ::beman::net::detail::io_operation< + ::std::tuple<::std::chrono::system_clock::time_point, ::timeval> + >; + using resume_at_operation = ::beman::net::detail::io_operation< + ::std::tuple<::std::chrono::system_clock::time_point, ::timeval> + >; + + virtual ~context_base() = default; + virtual auto make_socket(int) -> ::beman::net::detail::socket_id = 0; + virtual auto make_socket(int, int, int, ::std::error_code&) -> ::beman::net::detail::socket_id = 0; + virtual auto release(::beman::net::detail::socket_id, ::std::error_code&) -> void = 0; + virtual auto native_handle(::beman::net::detail::socket_id) -> ::beman::net::detail::native_handle_type = 0; + virtual auto set_option(::beman::net::detail::socket_id, int, int, void const*, ::socklen_t, ::std::error_code&) -> void = 0; + virtual auto bind(::beman::net::detail::socket_id, ::beman::net::detail::endpoint const&, ::std::error_code&) -> void = 0; + virtual auto listen(::beman::net::detail::socket_id, int, ::std::error_code&) -> void = 0; + + virtual auto run_one() -> ::std::size_t = 0; + + virtual auto cancel(::beman::net::detail::io_base*, ::beman::net::detail::io_base*) -> void = 0; + virtual auto schedule(::beman::net::detail::context_base::task*) -> void = 0; + virtual auto accept(::beman::net::detail::context_base::accept_operation*) + -> ::beman::net::detail::submit_result = 0; + virtual auto connect(::beman::net::detail::context_base::connect_operation*) + -> ::beman::net::detail::submit_result = 0; + virtual auto receive(::beman::net::detail::context_base::receive_operation*) + -> ::beman::net::detail::submit_result = 0; + virtual auto send(::beman::net::detail::context_base::send_operation*) + -> ::beman::net::detail::submit_result = 0; + virtual auto resume_at(::beman::net::detail::context_base::resume_at_operation*) + -> ::beman::net::detail::submit_result = 0; +}; + +// ---------------------------------------------------------------------------- + +#endif diff --git a/include/beman/net29/detail/endpoint.hpp b/include/beman/net/detail/endpoint.hpp similarity index 84% rename from include/beman/net29/detail/endpoint.hpp rename to include/beman/net/detail/endpoint.hpp index 6004f8e..bb998dc 100644 --- a/include/beman/net29/detail/endpoint.hpp +++ b/include/beman/net/detail/endpoint.hpp @@ -1,8 +1,8 @@ -// include/beman/net29/detail/endpoint.hpp -*-C++-*- +// include/beman/net/detail/endpoint.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_ENDPOINT -#define INCLUDED_BEMAN_NET29_DETAIL_ENDPOINT +#ifndef INCLUDED_BEMAN_NET_DETAIL_ENDPOINT +#define INCLUDED_BEMAN_NET_DETAIL_ENDPOINT #include #include @@ -10,14 +10,14 @@ // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { class endpoint; } // ---------------------------------------------------------------------------- -class beman::net29::detail::endpoint +class beman::net::detail::endpoint { private: ::sockaddr_storage d_data{}; diff --git a/include/beman/net29/detail/execution.hpp b/include/beman/net/detail/execution.hpp similarity index 91% rename from include/beman/net29/detail/execution.hpp rename to include/beman/net/detail/execution.hpp index f16238c..73a3754 100644 --- a/include/beman/net29/detail/execution.hpp +++ b/include/beman/net/detail/execution.hpp @@ -1,14 +1,14 @@ -// include/beman/net29/detail/execution.hpp -*-C++-*- +// include/beman/net/detail/execution.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_INCLUDE_BEMAN_NET29_DETAIL_EXECUTION -#define INCLUDED_INCLUDE_BEMAN_NET29_DETAIL_EXECUTION +#ifndef INCLUDED_INCLUDE_BEMAN_NET_DETAIL_EXECUTION +#define INCLUDED_INCLUDE_BEMAN_NET_DETAIL_EXECUTION #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail::ex::detail +namespace beman::net::detail::ex::detail { using ::beman::execution26::detail::type_list; using ::beman::execution26::detail::variant_or_empty; @@ -20,7 +20,7 @@ namespace beman::net29::detail::ex::detail using ::beman::execution26::detail::forward_like; } -namespace beman::net29::detail::ex +namespace beman::net::detail::ex { using ::beman::execution26::completion_signatures; using ::beman::execution26::detail::decayed_tuple; diff --git a/include/beman/net29/detail/internet.hpp b/include/beman/net/detail/internet.hpp similarity index 78% rename from include/beman/net29/detail/internet.hpp rename to include/beman/net/detail/internet.hpp index 41dce47..0f82b62 100644 --- a/include/beman/net29/detail/internet.hpp +++ b/include/beman/net/detail/internet.hpp @@ -1,11 +1,11 @@ -// include/beman/net29/detail/internet.hpp -*-C++-*- +// include/beman/net/detail/internet.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_INTERNET -#define INCLUDED_BEMAN_NET29_DETAIL_INTERNET +#ifndef INCLUDED_BEMAN_NET_DETAIL_INTERNET +#define INCLUDED_BEMAN_NET_DETAIL_INTERNET -#include -#include +#include +#include #include #include #include @@ -19,7 +19,7 @@ // ---------------------------------------------------------------------------- -namespace beman::net29::ip +namespace beman::net::ip { using port_type = ::std::uint_least16_t; @@ -32,7 +32,7 @@ namespace beman::net29::ip // ---------------------------------------------------------------------------- -class beman::net29::ip::tcp +class beman::net::ip::tcp { private: int d_family; @@ -56,7 +56,7 @@ class beman::net29::ip::tcp // ---------------------------------------------------------------------------- -class beman::net29::ip::address_v4 +class beman::net::ip::address_v4 { public: using uint_type = uint_least32_t; @@ -128,7 +128,7 @@ basic_ostream& os, const address_v4& addr); // ---------------------------------------------------------------------------- -class beman::net29::ip::address_v6 +class beman::net::ip::address_v6 { public: struct bytes_type @@ -159,7 +159,7 @@ class beman::net29::ip::address_v6 constexpr auto operator== (address_v6 const&) const -> bool = default; constexpr auto operator<=> (address_v6 const&) const -> ::std::strong_ordering; - auto get_address(::sockaddr_in6& addr, ::beman::net29::ip::port_type port) const + auto get_address(::sockaddr_in6& addr, ::beman::net::ip::port_type port) const -> ::socklen_t { addr.sin6_family = AF_INET6; @@ -193,26 +193,26 @@ class beman::net29::ip::address_v6 } }; -inline constexpr beman::net29::ip::address_v6::address_v6() noexcept +inline constexpr beman::net::ip::address_v6::address_v6() noexcept : d_bytes() { } -inline constexpr auto beman::net29::ip::address_v6::any() noexcept - -> ::beman::net29::ip::address_v6 +inline constexpr auto beman::net::ip::address_v6::any() noexcept + -> ::beman::net::ip::address_v6 { - return ::beman::net29::ip::address_v6(); + return ::beman::net::ip::address_v6(); } -inline constexpr auto beman::net29::ip::address_v6::loopback() noexcept - -> ::beman::net29::ip::address_v6 +inline constexpr auto beman::net::ip::address_v6::loopback() noexcept + -> ::beman::net::ip::address_v6 { - return ::beman::net29::ip::address_v6(); + return ::beman::net::ip::address_v6(); } // ---------------------------------------------------------------------------- -class beman::net29::ip::address +class beman::net::ip::address { private: union address_t @@ -231,31 +231,31 @@ class beman::net29::ip::address this->d_address.storage.ss_family = PF_INET; } constexpr address(address const&) noexcept = default; - /*-dk:TODO constexpr*/ address(::beman::net29::ip::address_v4 const& address) noexcept + /*-dk:TODO constexpr*/ address(::beman::net::ip::address_v4 const& address) 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_port = 0xFF'FF; } - /*-dk:TODO constexpr*/ address(::beman::net29::ip::address_v6 const& address) noexcept + /*-dk:TODO constexpr*/ address(::beman::net::ip::address_v6 const& address) noexcept { address.get_address(this->d_address.inet6, 0xFF'FF); } auto operator=(address const&) noexcept -> address& = default; - auto operator=(::beman::net29::ip::address_v4 const&) noexcept -> address&; - auto operator=(::beman::net29::ip::address_v6 const&) noexcept -> address&; + auto operator=(::beman::net::ip::address_v4 const&) noexcept -> address&; + auto operator=(::beman::net::ip::address_v6 const&) noexcept -> address&; auto data() const -> ::sockaddr_storage const& { return this->d_address.storage; } constexpr auto is_v4() const noexcept -> bool { return this->d_address.storage.ss_family == PF_INET; } constexpr auto is_v6() const noexcept -> bool { return this->d_address.storage.ss_family == PF_INET6; } - /*constexpr -dk:TODO*/ auto to_v4() const -> ::beman::net29::ip::address_v4 + /*constexpr -dk:TODO*/ auto to_v4() const -> ::beman::net::ip::address_v4 { - return ::beman::net29::ip::address_v4(ntohl(reinterpret_cast<::sockaddr_in const&>(this->d_address.storage).sin_addr.s_addr)); + return ::beman::net::ip::address_v4(ntohl(reinterpret_cast<::sockaddr_in const&>(this->d_address.storage).sin_addr.s_addr)); } - constexpr auto to_v6() const -> ::beman::net29::ip::address_v6 + constexpr auto to_v6() const -> ::beman::net::ip::address_v6 { - return ::beman::net29::ip::address_v6(this->d_address.inet6.sin6_addr.s6_addr); + return ::beman::net::ip::address_v6(this->d_address.inet6.sin6_addr.s6_addr); } constexpr auto is_unspecified() const noexcept -> bool; constexpr auto is_loopback() const noexcept -> bool; @@ -275,23 +275,23 @@ class beman::net29::ip::address // ---------------------------------------------------------------------------- template -class beman::net29::ip::basic_endpoint - : public ::beman::net29::detail::endpoint +class beman::net::ip::basic_endpoint + : public ::beman::net::detail::endpoint { public: using protocol_type = Protocol; constexpr basic_endpoint() noexcept - : basic_endpoint(::beman::net29::ip::address(), ::beman::net29::ip::port_type()) + : basic_endpoint(::beman::net::ip::address(), ::beman::net::ip::port_type()) { } - constexpr basic_endpoint(::beman::net29::detail::endpoint const& ep) noexcept - : ::beman::net29::detail::endpoint(ep) + constexpr basic_endpoint(::beman::net::detail::endpoint const& ep) noexcept + : ::beman::net::detail::endpoint(ep) { } - constexpr basic_endpoint(const protocol_type&, ::beman::net29::ip::port_type) noexcept; - constexpr basic_endpoint(const ip::address& address, ::beman::net29::ip::port_type port) noexcept - : ::beman::net29::detail::endpoint(&address.data(), address.is_v4()? sizeof(::sockaddr_in): sizeof(::sockaddr_in6)) + constexpr basic_endpoint(const protocol_type&, ::beman::net::ip::port_type) noexcept; + constexpr basic_endpoint(const ip::address& address, ::beman::net::ip::port_type port) noexcept + : ::beman::net::detail::endpoint(&address.data(), address.is_v4()? sizeof(::sockaddr_in): sizeof(::sockaddr_in6)) { (address.is_v4() ? reinterpret_cast<::sockaddr_in&>(this->storage()).sin_port @@ -300,19 +300,19 @@ class beman::net29::ip::basic_endpoint constexpr auto protocol() const noexcept -> protocol_type { - return this->storage().ss_family == PF_INET? ::beman::net29::ip::tcp::v4(): ::beman::net29::ip::tcp::v6(); + return this->storage().ss_family == PF_INET? ::beman::net::ip::tcp::v4(): ::beman::net::ip::tcp::v6(); } - /*-dk:TODO constexpr*/ auto address() const noexcept -> ::beman::net29::ip::address + /*-dk:TODO constexpr*/ auto address() const noexcept -> ::beman::net::ip::address { switch (this->storage().ss_family) { default: return {}; - case PF_INET: return ::beman::net29::ip::address_v4(ntohl(reinterpret_cast<::sockaddr_in const&>(this->storage()).sin_addr.s_addr)); - //-dk:TODO case PF_INET6: return ::beman::net29::ip::address_v6(reinterpret_cast<::sockaddr_in6 const&>(this->storage()).sin6_addr.s_addr); + case PF_INET: return ::beman::net::ip::address_v4(ntohl(reinterpret_cast<::sockaddr_in const&>(this->storage()).sin_addr.s_addr)); + //-dk:TODO case PF_INET6: return ::beman::net::ip::address_v6(reinterpret_cast<::sockaddr_in6 const&>(this->storage()).sin6_addr.s_addr); } } - auto address(::beman::net29::ip::address const&) noexcept -> void; - constexpr auto port() const noexcept -> ::beman::net29::ip::port_type + auto address(::beman::net::ip::address const&) noexcept -> void; + constexpr auto port() const noexcept -> ::beman::net::ip::port_type { switch (this->storage().ss_family) { @@ -321,7 +321,7 @@ class beman::net29::ip::basic_endpoint case PF_INET6: return ntohs(reinterpret_cast<::sockaddr_in6 const&>(this->storage()).sin6_port); } } - auto port(::beman::net29::ip::port_type) noexcept -> void; + auto port(::beman::net::ip::port_type) noexcept -> void; auto size() const -> ::socklen_t { diff --git a/include/beman/net29/detail/io_base.hpp b/include/beman/net/detail/io_base.hpp similarity index 59% rename from include/beman/net29/detail/io_base.hpp rename to include/beman/net/detail/io_base.hpp index 06deda7..da8e402 100644 --- a/include/beman/net29/detail/io_base.hpp +++ b/include/beman/net/detail/io_base.hpp @@ -1,21 +1,21 @@ -// include/beman/net29/detail/io_base.hpp -*-C++-*- +// include/beman/net/detail/io_base.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_IO_BASE -#define INCLUDED_BEMAN_NET29_DETAIL_IO_BASE +#ifndef INCLUDED_BEMAN_NET_DETAIL_IO_BASE +#define INCLUDED_BEMAN_NET_DETAIL_IO_BASE -#include +#include #include #include #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { enum class submit_result { ready, submit, error }; auto operator<< (::std::ostream&, - ::beman::net29::detail::submit_result) -> ::std::ostream&; + ::beman::net::detail::submit_result) -> ::std::ostream&; struct io_base; template struct io_operation; @@ -23,15 +23,15 @@ namespace beman::net29::detail // ---------------------------------------------------------------------------- -inline auto beman::net29::detail::operator<< ( +inline auto beman::net::detail::operator<< ( ::std::ostream& out, - ::beman::net29::detail::submit_result result) -> ::std::ostream& + ::beman::net::detail::submit_result result) -> ::std::ostream& { switch (result) { - case ::beman::net29::detail::submit_result::ready: return out << "ready"; - case ::beman::net29::detail::submit_result::submit: return out << "submit"; - case ::beman::net29::detail::submit_result::error: return out << "error"; + case ::beman::net::detail::submit_result::ready: return out << "ready"; + case ::beman::net::detail::submit_result::submit: return out << "submit"; + case ::beman::net::detail::submit_result::error: return out << "error"; } return out << ""; @@ -42,20 +42,20 @@ inline auto beman::net29::detail::operator<< ( // this type are also used to kick off the actual work once a readiness // indication was received. -struct beman::net29::detail::io_base +struct beman::net::detail::io_base { using extra_t = ::std::unique_ptrvoid>; - using work_t = auto(*)(::beman::net29::detail::context_base&, io_base*) - -> ::beman::net29::detail::submit_result; + using work_t = auto(*)(::beman::net::detail::context_base&, io_base*) + -> ::beman::net::detail::submit_result; io_base* next{nullptr}; // used for an intrusive list - ::beman::net29::detail::context_base* context{nullptr}; - ::beman::net29::detail::socket_id id; // the entity affected + ::beman::net::detail::context_base* context{nullptr}; + ::beman::net::detail::socket_id id; // the entity affected int event; // mask for expected events work_t work; extra_t extra{nullptr, +[](void*){}}; - io_base(::beman::net29::detail::socket_id id, int event): id(id), event(event) {} + io_base(::beman::net::detail::socket_id id, int event): id(id), event(event) {} virtual auto complete() -> void = 0; virtual auto error(::std::error_code) -> void = 0; @@ -67,12 +67,12 @@ struct beman::net29::detail::io_base // The struct io_operation is an io_base storing operation specific data. template -struct beman::net29::detail::io_operation +struct beman::net::detail::io_operation : io_base , Data { template - io_operation(::beman::net29::detail::socket_id id, int event, D&& a = Data()) + io_operation(::beman::net::detail::socket_id id, int event, D&& a = Data()) : io_base(id, event) , Data(::std::forward(a)) { diff --git a/include/beman/net29/detail/io_context.hpp b/include/beman/net/detail/io_context.hpp similarity index 53% rename from include/beman/net29/detail/io_context.hpp rename to include/beman/net/detail/io_context.hpp index e20b025..fe3d75c 100644 --- a/include/beman/net29/detail/io_context.hpp +++ b/include/beman/net/detail/io_context.hpp @@ -1,16 +1,16 @@ -// include/beman/net29/detail/io_context.hpp -*-C++-*- +// include/beman/net/detail/io_context.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_IO_CONTEXT -#define INCLUDED_BEMAN_NET29_DETAIL_IO_CONTEXT +#ifndef INCLUDED_BEMAN_NET_DETAIL_IO_CONTEXT +#define INCLUDED_BEMAN_NET_DETAIL_IO_CONTEXT // ---------------------------------------------------------------------------- -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -21,40 +21,40 @@ // ---------------------------------------------------------------------------- -namespace beman::net29 +namespace beman::net { class io_context; } // ---------------------------------------------------------------------------- -class beman::net29::io_context +class beman::net::io_context { private: - ::std::unique_ptr<::beman::net29::detail::context_base> d_owned{new ::beman::net29::detail::poll_context()}; - ::beman::net29::detail::context_base& d_context{*this->d_owned}; + ::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::poll_context()}; + ::beman::net::detail::context_base& d_context{*this->d_owned}; public: - using scheduler_type = ::beman::net29::detail::io_context_scheduler; + using scheduler_type = ::beman::net::detail::io_context_scheduler; class executor_type {}; io_context() { std::signal(SIGPIPE, SIG_IGN); } - io_context(::beman::net29::detail::context_base& context): d_owned(), d_context(context) {} + io_context(::beman::net::detail::context_base& context): d_owned(), d_context(context) {} io_context(io_context&&) = delete; - auto make_socket(int d, int t, int p, ::std::error_code& error) -> ::beman::net29::detail::socket_id + auto make_socket(int d, int t, int p, ::std::error_code& error) -> ::beman::net::detail::socket_id { return this->d_context.make_socket(d, t, p, error); } - auto release(::beman::net29::detail::socket_id id, ::std::error_code& error) -> void + auto release(::beman::net::detail::socket_id id, ::std::error_code& error) -> void { return this->d_context.release(id, error); } - auto native_handle(::beman::net29::detail::socket_id id) -> ::beman::net29::detail::native_handle_type + auto native_handle(::beman::net::detail::socket_id id) -> ::beman::net::detail::native_handle_type { return this->d_context.native_handle(id); } - auto set_option(::beman::net29::detail::socket_id id, + auto set_option(::beman::net::detail::socket_id id, int level, int name, void const* data, @@ -63,11 +63,11 @@ class beman::net29::io_context { this->d_context.set_option(id, level, name, data, size, error); } - auto bind(::beman::net29::detail::socket_id id, ::beman::net29::ip::basic_endpoint<::beman::net29::ip::tcp> const& endpoint, ::std::error_code& error) + auto bind(::beman::net::detail::socket_id id, ::beman::net::ip::basic_endpoint<::beman::net::ip::tcp> const& endpoint, ::std::error_code& error) { - this->d_context.bind(id, ::beman::net29::detail::endpoint(endpoint), error); + this->d_context.bind(id, ::beman::net::detail::endpoint(endpoint), error); } - auto listen(::beman::net29::detail::socket_id id, int no, ::std::error_code& error) + auto listen(::beman::net::detail::socket_id id, int no, ::std::error_code& error) { this->d_context.listen(id, no, error); } diff --git a/include/beman/net/detail/io_context_scheduler.hpp b/include/beman/net/detail/io_context_scheduler.hpp new file mode 100644 index 0000000..57d1e67 --- /dev/null +++ b/include/beman/net/detail/io_context_scheduler.hpp @@ -0,0 +1,131 @@ +// include/beman/net/detail/io_context_scheduler.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_NET_DETAIL_IO_CONTEXT_SCHEDULER +#define INCLUDED_BEMAN_NET_DETAIL_IO_CONTEXT_SCHEDULER + +// ---------------------------------------------------------------------------- + +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace beman::net::detail +{ + class io_context_scheduler; +} + +// ---------------------------------------------------------------------------- + +class beman::net::detail::io_context_scheduler +{ +private: + ::beman::net::detail::context_base* d_context; + +public: + using scheduler_concept = ::beman::net::detail::ex::scheduler_t; + + struct env + { + ::beman::net::detail::context_base* d_context; + + template + auto query(::beman::net::detail::ex::get_completion_scheduler_t const&) const noexcept + -> io_context_scheduler + { + return this->d_context; + } + }; + struct sender + { + template + struct state + : ::beman::net::detail::context_base::task + { + using operation_state_concept = ::beman::net::detail::ex::operation_state_t; + + ::std::remove_cvref_t d_receiver; + ::beman::net::detail::context_base* d_context; + + state(Receiver&& receiver, ::beman::net::detail::context_base* context) + : d_receiver(::std::forward(receiver)) + , d_context(context) + { + } + + auto start() & noexcept -> void + { + this->d_context->schedule(this); + } + auto complete() -> void override + { + ::beman::net::detail::ex::set_value(::std::move(this->d_receiver)); + } + }; + + using sender_concept = ::beman::net::detail::ex::sender_t; + ::beman::net::detail::context_base* d_context; + + template + auto connect(Receiver&& receiver) -> state + { + return {::std::forward(receiver), this->d_context}; + } + + auto get_env() const noexcept -> env { return {this->d_context}; } + }; + + auto schedule() noexcept -> sender { return {this->d_context}; } + auto operator== (io_context_scheduler const&) const -> bool = default; + + io_context_scheduler(::beman::net::detail::context_base* context) + : d_context(context) + { + assert(this->d_context); + } + + auto get_context() const { return this->d_context; } + + auto cancel(beman::net::detail::io_base* cancel_op, beman::net::detail::io_base* op) -> void + { + this->d_context->cancel(cancel_op, op); + } + auto accept(::beman::net::detail::context_base::accept_operation* op) + -> ::beman::net::detail::submit_result + { + return this->d_context->accept(op); + } + auto connect(::beman::net::detail::context_base::connect_operation* op) + -> ::beman::net::detail::submit_result + { + return this->d_context->connect(op); + } + auto receive(::beman::net::detail::context_base::receive_operation* op) + -> ::beman::net::detail::submit_result + { + return this->d_context->receive(op); + } + auto send(::beman::net::detail::context_base::send_operation* op) + -> ::beman::net::detail::submit_result + { + return this->d_context->send(op); + } + auto resume_at(::beman::net::detail::context_base::resume_at_operation* op) + -> ::beman::net::detail::submit_result + { + return this->d_context->resume_at(op); + } +}; + +static_assert(::beman::net::detail::ex::sender< + beman::net::detail::io_context_scheduler::sender + >); +static_assert(::beman::net::detail::ex::scheduler< + beman::net::detail::io_context_scheduler + >); + +// ---------------------------------------------------------------------------- + +#endif diff --git a/include/beman/net29/detail/netfwd.hpp b/include/beman/net/detail/netfwd.hpp similarity index 80% rename from include/beman/net29/detail/netfwd.hpp rename to include/beman/net/detail/netfwd.hpp index 2184585..888dc16 100644 --- a/include/beman/net29/detail/netfwd.hpp +++ b/include/beman/net/detail/netfwd.hpp @@ -1,15 +1,15 @@ -// include/beman/net29/detail/netfwd.hpp -*-C++-*- +// include/beman/net/detail/netfwd.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_NETFWD -#define INCLUDED_BEMAN_NET29_DETAIL_NETFWD +#ifndef INCLUDED_BEMAN_NET_DETAIL_NETFWD +#define INCLUDED_BEMAN_NET_DETAIL_NETFWD #include #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { enum socket_id: ::std::uint_least32_t { @@ -20,7 +20,7 @@ namespace beman::net29::detail inline constexpr native_handle_type invalid_handle{-1}; } -namespace beman::net29 +namespace beman::net { class io_context; class socket_base; diff --git a/include/beman/net29/detail/operations.hpp b/include/beman/net/detail/operations.hpp similarity index 65% rename from include/beman/net29/detail/operations.hpp rename to include/beman/net/detail/operations.hpp index 44737f2..de39221 100644 --- a/include/beman/net29/detail/operations.hpp +++ b/include/beman/net/detail/operations.hpp @@ -1,17 +1,17 @@ -// include/beman/net29/detail/operations.hpp -*-C++-*- +// include/beman/net/detail/operations.hpp -*-C++-*- // ---------------------------------------------------------------------------- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // ---------------------------------------------------------------------------- -#ifndef INCLUDED_INCLUDE_BEMAN_NET29_DETAIL_OPERATIONS -#define INCLUDED_INCLUDE_BEMAN_NET29_DETAIL_OPERATIONS +#ifndef INCLUDED_INCLUDE_BEMAN_NET_DETAIL_OPERATIONS +#define INCLUDED_INCLUDE_BEMAN_NET_DETAIL_OPERATIONS -#include -#include +#include +#include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { struct accept_desc; struct connect_desc; @@ -21,44 +21,44 @@ namespace beman::net29::detail struct receive_from_desc; } -namespace beman::net29 +namespace beman::net { using async_accept_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::accept_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::accept_desc>; inline constexpr async_accept_t async_accept{}; using async_connect_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::connect_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::connect_desc>; inline constexpr async_connect_t async_connect{}; using async_send_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::send_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::send_desc>; inline constexpr async_send_t async_send{}; using async_send_to_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::send_to_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::send_to_desc>; inline constexpr async_send_to_t async_send_to{}; using async_receive_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::receive_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::receive_desc>; inline constexpr async_receive_t async_receive{}; using async_receive_from_t - = ::beman::net29::detail::sender_cpo<::beman::net29::detail::receive_from_desc>; + = ::beman::net::detail::sender_cpo<::beman::net::detail::receive_from_desc>; inline constexpr async_receive_from_t async_receive_from{}; } // ---------------------------------------------------------------------------- -struct beman::net29::detail::accept_desc +struct beman::net::detail::accept_desc { - using operation = ::beman::net29::detail::context_base::accept_operation; + using operation = ::beman::net::detail::context_base::accept_operation; template struct data { using acceptor_t = ::std::remove_cvref_t; using socket_t = acceptor_t::socket_type; using completion_signature - = ::beman::net29::detail::ex::set_value_t( + = ::beman::net::detail::ex::set_value_t( socket_t, typename socket_t::endpoint_type ); @@ -71,12 +71,12 @@ struct beman::net29::detail::accept_desc auto get_scheduler() { return this->d_acceptor.get_scheduler(); } auto set_value(operation& o, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver), + ::beman::net::detail::ex::set_value(::std::move(receiver), socket_t(this->d_acceptor.get_scheduler().get_context(), ::std::move(*::std::get<2>(o))), typename socket_t::endpoint_type(::std::get<0>(o))); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<1>(*base) = sizeof(::std::get<0>(*base)); return this->get_scheduler().accept(base); @@ -84,13 +84,13 @@ struct beman::net29::detail::accept_desc }; }; -struct beman::net29::detail::connect_desc +struct beman::net::detail::connect_desc { - using operation = ::beman::net29::detail::context_base::connect_operation; + using operation = ::beman::net::detail::context_base::connect_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(); + using completion_signature = ::beman::net::detail::ex::set_value_t(); Socket& d_socket; @@ -99,9 +99,9 @@ struct beman::net29::detail::connect_desc auto get_scheduler() { return this->d_socket.get_scheduler(); } auto set_value(operation&, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver)); + ::beman::net::detail::ex::set_value(::std::move(receiver)); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base) = this->d_socket.get_endpoint(); return this->d_socket.get_scheduler().connect(base); @@ -109,13 +109,13 @@ struct beman::net29::detail::connect_desc }; }; -struct beman::net29::detail::send_desc +struct beman::net::detail::send_desc { - using operation = ::beman::net29::detail::context_base::send_operation; + using operation = ::beman::net::detail::context_base::send_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(::std::size_t); + using completion_signature = ::beman::net::detail::ex::set_value_t(::std::size_t); Stream_t& d_stream; Buffers d_buffers; @@ -125,10 +125,10 @@ struct beman::net29::detail::send_desc auto get_scheduler() { return this->d_stream.get_scheduler(); } auto set_value(operation& o, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver), + ::beman::net::detail::ex::set_value(::std::move(receiver), ::std::move(::std::get<2>(o))); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + 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(); @@ -137,13 +137,13 @@ struct beman::net29::detail::send_desc }; }; -struct beman::net29::detail::send_to_desc +struct beman::net::detail::send_to_desc { - using operation = ::beman::net29::detail::context_base::send_operation; + using operation = ::beman::net::detail::context_base::send_operation; template struct Data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(::std::size_t); + using completion_signature = ::beman::net::detail::ex::set_value_t(::std::size_t); Stream_t& d_stream; Buffers d_buffers; @@ -154,9 +154,9 @@ struct beman::net29::detail::send_to_desc auto get_scheduler() { return this->d_stream.get_scheduler(); } auto set_value(operation& o, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); + ::beman::net::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + 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(); @@ -167,13 +167,13 @@ struct beman::net29::detail::send_to_desc }; }; -struct beman::net29::detail::receive_desc +struct beman::net::detail::receive_desc { - using operation = ::beman::net29::detail::context_base::receive_operation; + using operation = ::beman::net::detail::context_base::receive_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(::std::size_t); + using completion_signature = ::beman::net::detail::ex::set_value_t(::std::size_t); Stream_t& d_stream; Buffers d_buffers; @@ -183,9 +183,9 @@ struct beman::net29::detail::receive_desc auto get_scheduler() { return this->d_stream.get_scheduler(); } auto set_value(operation& o, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); + ::beman::net::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + 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(); @@ -194,13 +194,13 @@ struct beman::net29::detail::receive_desc }; }; -struct beman::net29::detail::receive_from_desc +struct beman::net::detail::receive_from_desc { - using operation = ::beman::net29::detail::context_base::receive_operation; + using operation = ::beman::net::detail::context_base::receive_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(::std::size_t); + using completion_signature = ::beman::net::detail::ex::set_value_t(::std::size_t); Stream_t& d_stream; Buffers d_buffers; @@ -211,9 +211,9 @@ struct beman::net29::detail::receive_from_desc auto get_scheduler() { return this->d_stream.get_scheduler(); } auto set_value(operation& o, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); + ::beman::net::detail::ex::set_value(::std::move(receiver), ::std::get<2>(o)); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + 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(); diff --git a/include/beman/net29/detail/poll_context.hpp b/include/beman/net/detail/poll_context.hpp similarity index 67% rename from include/beman/net29/detail/poll_context.hpp rename to include/beman/net/detail/poll_context.hpp index bcac9c9..54068af 100644 --- a/include/beman/net29/detail/poll_context.hpp +++ b/include/beman/net/detail/poll_context.hpp @@ -1,15 +1,15 @@ -// include/beman/net29/detail/poll_context.hpp -*-C++-*- +// include/beman/net/detail/poll_context.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_POLL_CONTEXT -#define INCLUDED_BEMAN_NET29_DETAIL_POLL_CONTEXT +#ifndef INCLUDED_BEMAN_NET_DETAIL_POLL_CONTEXT +#define INCLUDED_BEMAN_NET_DETAIL_POLL_CONTEXT // ---------------------------------------------------------------------------- -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -19,7 +19,7 @@ // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { struct poll_record; struct poll_context; @@ -27,58 +27,58 @@ namespace beman::net29::detail // ---------------------------------------------------------------------------- -struct beman::net29::detail::poll_record final +struct beman::net::detail::poll_record final { - poll_record(::beman::net29::detail::native_handle_type h): handle(h) {} - ::beman::net29::detail::native_handle_type handle; + poll_record(::beman::net::detail::native_handle_type h): handle(h) {} + ::beman::net::detail::native_handle_type handle; bool blocking{true}; }; // ---------------------------------------------------------------------------- -struct beman::net29::detail::poll_context final - : ::beman::net29::detail::context_base +struct beman::net::detail::poll_context final + : ::beman::net::detail::context_base { using time_t = ::std::chrono::system_clock::time_point; - using timer_node_t = ::beman::net29::detail::context_base::resume_at_operation; + using timer_node_t = ::beman::net::detail::context_base::resume_at_operation; struct get_time { auto operator()(auto* t) const -> time_t { return ::std::get<0>(*t); } }; using timer_priority_t - = ::beman::net29::detail::sorted_list< timer_node_t, ::std::less<>, get_time>; - ::beman::net29::detail::container<::beman::net29::detail::poll_record> d_sockets; + = ::beman::net::detail::sorted_list< timer_node_t, ::std::less<>, get_time>; + ::beman::net::detail::container<::beman::net::detail::poll_record> d_sockets; ::std::vector<::pollfd> d_poll; - ::std::vector<::beman::net29::detail::io_base*> d_outstanding; + ::std::vector<::beman::net::detail::io_base*> d_outstanding; timer_priority_t d_timeouts; - ::beman::net29::detail::context_base::task* d_tasks{}; + ::beman::net::detail::context_base::task* d_tasks{}; - auto make_socket(int fd) -> ::beman::net29::detail::socket_id override final + auto make_socket(int fd) -> ::beman::net::detail::socket_id override final { return this->d_sockets.insert(fd); } auto make_socket(int d, int t, int p, ::std::error_code& error) - -> ::beman::net29::detail::socket_id override final + -> ::beman::net::detail::socket_id override final { int fd(::socket(d, t, p)); if (fd < 0) { error = ::std::error_code(errno, ::std::system_category()); - return ::beman::net29::detail::socket_id::invalid; + return ::beman::net::detail::socket_id::invalid; } return this->make_socket(fd); } - auto release(::beman::net29::detail::socket_id id, ::std::error_code& error) -> void override final + auto release(::beman::net::detail::socket_id id, ::std::error_code& error) -> void override final { - ::beman::net29::detail::native_handle_type handle(this->d_sockets[id].handle); + ::beman::net::detail::native_handle_type handle(this->d_sockets[id].handle); this->d_sockets.erase(id); if (::close(handle) < 0) { error = ::std::error_code(errno, ::std::system_category()); } } - auto native_handle(::beman::net29::detail::socket_id id) -> ::beman::net29::detail::native_handle_type override final + auto native_handle(::beman::net::detail::socket_id id) -> ::beman::net::detail::native_handle_type override final { return this->d_sockets[id].handle; } - auto set_option(::beman::net29::detail::socket_id id, + auto set_option(::beman::net::detail::socket_id id, int level, int name, void const* data, @@ -90,8 +90,8 @@ struct beman::net29::detail::poll_context final error = ::std::error_code(errno, ::std::system_category()); } } - auto bind(::beman::net29::detail::socket_id id, - ::beman::net29::detail::endpoint const& endpoint, + auto bind(::beman::net::detail::socket_id id, + ::beman::net::detail::endpoint const& endpoint, ::std::error_code& error) -> void override final { if (::bind(this->native_handle(id), endpoint.data(), endpoint.size()) < 0) @@ -99,7 +99,7 @@ struct beman::net29::detail::poll_context final error = ::std::error_code(errno, ::std::system_category()); } } - auto listen(::beman::net29::detail::socket_id id, int no, ::std::error_code& error) -> void override final + auto listen(::beman::net::detail::socket_id id, int no, ::std::error_code& error) -> void override final { if (::listen(this->native_handle(id), no) < 0) { @@ -176,7 +176,7 @@ struct beman::net29::detail::poll_context final { if (this->d_poll[i].revents & (this->d_poll[i].events | POLLERR)) { - ::beman::net29::detail::io_base* completion = this->d_outstanding[i]; + ::beman::net::detail::io_base* completion = this->d_outstanding[i]; this->remove_outstanding(i); completion->work(*this, completion); return ::std::size_t(1); @@ -195,22 +195,22 @@ struct beman::net29::detail::poll_context final //-dk:TODO wake-up polling thread } - auto add_outstanding(::beman::net29::detail::io_base* completion) - -> ::beman::net29::detail::submit_result + auto add_outstanding(::beman::net::detail::io_base* completion) + -> ::beman::net::detail::submit_result { auto id{completion->id}; if (this->d_sockets[id].blocking - || completion->work(*this, completion) == ::beman::net29::detail::submit_result::submit) + || completion->work(*this, completion) == ::beman::net::detail::submit_result::submit) { this->d_poll.emplace_back(::pollfd{this->native_handle(id), short(completion->event), short()}); this->d_outstanding.emplace_back(completion); this->wakeup(); - return ::beman::net29::detail::submit_result::submit; + return ::beman::net::detail::submit_result::submit; } - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } - auto cancel(::beman::net29::detail::io_base* cancel_op, ::beman::net29::detail::io_base* op) -> void override final + auto cancel(::beman::net::detail::io_base* cancel_op, ::beman::net::detail::io_base* op) -> void override final { auto it(::std::find(this->d_outstanding.begin(), this->d_outstanding.end(), op)); if (it != this->d_outstanding.end()) @@ -229,17 +229,17 @@ struct beman::net29::detail::poll_context final std::cerr << "ERROR: poll_context::cancel(): entity not cancelled!\n"; } } - auto schedule(::beman::net29::detail::context_base::task* task) -> void override + auto schedule(::beman::net::detail::context_base::task* task) -> void override { task->next = this->d_tasks; this->d_tasks = task; } - auto accept(::beman::net29::detail::context_base::accept_operation* completion) - -> ::beman::net29::detail::submit_result override final + auto accept(::beman::net::detail::context_base::accept_operation* completion) + -> ::beman::net::detail::submit_result override final { completion->work = - [](::beman::net29::detail::context_base& ctxt, - ::beman::net29::detail::io_base* comp) + [](::beman::net::detail::context_base& ctxt, + ::beman::net::detail::io_base* comp) { auto id{comp->id}; auto& completion(*static_cast(comp)); @@ -251,7 +251,7 @@ struct beman::net29::detail::poll_context final { ::std::get<2>(completion) = ctxt.make_socket(rc); completion.complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } else { @@ -259,45 +259,45 @@ struct beman::net29::detail::poll_context final { default: completion.error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; case EINTR: break; case EWOULDBLOCK: - return ::beman::net29::detail::submit_result::submit; + return ::beman::net::detail::submit_result::submit; } } } }; return this->add_outstanding(completion); } - auto connect(::beman::net29::detail::context_base::connect_operation* op) - -> ::beman::net29::detail::submit_result override + auto connect(::beman::net::detail::context_base::connect_operation* op) + -> ::beman::net::detail::submit_result override { auto handle{this->native_handle(op->id)}; auto const& endpoint(::std::get<0>(*op)); if (-1 == ::fcntl(handle, F_SETFL, O_NONBLOCK)) { op->error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; } if (0 == ::connect(handle, endpoint.data(), endpoint.size())) { op->complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } switch (errno) { default: op->error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; case EINPROGRESS: case EINTR: break; } op->context = this; - op->work = [](::beman::net29::detail::context_base& ctxt, - ::beman::net29::detail::io_base* op) + op->work = [](::beman::net::detail::context_base& ctxt, + ::beman::net::detail::io_base* op) { auto handle{ctxt.native_handle(op->id)}; @@ -306,28 +306,28 @@ struct beman::net29::detail::poll_context final if (-1 == ::getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &len)) { op->error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; } if (0 == error) { op->complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } else { op->error(::std::error_code(error, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; } }; return this->add_outstanding(op); } - auto receive(::beman::net29::detail::context_base::receive_operation* op) - -> ::beman::net29::detail::submit_result override + auto receive(::beman::net::detail::context_base::receive_operation* op) + -> ::beman::net::detail::submit_result override { op->context = this; - op->work = [](::beman::net29::detail::context_base& ctxt, - ::beman::net29::detail::io_base* op) + op->work = [](::beman::net::detail::context_base& ctxt, + ::beman::net::detail::io_base* op) { auto& completion(*static_cast(op)); while (true) @@ -339,33 +339,33 @@ struct beman::net29::detail::poll_context final { ::std::get<2>(completion) = rc; completion.complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } else switch (errno) { default: completion.error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; case ECONNRESET: case EPIPE: ::std::get<2>(completion) = 0u; completion.complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; case EINTR: break; case EWOULDBLOCK: - return ::beman::net29::detail::submit_result::submit; + return ::beman::net::detail::submit_result::submit; } } }; return this->add_outstanding(op); } - auto send(::beman::net29::detail::context_base::send_operation* op) - -> ::beman::net29::detail::submit_result override + auto send(::beman::net::detail::context_base::send_operation* op) + -> ::beman::net::detail::submit_result override { op->context = this; - op->work = [](::beman::net29::detail::context_base& ctxt, - ::beman::net29::detail::io_base* op) + op->work = [](::beman::net::detail::context_base& ctxt, + ::beman::net::detail::io_base* op) { auto& completion(*static_cast(op)); @@ -378,38 +378,38 @@ struct beman::net29::detail::poll_context final { ::std::get<2>(completion) = rc; completion.complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } else switch (errno) { default: completion.error(::std::error_code(errno, ::std::system_category())); - return ::beman::net29::detail::submit_result::error; + return ::beman::net::detail::submit_result::error; case ECONNRESET: case EPIPE: ::std::get<2>(completion) = 0u; completion.complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; case EINTR: break; case EWOULDBLOCK: - return ::beman::net29::detail::submit_result::submit; + return ::beman::net::detail::submit_result::submit; } } }; return this->add_outstanding(op); } - auto resume_at(::beman::net29::detail::context_base::resume_at_operation* op) -> ::beman::net29::detail::submit_result override + auto resume_at(::beman::net::detail::context_base::resume_at_operation* op) -> ::beman::net::detail::submit_result override { if (::std::chrono::system_clock::now() < ::std::get<0>(*op)) { this->d_timeouts.insert(op); - return ::beman::net29::detail::submit_result::submit; + return ::beman::net::detail::submit_result::submit; } else { op->complete(); - return ::beman::net29::detail::submit_result::ready; + return ::beman::net::detail::submit_result::ready; } } }; diff --git a/include/beman/net29/detail/sender.hpp b/include/beman/net/detail/sender.hpp similarity index 59% rename from include/beman/net29/detail/sender.hpp rename to include/beman/net/detail/sender.hpp index 1dafb72..460cdfd 100644 --- a/include/beman/net29/detail/sender.hpp +++ b/include/beman/net/detail/sender.hpp @@ -1,12 +1,12 @@ -// include/beman/net29/detail/sender.hpp -*-C++-*- +// include/beman/net/detail/sender.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_SENDER -#define INCLUDED_BEMAN_NET29_DETAIL_SENDER +#ifndef INCLUDED_BEMAN_NET_DETAIL_SENDER +#define INCLUDED_BEMAN_NET_DETAIL_SENDER -#include -#include -#include +#include +#include +#include #include #include #include @@ -14,16 +14,16 @@ // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { - template <::beman::net29::detail::ex::receiver> + template <::beman::net::detail::ex::receiver> struct sender_state_base; - template <::beman::net29::detail::ex::receiver> + template <::beman::net::detail::ex::receiver> struct sender_upstream_receiver; - template + template struct sender_state; - template + template struct sender; template struct sender_cpo; @@ -31,13 +31,13 @@ namespace beman::net29::detail // ---------------------------------------------------------------------------- -template <::beman::net29::detail::ex::receiver Receiver> -struct beman::net29::detail::sender_state_base +template <::beman::net::detail::ex::receiver Receiver> +struct beman::net::detail::sender_state_base { Receiver d_receiver; ::std::atomic d_outstanding{}; - template <::beman::net29::detail::ex::receiver R> + template <::beman::net::detail::ex::receiver R> sender_state_base(R&& r) : d_receiver(::std::forward(r)) { @@ -45,11 +45,11 @@ struct beman::net29::detail::sender_state_base virtual auto start() & noexcept -> void = 0; }; -template <::beman::net29::detail::ex::receiver Receiver> -struct beman::net29::detail::sender_upstream_receiver +template <::beman::net::detail::ex::receiver Receiver> +struct beman::net::detail::sender_upstream_receiver { - using receiver_concept = ::beman::net29::detail::ex::receiver_t; - ::beman::net29::detail::sender_state_base* d_state; + using receiver_concept = ::beman::net::detail::ex::receiver_t; + ::beman::net::detail::sender_state_base* d_state; auto set_value() && noexcept -> void { @@ -58,38 +58,38 @@ struct beman::net29::detail::sender_upstream_receiver template auto set_error(Error&& error) && noexcept -> void { - ::beman::net29::detail::ex::set_error( + ::beman::net::detail::ex::set_error( ::std::move(this->d_state->d_receiver), ::std::forward(error) ); } auto set_stopped() && noexcept -> void { - ::beman::net29::detail::ex::set_stopped( + ::beman::net::detail::ex::set_stopped( ::std::move(this->d_state->d_receiver) ); } auto get_env() const noexcept { - return ::beman::net29::detail::ex::get_env(this->d_state->d_receiver); + return ::beman::net::detail::ex::get_env(this->d_state->d_receiver); } }; template -struct beman::net29::detail::sender_state + ::beman::net::detail::ex::receiver Receiver, + ::beman::net::detail::ex::sender UpstreamSender> +struct beman::net::detail::sender_state : Desc::operation - , ::beman::net29::detail::sender_state_base + , ::beman::net::detail::sender_state_base { - using operation_state_concept = ::beman::net29::detail::ex::operation_state_t; + using operation_state_concept = ::beman::net::detail::ex::operation_state_t; struct cancel_callback - : ::beman::net29::detail::io_base + : ::beman::net::detail::io_base { sender_state* d_state; cancel_callback(sender_state* s) - : ::beman::net29::detail::io_base(::beman::net29::detail::socket_id(), 0) + : ::beman::net::detail::io_base(::beman::net::detail::socket_id(), 0) , d_state(s) { } @@ -104,7 +104,7 @@ struct beman::net29::detail::sender_state { if (0u == --this->d_state->d_outstanding) { - ::beman::net29::detail::ex::set_stopped( + ::beman::net::detail::ex::set_stopped( ::std::move(this->d_state->d_receiver) ); } @@ -119,14 +119,14 @@ struct beman::net29::detail::sender_state } }; using upstream_state_t = decltype( - ::beman::net29::detail::ex::connect( + ::beman::net::detail::ex::connect( ::std::declval(), ::std::declval>() ) ); using stop_token = decltype( - ::beman::net29::detail::ex::get_stop_token( - ::beman::net29::detail::ex::get_env(::std::declval()) + ::beman::net::detail::ex::get_stop_token( + ::beman::net::detail::ex::get_env(::std::declval()) ) ); using callback = typename stop_token::template callback_type; @@ -135,20 +135,20 @@ struct beman::net29::detail::sender_state upstream_state_t d_state; ::std::optional d_callback; - template + template sender_state(D&& d, R&& r, UpstreamSender up) : Desc::operation(d.id(), d.events()) , sender_state_base(::std::forward(r)) , d_data(::std::forward(d)) - , d_state(::beman::net29::detail::ex::connect( + , d_state(::beman::net::detail::ex::connect( up, sender_upstream_receiver{this})) { } auto start() & noexcept -> void override { - auto token(::beman::net29::detail::ex::get_stop_token( - ::beman::net29::detail::ex::get_env(this->d_receiver) + auto token(::beman::net::detail::ex::get_stop_token( + ::beman::net::detail::ex::get_env(this->d_receiver) ) ); static_assert(not std::same_as); @@ -160,7 +160,7 @@ struct beman::net29::detail::sender_state this->cancel(); return; } - if (this->d_data.submit(this) == ::beman::net29::detail::submit_result::ready) + if (this->d_data.submit(this) == ::beman::net::detail::submit_result::ready) { this->complete(); } @@ -178,7 +178,7 @@ struct beman::net29::detail::sender_state d_callback.reset(); if (0 == --this->d_outstanding) { - ::beman::net29::detail::ex::set_error( + ::beman::net::detail::ex::set_error( ::std::move(this->d_receiver), std::move(err) ); @@ -188,39 +188,39 @@ struct beman::net29::detail::sender_state { if (0 == --this->d_outstanding) { - ::beman::net29::detail::ex::set_stopped(::std::move(this->d_receiver)); + ::beman::net::detail::ex::set_stopped(::std::move(this->d_receiver)); } } }; -template -struct beman::net29::detail::sender +template +struct beman::net::detail::sender { - using sender_concept = ::beman::net29::detail::ex::sender_t; + using sender_concept = ::beman::net::detail::ex::sender_t; using completion_signatures - = ::beman::net29::detail::ex::completion_signatures< + = ::beman::net::detail::ex::completion_signatures< typename Data::completion_signature, - ::beman::net29::detail::ex::set_error_t(::std::error_code), - ::beman::net29::detail::ex::set_stopped_t() + ::beman::net::detail::ex::set_error_t(::std::error_code), + ::beman::net::detail::ex::set_stopped_t() >; Data d_data; Upstream d_upstream; - template <::beman::net29::detail::ex::receiver Receiver> + template <::beman::net::detail::ex::receiver Receiver> auto connect(Receiver&& receiver) const& { - return ::beman::net29::detail::sender_state, Upstream>( this->d_data, ::std::forward(receiver), this->d_upstream ); } - template <::beman::net29::detail::ex::receiver Receiver> + template <::beman::net::detail::ex::receiver Receiver> auto connect(Receiver&& receiver) && { - return ::beman::net29::detail::sender_state, Upstream>( this->d_data, ::std::forward(receiver), @@ -230,24 +230,24 @@ struct beman::net29::detail::sender }; template -struct beman::net29::detail::sender_cpo +struct beman::net::detail::sender_cpo { template - requires (!::beman::net29::detail::ex::sender<::std::remove_cvref_t>) + requires (!::beman::net::detail::ex::sender<::std::remove_cvref_t>) && ::std::invocable auto operator()(Arg0&& arg0, Args&&... args) const { - return (*this)(::beman::net29::detail::ex::just(), + return (*this)(::beman::net::detail::ex::just(), ::std::forward(arg0), ::std::forward(args)...); } - template <::beman::net29::detail::ex::sender Upstream, typename... Args> + template <::beman::net::detail::ex::sender Upstream, typename... Args> auto operator()(Upstream&& u, Args&&... args) const { using data = Desc::template data<::std::decay_t...>; - return ::beman::net29::detail::sender>{ + return ::beman::net::detail::sender>{ data{::std::forward(args)...}, ::std::forward(u) }; diff --git a/include/beman/net29/detail/socket_base.hpp b/include/beman/net/detail/socket_base.hpp similarity index 90% rename from include/beman/net29/detail/socket_base.hpp rename to include/beman/net/detail/socket_base.hpp index d25c953..ab5a0ae 100644 --- a/include/beman/net29/detail/socket_base.hpp +++ b/include/beman/net/detail/socket_base.hpp @@ -1,17 +1,17 @@ -// include/beman/net29/detail/socket_base.hpp -*-C++-*- +// include/beman/net/detail/socket_base.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_SOCKET_BASE -#define INCLUDED_BEMAN_NET29_DETAIL_SOCKET_BASE +#ifndef INCLUDED_BEMAN_NET_DETAIL_SOCKET_BASE +#define INCLUDED_BEMAN_NET_DETAIL_SOCKET_BASE // ---------------------------------------------------------------------------- -#include +#include #include // ---------------------------------------------------------------------------- -class beman::net29::socket_base +class beman::net::socket_base { public: template diff --git a/include/beman/net29/detail/socket_category.hpp b/include/beman/net/detail/socket_category.hpp similarity index 60% rename from include/beman/net29/detail/socket_category.hpp rename to include/beman/net/detail/socket_category.hpp index 6927509..249b7b8 100644 --- a/include/beman/net29/detail/socket_category.hpp +++ b/include/beman/net/detail/socket_category.hpp @@ -1,14 +1,14 @@ -// include/beman/net29/detail/socket_category.hpp -*-C++-*- +// include/beman/net/detail/socket_category.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_SOCKET_CATEGORY -#define INCLUDED_BEMAN_NET29_DETAIL_SOCKET_CATEGORY +#ifndef INCLUDED_BEMAN_NET_DETAIL_SOCKET_CATEGORY +#define INCLUDED_BEMAN_NET_DETAIL_SOCKET_CATEGORY #include // ---------------------------------------------------------------------------- -namespace beman::net29 +namespace beman::net { enum class socket_errc: int; auto socket_category() noexcept -> ::std::error_category const&; @@ -16,13 +16,13 @@ namespace beman::net29 // ---------------------------------------------------------------------------- -enum class beman::net29::socket_errc: int +enum class beman::net::socket_errc: int { already_open = 1, not_found }; -auto beman::net29::socket_category() noexcept -> ::std::error_category const& +auto beman::net::socket_category() noexcept -> ::std::error_category const& { struct category : ::std::error_category @@ -30,11 +30,11 @@ auto beman::net29::socket_category() noexcept -> ::std::error_category const& auto name() const noexcept -> char const* override final { return "socket"; } auto message(int error) const -> ::std::string override final { - switch (::beman::net29::socket_errc(error)) + switch (::beman::net::socket_errc(error)) { default: return "none"; - case ::beman::net29::socket_errc::already_open: return "already open"; - case ::beman::net29::socket_errc::not_found: return "not found"; + case ::beman::net::socket_errc::already_open: return "already open"; + case ::beman::net::socket_errc::not_found: return "not found"; } } }; diff --git a/include/beman/net29/detail/sorted_list.hpp b/include/beman/net/detail/sorted_list.hpp similarity index 79% rename from include/beman/net29/detail/sorted_list.hpp rename to include/beman/net/detail/sorted_list.hpp index 98daf52..8cdfed6 100644 --- a/include/beman/net29/detail/sorted_list.hpp +++ b/include/beman/net/detail/sorted_list.hpp @@ -1,15 +1,15 @@ -// include/beman/net29/detail/sorted_list.hpp -*-C++-*- +// include/beman/net/detail/sorted_list.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_SORTED_LIST -#define INCLUDED_BEMAN_NET29_DETAIL_SORTED_LIST +#ifndef INCLUDED_BEMAN_NET_DETAIL_SORTED_LIST +#define INCLUDED_BEMAN_NET_DETAIL_SORTED_LIST #include #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { template , typename = decltype([](T* n){ return n->value; })> struct sorted_list; @@ -18,7 +18,7 @@ namespace beman::net29::detail // ---------------------------------------------------------------------------- template -struct beman::net29::detail::sorted_list +struct beman::net::detail::sorted_list { using next_t = decltype(::std::declval().next); @@ -38,7 +38,7 @@ struct beman::net29::detail::sorted_list }; template -auto beman::net29::detail::sorted_list::pop_front() -> T* +auto beman::net::detail::sorted_list::pop_front() -> T* { next_t rc{this->head}; this->head = rc->next; @@ -46,7 +46,7 @@ auto beman::net29::detail::sorted_list::pop_front() -> T* } template -auto beman::net29::detail::sorted_list::insert(T* node) -> T* +auto beman::net::detail::sorted_list::insert(T* node) -> T* { next_t* it{&this->head}; while (*it != nullptr && this->comp(this->value(*it), this->value(node))) @@ -57,7 +57,7 @@ auto beman::net29::detail::sorted_list::insert(T* node) -> T* } template -auto beman::net29::detail::sorted_list::erase(next_t node) -> next_t +auto beman::net::detail::sorted_list::erase(next_t node) -> next_t { next_t* it{&this->head}; while (*it != node && *it != nullptr) diff --git a/include/beman/net29/detail/stop_token.hpp b/include/beman/net/detail/stop_token.hpp similarity index 72% rename from include/beman/net29/detail/stop_token.hpp rename to include/beman/net/detail/stop_token.hpp index 0d7b483..503529b 100644 --- a/include/beman/net29/detail/stop_token.hpp +++ b/include/beman/net/detail/stop_token.hpp @@ -1,14 +1,14 @@ -// include/beman/net29/detail/stop_token.hpp -*-C++-*- +// include/beman/net/detail/stop_token.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_STOP_TOKEN -#define INCLUDED_BEMAN_NET29_DETAIL_STOP_TOKEN +#ifndef INCLUDED_BEMAN_NET_DETAIL_STOP_TOKEN +#define INCLUDED_BEMAN_NET_DETAIL_STOP_TOKEN #include // ---------------------------------------------------------------------------- -namespace beman::net29::detail::ex +namespace beman::net::detail::ex { using ::beman::execution26::never_stop_token; using ::beman::execution26::inplace_stop_source; diff --git a/include/beman/net29/detail/timer.hpp b/include/beman/net/detail/timer.hpp similarity index 57% rename from include/beman/net29/detail/timer.hpp rename to include/beman/net/detail/timer.hpp index 16a20b3..fb2073f 100644 --- a/include/beman/net29/detail/timer.hpp +++ b/include/beman/net/detail/timer.hpp @@ -1,26 +1,26 @@ -// include/beman/net29/detail/timer.hpp -*-C++-*- +// include/beman/net/detail/timer.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_DETAIL_TIMER -#define INCLUDED_BEMAN_NET29_DETAIL_TIMER +#ifndef INCLUDED_BEMAN_NET_DETAIL_TIMER +#define INCLUDED_BEMAN_NET_DETAIL_TIMER // ---------------------------------------------------------------------------- -#include -#include +#include +#include // ---------------------------------------------------------------------------- -namespace beman::net29::detail +namespace beman::net::detail { struct resume_after_desc; struct resume_at_desc; } -namespace beman::net29 +namespace beman::net { - using async_resume_after_t = ::beman::net29::detail::sender_cpo<::beman::net29::detail::resume_after_desc>; - using async_resume_at_t = ::beman::net29::detail::sender_cpo<::beman::net29::detail::resume_at_desc>; + using async_resume_after_t = ::beman::net::detail::sender_cpo<::beman::net::detail::resume_after_desc>; + using async_resume_at_t = ::beman::net::detail::sender_cpo<::beman::net::detail::resume_at_desc>; inline constexpr async_resume_after_t resume_after{}; inline constexpr async_resume_at_t resume_at{}; @@ -28,25 +28,25 @@ namespace beman::net29 // ---------------------------------------------------------------------------- -struct beman::net29::detail::resume_after_desc +struct beman::net::detail::resume_after_desc { - using operation = ::beman::net29::detail::context_base::resume_after_operation; + using operation = ::beman::net::detail::context_base::resume_after_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(); + using completion_signature = ::beman::net::detail::ex::set_value_t(); ::std::remove_cvref_t d_scheduler; ::std::chrono::microseconds d_duration; - auto id() const -> ::beman::net29::detail::socket_id { return {}; } + auto id() const -> ::beman::net::detail::socket_id { return {}; } auto events() const { return decltype(POLLIN)(); } auto get_scheduler() { return this->d_scheduler; } auto set_value(operation&, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver)); + ::beman::net::detail::ex::set_value(::std::move(receiver)); } - auto submit(auto* base) -> ::beman::net29::detail::submit_result + auto submit(auto* base) -> ::beman::net::detail::submit_result { ::std::get<0>(*base) = ::std::chrono::system_clock::now() + this->d_duration; return this->d_scheduler.resume_at(base); @@ -56,23 +56,23 @@ struct beman::net29::detail::resume_after_desc // ---------------------------------------------------------------------------- -struct beman::net29::detail::resume_at_desc +struct beman::net::detail::resume_at_desc { - using operation = ::beman::net29::detail::context_base::resume_at_operation; + using operation = ::beman::net::detail::context_base::resume_at_operation; template struct data { - using completion_signature = ::beman::net29::detail::ex::set_value_t(); + using completion_signature = ::beman::net::detail::ex::set_value_t(); ::std::remove_cvref_t d_scheduler; ::std::chrono::system_clock::time_point d_time; - auto id() const -> ::beman::net29::detail::socket_id { return {}; } + auto id() const -> ::beman::net::detail::socket_id { return {}; } auto events() const { return decltype(POLLIN)(); } auto get_scheduler() { return this->d_scheduler; } auto set_value(operation&, auto&& receiver) { - ::beman::net29::detail::ex::set_value(::std::move(receiver)); + ::beman::net::detail::ex::set_value(::std::move(receiver)); } auto submit(auto* base) -> bool { diff --git a/include/beman/net/net.hpp b/include/beman/net/net.hpp new file mode 100644 index 0000000..0566f62 --- /dev/null +++ b/include/beman/net/net.hpp @@ -0,0 +1,30 @@ +// include/beman/net/net.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_NET_NET +#define INCLUDED_BEMAN_NET_NET + +// ---------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +#endif diff --git a/include/beman/net29/detail/basic_socket.hpp b/include/beman/net29/detail/basic_socket.hpp deleted file mode 100644 index e21349e..0000000 --- a/include/beman/net29/detail/basic_socket.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// include/beman/net29/detail/basic_socket.hpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef INCLUDED_BEMAN_NET29_DETAIL_BASIC_SOCKET -#define INCLUDED_BEMAN_NET29_DETAIL_BASIC_SOCKET - -// ---------------------------------------------------------------------------- - -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- - -template -class beman::net29::basic_socket - : public ::beman::net29::socket_base -{ -public: - using scheduler_type = ::beman::net29::detail::io_context_scheduler; - using protocol_type = Protocol; - -private: - ::beman::net29::detail::context_base* d_context; - protocol_type d_protocol{::beman::net29::ip::tcp::v6()}; - ::beman::net29::detail::socket_id d_id{::beman::net29::detail::socket_id::invalid}; - -public: - basic_socket() - : d_context(nullptr) - { - } - basic_socket(::beman::net29::detail::context_base* context, ::beman::net29::detail::socket_id id) - : d_context(context) - , d_id(id) - { - } - basic_socket(basic_socket&& other) - : d_context(other.d_context) - , d_protocol(other.d_protocol) - , d_id(::std::exchange(other.d_id, ::beman::net29::detail::socket_id::invalid)) - { - } - ~basic_socket() - { - if (this->d_id != ::beman::net29::detail::socket_id::invalid) - { - ::std::error_code error{}; - this->d_context->release(this->d_id, error); - } - } - auto get_scheduler() noexcept -> scheduler_type - { - return scheduler_type{this->d_context}; - } - auto id() const -> ::beman::net29::detail::socket_id { return this->d_id; } -}; - - -// ---------------------------------------------------------------------------- - -#endif diff --git a/include/beman/net29/detail/context_base.hpp b/include/beman/net29/detail/context_base.hpp deleted file mode 100644 index 440dd55..0000000 --- a/include/beman/net29/detail/context_base.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// include/beman/net29/detail/context_base.hpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef INCLUDED_BEMAN_NET29_DETAIL_CONTEXT_BASE -#define INCLUDED_BEMAN_NET29_DETAIL_CONTEXT_BASE - -#include -#include -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- - -namespace beman::net29::detail -{ - struct context_base; -} - -// ---------------------------------------------------------------------------- - -struct beman::net29::detail::context_base -{ - struct task - { - task* next; - virtual auto complete() -> void = 0; - }; - - using accept_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::beman::net29::detail::endpoint, - ::socklen_t, - ::std::optional<::beman::net29::detail::socket_id> - > - >; - using connect_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::beman::net29::detail::endpoint> - >; - using receive_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::msghdr, int, ::std::size_t> - >; - using send_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::msghdr, int, ::std::size_t> - >; - using resume_after_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::std::chrono::system_clock::time_point, ::timeval> - >; - using resume_at_operation = ::beman::net29::detail::io_operation< - ::std::tuple<::std::chrono::system_clock::time_point, ::timeval> - >; - - virtual ~context_base() = default; - virtual auto make_socket(int) -> ::beman::net29::detail::socket_id = 0; - virtual auto make_socket(int, int, int, ::std::error_code&) -> ::beman::net29::detail::socket_id = 0; - virtual auto release(::beman::net29::detail::socket_id, ::std::error_code&) -> void = 0; - virtual auto native_handle(::beman::net29::detail::socket_id) -> ::beman::net29::detail::native_handle_type = 0; - virtual auto set_option(::beman::net29::detail::socket_id, int, int, void const*, ::socklen_t, ::std::error_code&) -> void = 0; - virtual auto bind(::beman::net29::detail::socket_id, ::beman::net29::detail::endpoint const&, ::std::error_code&) -> void = 0; - virtual auto listen(::beman::net29::detail::socket_id, int, ::std::error_code&) -> void = 0; - - virtual auto run_one() -> ::std::size_t = 0; - - virtual auto cancel(::beman::net29::detail::io_base*, ::beman::net29::detail::io_base*) -> void = 0; - virtual auto schedule(::beman::net29::detail::context_base::task*) -> void = 0; - virtual auto accept(::beman::net29::detail::context_base::accept_operation*) - -> ::beman::net29::detail::submit_result = 0; - virtual auto connect(::beman::net29::detail::context_base::connect_operation*) - -> ::beman::net29::detail::submit_result = 0; - virtual auto receive(::beman::net29::detail::context_base::receive_operation*) - -> ::beman::net29::detail::submit_result = 0; - virtual auto send(::beman::net29::detail::context_base::send_operation*) - -> ::beman::net29::detail::submit_result = 0; - virtual auto resume_at(::beman::net29::detail::context_base::resume_at_operation*) - -> ::beman::net29::detail::submit_result = 0; -}; - -// ---------------------------------------------------------------------------- - -#endif diff --git a/include/beman/net29/detail/io_context_scheduler.hpp b/include/beman/net29/detail/io_context_scheduler.hpp deleted file mode 100644 index fb72df8..0000000 --- a/include/beman/net29/detail/io_context_scheduler.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// include/beman/net29/detail/io_context_scheduler.hpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef INCLUDED_BEMAN_NET29_DETAIL_IO_CONTEXT_SCHEDULER -#define INCLUDED_BEMAN_NET29_DETAIL_IO_CONTEXT_SCHEDULER - -// ---------------------------------------------------------------------------- - -#include -#include -#include - -// ---------------------------------------------------------------------------- - -namespace beman::net29::detail -{ - class io_context_scheduler; -} - -// ---------------------------------------------------------------------------- - -class beman::net29::detail::io_context_scheduler -{ -private: - ::beman::net29::detail::context_base* d_context; - -public: - using scheduler_concept = ::beman::net29::detail::ex::scheduler_t; - - struct env - { - ::beman::net29::detail::context_base* d_context; - - template - auto query(::beman::net29::detail::ex::get_completion_scheduler_t const&) const noexcept - -> io_context_scheduler - { - return this->d_context; - } - }; - struct sender - { - template - struct state - : ::beman::net29::detail::context_base::task - { - using operation_state_concept = ::beman::net29::detail::ex::operation_state_t; - - ::std::remove_cvref_t d_receiver; - ::beman::net29::detail::context_base* d_context; - - state(Receiver&& receiver, ::beman::net29::detail::context_base* context) - : d_receiver(::std::forward(receiver)) - , d_context(context) - { - } - - auto start() & noexcept -> void - { - this->d_context->schedule(this); - } - auto complete() -> void override - { - ::beman::net29::detail::ex::set_value(::std::move(this->d_receiver)); - } - }; - - using sender_concept = ::beman::net29::detail::ex::sender_t; - ::beman::net29::detail::context_base* d_context; - - template - auto connect(Receiver&& receiver) -> state - { - return {::std::forward(receiver), this->d_context}; - } - - auto get_env() const noexcept -> env { return {this->d_context}; } - }; - - auto schedule() noexcept -> sender { return {this->d_context}; } - auto operator== (io_context_scheduler const&) const -> bool = default; - - io_context_scheduler(::beman::net29::detail::context_base* context) - : d_context(context) - { - assert(this->d_context); - } - - auto get_context() const { return this->d_context; } - - auto cancel(beman::net29::detail::io_base* cancel_op, beman::net29::detail::io_base* op) -> void - { - this->d_context->cancel(cancel_op, op); - } - auto accept(::beman::net29::detail::context_base::accept_operation* op) - -> ::beman::net29::detail::submit_result - { - return this->d_context->accept(op); - } - auto connect(::beman::net29::detail::context_base::connect_operation* op) - -> ::beman::net29::detail::submit_result - { - return this->d_context->connect(op); - } - auto receive(::beman::net29::detail::context_base::receive_operation* op) - -> ::beman::net29::detail::submit_result - { - return this->d_context->receive(op); - } - auto send(::beman::net29::detail::context_base::send_operation* op) - -> ::beman::net29::detail::submit_result - { - return this->d_context->send(op); - } - auto resume_at(::beman::net29::detail::context_base::resume_at_operation* op) - -> ::beman::net29::detail::submit_result - { - return this->d_context->resume_at(op); - } -}; - -static_assert(::beman::net29::detail::ex::sender< - beman::net29::detail::io_context_scheduler::sender - >); -static_assert(::beman::net29::detail::ex::scheduler< - beman::net29::detail::io_context_scheduler - >); - -// ---------------------------------------------------------------------------- - -#endif diff --git a/include/beman/net29/net.hpp b/include/beman/net29/net.hpp index c3f0280..55f1830 100644 --- a/include/beman/net29/net.hpp +++ b/include/beman/net29/net.hpp @@ -1,30 +1,26 @@ // include/beman/net29/net.hpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef INCLUDED_BEMAN_NET29_NET -#define INCLUDED_BEMAN_NET29_NET +#ifndef INCLUDED_INCLUDE_BEMAN_NET29_NET +#define INCLUDED_INCLUDE_BEMAN_NET29_NET -// ---------------------------------------------------------------------------- +#include +namespace beman::net29::detail { + namespace ex = beman::net::detail::ex; +} +namespace beman::net29 { + namespace ip = ::beman::net::ip; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + using ::beman::net::async_accept; + using ::beman::net::const_buffer; + using ::beman::net::async_connect; + using ::beman::net::async_receive; + using ::beman::net::async_send; + using ::beman::net::buffer; + using ::beman::net::io_context; + using ::beman::net::resume_after; + using ::beman::net::resume_at; -// ---------------------------------------------------------------------------- +} #endif diff --git a/src/beman/net29/CMakeLists.txt b/src/beman/net/CMakeLists.txt similarity index 97% rename from src/beman/net29/CMakeLists.txt rename to src/beman/net/CMakeLists.txt index 1efbcb0..e660764 100644 --- a/src/beman/net29/CMakeLists.txt +++ b/src/beman/net/CMakeLists.txt @@ -1,5 +1,5 @@ # cmake-format: off -# src/beman/net29/CMakeLists.txt -*-makefile-*- +# src/beman/net/CMakeLists.txt -*-makefile-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on @@ -8,7 +8,7 @@ add_library(${TARGET_ALIAS} ALIAS ${TARGET_LIBRARY}) target_sources(${TARGET_LIBRARY} PRIVATE - net29.cpp + net.cpp PUBLIC FILE_SET ${TARGET_LIBRARY}_public_headers TYPE HEADERS BASE_DIRS ${PROJECT_SOURCE_DIR}/include diff --git a/src/beman/net29/net29.cpp b/src/beman/net/net.cpp similarity index 67% rename from src/beman/net29/net29.cpp rename to src/beman/net/net.cpp index a1be518..84152fb 100644 --- a/src/beman/net29/net29.cpp +++ b/src/beman/net/net.cpp @@ -1,9 +1,9 @@ -// src/beman/net29/net29.cpp -*-C++-*- +// src/beman/net/net.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // ---------------------------------------------------------------------------- -namespace beman::net29 +namespace beman::net { int version{000}; } diff --git a/src/beman/net29/tests/dummy.pass.cpp b/src/beman/net29/tests/dummy.pass.cpp deleted file mode 100644 index 9d0ee78..0000000 --- a/src/beman/net29/tests/dummy.pass.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// src/beman/net29/tests/dummy.pass.cpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -// ---------------------------------------------------------------------------- - -auto main() -> int -{ -} diff --git a/src/beman/net29/tests/CMakeLists.txt b/tests/beman/net/CMakeLists.txt similarity index 84% rename from src/beman/net29/tests/CMakeLists.txt rename to tests/beman/net/CMakeLists.txt index 6540cd9..b99c827 100644 --- a/src/beman/net29/tests/CMakeLists.txt +++ b/tests/beman/net/CMakeLists.txt @@ -1,5 +1,5 @@ # cmake-format: off -# src/beman/net29/CMakeLists.txt -*-makefile-*- +# src/beman/net/CMakeLists.txt -*-makefile-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on @@ -11,4 +11,4 @@ foreach(test ${tests}) add_executable(${test} ${test}.cpp) target_link_libraries(${test} PRIVATE ${TARGET_LIBRARY}) add_test(NAME ${test} COMMAND $) -endforeach() \ No newline at end of file +endforeach() diff --git a/src/beman/net29/tests/sorted_list.pass.cpp b/tests/beman/net/sorted_list.pass.cpp similarity index 91% rename from src/beman/net29/tests/sorted_list.pass.cpp rename to tests/beman/net/sorted_list.pass.cpp index 2540caa..539358e 100644 --- a/src/beman/net29/tests/sorted_list.pass.cpp +++ b/tests/beman/net/sorted_list.pass.cpp @@ -1,7 +1,7 @@ -// src/beman/net29/tests/sorted_list.pass.cpp -*-C++-*- +// src/beman/net/tests/sorted_list.pass.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include #include @@ -29,7 +29,7 @@ namespace std::cout << "test insert()\n"; node d{}; node n[] = { {3, &d}, {2, &d}, {5, &d}, {4, &d} }; - beman::net29::detail::sorted_list l; + beman::net::detail::sorted_list l; assert(l.empty()); print(l.front()); @@ -61,7 +61,7 @@ namespace auto test_pop_front() -> void { node n[] = { {3}, {2}, {5}, {4} }; - beman::net29::detail::sorted_list l; + beman::net::detail::sorted_list l; for (node& c: n) l.insert(&c); @@ -89,7 +89,7 @@ namespace auto test_pop_front_or() -> void { node n[] = { {3}, {2}, {5}, {4} }; - beman::net29::detail::sorted_list l; + beman::net::detail::sorted_list l; for (node& c: n) l.insert(&c); @@ -105,7 +105,7 @@ namespace { std::cout << "test erase()\n"; node n[] = { {2}, {1}, {5}, {4}, {3} }; - beman::net29::detail::sorted_list l; + beman::net::detail::sorted_list l; for (node& c: n) l.insert(&c); print(l.front()); @@ -139,4 +139,4 @@ auto main() -> int test_pop_front(); test_pop_front_or(); test_erase(); -} \ No newline at end of file +}