diff --git a/CMakeLists.txt b/CMakeLists.txt index e3aea90c..95fe8de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html add_custom_target(boost_async_doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html) +add_compile_definitions(BOOST_ASIO_HAS_IO_URING=1) if(BOOST_ASYNC_IS_ROOT) #include(CTest) @@ -120,7 +121,8 @@ add_library(boost_async src/io/write_at.cpp src/io/detail/random_access_device.cpp src/io/copy.cpp - src/io/copy_n.cpp) + src/io/copy_n.cpp + src/io/sleep.cpp) target_include_directories(boost_async PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(boost_async PUBLIC diff --git a/include/boost/async/io/acceptor.hpp b/include/boost/async/io/acceptor.hpp index 39397f0b..66741a6a 100644 --- a/include/boost/async/io/acceptor.hpp +++ b/include/boost/async/io/acceptor.hpp @@ -19,8 +19,8 @@ namespace boost::async::io struct acceptor { - BOOST_ASYNC_DECL acceptor(); - BOOST_ASYNC_DECL acceptor(endpoint ep); + BOOST_ASYNC_DECL acceptor(const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL acceptor(endpoint ep, const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL system::result bind(endpoint ep); BOOST_ASYNC_DECL system::result listen(int backlog = asio::socket_base::max_listen_connections); // int backlog = asio::max_backlog() BOOST_ASYNC_DECL endpoint local_endpoint(); diff --git a/include/boost/async/io/datagram_socket.hpp b/include/boost/async/io/datagram_socket.hpp index 4d9a0933..85bd7ec4 100644 --- a/include/boost/async/io/datagram_socket.hpp +++ b/include/boost/async/io/datagram_socket.hpp @@ -20,12 +20,14 @@ namespace boost::async::io struct [[nodiscard]] datagram_socket final : socket { // duplicate onto another thread - system::result duplicate(); + system::result duplicate(const async::executor & executor = this_thread::get_executor()); - datagram_socket(); + datagram_socket(const async::executor & executor = this_thread::get_executor()); datagram_socket(datagram_socket && lhs); - datagram_socket(native_handle_type h, protocol_type protocol = protocol_type()); - datagram_socket(endpoint ep); + datagram_socket(native_handle_type h, protocol_type protocol = protocol_type(), + const async::executor & executor = this_thread::get_executor()); + datagram_socket(endpoint ep, + const async::executor & executor = this_thread::get_executor()); private: struct receive_op_; struct receive_op_seq_; diff --git a/include/boost/async/io/pipe.hpp b/include/boost/async/io/pipe.hpp index e53bd144..8156dd22 100644 --- a/include/boost/async/io/pipe.hpp +++ b/include/boost/async/io/pipe.hpp @@ -16,7 +16,9 @@ namespace boost::async::io { -system::result> make_pipe(); +system::result> make_pipe( + const async::executor & executor = this_thread::get_executor() + ); struct readable_pipe final : stream { @@ -27,13 +29,13 @@ struct readable_pipe final : stream using native_handle_type = typename asio::basic_readable_pipe::native_handle_type; native_handle_type native_handle() {return pipe_.native_handle();} - BOOST_ASYNC_DECL readable_pipe(); - BOOST_ASYNC_DECL readable_pipe(native_handle_type native_handle); + BOOST_ASYNC_DECL readable_pipe(const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL readable_pipe(native_handle_type native_handle, const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL system::result assign(native_handle_type native_handle); BOOST_ASYNC_DECL system::result release(); - BOOST_ASYNC_DECL system::result duplicate(); + BOOST_ASYNC_DECL system::result duplicate(const async::executor & executor = this_thread::get_executor()); void write_some(buffers::mutable_buffer_subspan buffers) = delete; void write_some(buffers::mutable_buffer buffer) = delete; @@ -42,7 +44,7 @@ struct readable_pipe final : stream BOOST_ASYNC_DECL void async_read_some_impl_(buffers::mutable_buffer_subspan buffer, async::completion_handler h) override; BOOST_ASYNC_DECL void async_write_some_impl_(buffers::const_buffer_subspan buffer, async::completion_handler h) override; - friend system::result> make_pipe(); + friend system::result> make_pipe(const async::executor & exec); asio::basic_readable_pipe pipe_; }; @@ -55,24 +57,23 @@ struct writable_pipe final : stream using native_handle_type = typename asio::basic_readable_pipe::native_handle_type; native_handle_type native_handle() {return pipe_.native_handle();} - BOOST_ASYNC_DECL writable_pipe(); - BOOST_ASYNC_DECL writable_pipe(native_handle_type native_handle); + BOOST_ASYNC_DECL writable_pipe(const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL writable_pipe(native_handle_type native_handle, + const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL system::result assign(native_handle_type native_handle); BOOST_ASYNC_DECL system::result release(); - BOOST_ASYNC_DECL system::result duplicate(); + BOOST_ASYNC_DECL system::result duplicate(const async::executor & executor = this_thread::get_executor()); void read_some(buffers::mutable_buffer_subspan buffers) = delete; void read_some(buffers::mutable_buffer buffer) = delete; private: BOOST_ASYNC_DECL void async_read_some_impl_(buffers::mutable_buffer_subspan buffer, async::completion_handler h) override; BOOST_ASYNC_DECL void async_write_some_impl_(buffers::const_buffer_subspan buffer, async::completion_handler h) override; - friend system::result> make_pipe(); + friend system::result> make_pipe(const async::executor & exec); asio::basic_writable_pipe pipe_; }; -system::result> make_pipe(); - } diff --git a/include/boost/async/io/popen.hpp b/include/boost/async/io/popen.hpp index 59097572..733c4c7a 100644 --- a/include/boost/async/io/popen.hpp +++ b/include/boost/async/io/popen.hpp @@ -23,13 +23,15 @@ struct popen : stream using native_handle_type = typename boost::process::v2::basic_process::native_handle_type; BOOST_ASYNC_DECL popen(boost::process::v2::filesystem::path executable, - std::initializer_list args, - process_initializer initializer = {}); + std::initializer_list args, + process_initializer initializer = {}, + const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL popen(boost::process::v2::filesystem::path executable, - std::span args, - process_initializer initializer = {}); + std::span args, + process_initializer initializer = {}, + const async::executor & executor = this_thread::get_executor()); [[nodiscard]] BOOST_ASYNC_DECL system::result interrupt(); [[nodiscard]] BOOST_ASYNC_DECL system::result request_exit(); diff --git a/include/boost/async/io/process.hpp b/include/boost/async/io/process.hpp index 56059981..db09ea30 100644 --- a/include/boost/async/io/process.hpp +++ b/include/boost/async/io/process.hpp @@ -40,15 +40,18 @@ struct process BOOST_ASYNC_DECL process(boost::process::v2::filesystem::path executable, std::initializer_list args, - process_initializer initializer = {}); + process_initializer initializer = {}, + const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL process(boost::process::v2::filesystem::path executable, std::span args, - process_initializer initializer = {}); + process_initializer initializer = {}, + const async::executor & executor = this_thread::get_executor()); - BOOST_ASYNC_DECL process(pid_type pid); - BOOST_ASYNC_DECL process(pid_type pid, native_handle_type native_handle); + BOOST_ASYNC_DECL process(pid_type pid, const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL process(pid_type pid, native_handle_type native_handle, + const async::executor & executor = this_thread::get_executor()); [[nodiscard]] BOOST_ASYNC_DECL system::result interrupt(); [[nodiscard]] BOOST_ASYNC_DECL system::result request_exit(); diff --git a/include/boost/async/io/resolver.hpp b/include/boost/async/io/resolver.hpp index a18ad8fa..0f2ee03f 100644 --- a/include/boost/async/io/resolver.hpp +++ b/include/boost/async/io/resolver.hpp @@ -25,7 +25,7 @@ struct resolver { using resolve_result = system::result>; - BOOST_ASYNC_DECL resolver(); + BOOST_ASYNC_DECL resolver(const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL resolver(resolver && ) = delete; BOOST_ASYNC_DECL void cancel(); @@ -42,32 +42,29 @@ struct resolver asio::ip::basic_resolver & resolver_; core::string_view host_; core::string_view service_; - - }; - public: [[nodiscard]] resolve_op_ resolve(core::string_view host, core::string_view service) { return resolve_op_{resolver_, host, service}; } - - private: asio::ip::basic_resolver resolver_; }; -struct lookup +struct lookup final : result_op { lookup(core::string_view host, core::string_view service) : host_(host), service_(service) {} - auto operator co_await() {return resolver_.resolve(host_, service_);} - private: + + BOOST_ASYNC_DECL + void initiate(completion_handler); + + private: core::string_view host_; core::string_view service_; - resolver resolver_; - + std::optional> resolver_; }; } diff --git a/include/boost/async/io/sleep.hpp b/include/boost/async/io/sleep.hpp index d8d58063..33c9b55b 100644 --- a/include/boost/async/io/sleep.hpp +++ b/include/boost/async/io/sleep.hpp @@ -8,37 +8,49 @@ #ifndef BOOST_ASYNC_IO_SLEEP_HPP #define BOOST_ASYNC_IO_SLEEP_HPP -#include + #include +#include + +#include -#include +#include namespace boost::async::detail::io { -struct steady_sleep + +struct steady_sleep final : async::io::result_op<> { - steady_sleep(const std::chrono::steady_clock::time_point & tp) : tim{tp} {} - steady_sleep(const std::chrono::steady_clock::duration & du) : tim{du} {} + steady_sleep(const std::chrono::steady_clock::time_point & tp) : time_{tp} {} + steady_sleep(const std::chrono::steady_clock::duration & du) + : time_{std::chrono::steady_clock::now() + du} {} + + BOOST_ASYNC_DECL void ready(async::handler h); + BOOST_ASYNC_DECL void initiate(async::completion_handler complete); - async::io::steady_timer::wait_op_ operator co_await() { return tim.wait(); } - async::io::steady_timer::wait_op_::vawaitable value() { return std::move(op_.emplace(tim.wait())).value(); } private: - async::io::steady_timer tim; - std::optional op_; + std::chrono::steady_clock::time_point time_; + std::optional, + executor>> timer_; }; -struct system_sleep +struct system_sleep final : async::io::result_op<> { - system_sleep(const std::chrono::system_clock::time_point & tp) : tim{tp} {} - system_sleep(const std::chrono::system_clock::duration & du) : tim{du} {} - - async::io::system_timer::wait_op_ operator co_await() { return tim.wait(); } - async::io::system_timer::wait_op_::vawaitable value() { return std::move(op_.emplace(tim.wait())).value(); } - private: - async::io::system_timer tim; - std::optional op_; + system_sleep(const std::chrono::system_clock::time_point & tp) : time_{tp} {} + system_sleep(const std::chrono::system_clock::duration & du) + : time_{std::chrono::system_clock::now() + du} {} + + BOOST_ASYNC_DECL void ready(async::handler h); + BOOST_ASYNC_DECL void initiate(async::completion_handler complete); + + private: + std::chrono::system_clock::time_point time_; + std::optional, + executor>> timer_; }; } diff --git a/include/boost/async/io/ssl.hpp b/include/boost/async/io/ssl.hpp index fb4f265b..ade9dc48 100644 --- a/include/boost/async/io/ssl.hpp +++ b/include/boost/async/io/ssl.hpp @@ -38,11 +38,11 @@ struct ssl_stream : private detail::ssl_stream_base, stream, socket [[nodiscard]] BOOST_ASYNC_DECL system::result cancel() override; [[nodiscard]] BOOST_ASYNC_DECL bool is_open() const override; - BOOST_ASYNC_DECL ssl_stream(); + BOOST_ASYNC_DECL ssl_stream(const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL ssl_stream(ssl_stream && steam); BOOST_ASYNC_DECL ssl_stream(stream_socket && socket); - BOOST_ASYNC_DECL ssl_stream(asio::ssl::context & ctx); + BOOST_ASYNC_DECL ssl_stream(asio::ssl::context & ctx, const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL ssl_stream(asio::ssl::context & ctx, stream_socket && socket); private: diff --git a/include/boost/async/io/steady_timer.hpp b/include/boost/async/io/steady_timer.hpp index 258aef3e..9ba6cd2f 100644 --- a/include/boost/async/io/steady_timer.hpp +++ b/include/boost/async/io/steady_timer.hpp @@ -34,9 +34,9 @@ struct steady_timer /// The time point type of the clock. typedef typename clock_type::time_point time_point; - BOOST_ASYNC_DECL steady_timer(); - BOOST_ASYNC_DECL steady_timer(const time_point& expiry_time); - BOOST_ASYNC_DECL steady_timer(const duration& expiry_time); + BOOST_ASYNC_DECL steady_timer(const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL steady_timer(const time_point& expiry_time, const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL steady_timer(const duration& expiry_time, const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL void cancel(); diff --git a/include/boost/async/io/stream_file.hpp b/include/boost/async/io/stream_file.hpp index 1737d9b9..b2da4751 100644 --- a/include/boost/async/io/stream_file.hpp +++ b/include/boost/async/io/stream_file.hpp @@ -19,16 +19,18 @@ namespace boost::async::io struct stream_file : file, stream { - BOOST_ASYNC_DECL system::result duplicate(); + BOOST_ASYNC_DECL + system::result duplicate(const async::executor & executor = this_thread::get_executor()); [[nodiscard]] BOOST_ASYNC_DECL system::result close() override; [[nodiscard]] BOOST_ASYNC_DECL system::result cancel() override; [[nodiscard]] BOOST_ASYNC_DECL bool is_open() const override; - BOOST_ASYNC_DECL stream_file(); + BOOST_ASYNC_DECL stream_file(const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL stream_file(stream_file && lhs); - BOOST_ASYNC_DECL stream_file(native_handle_type h); - BOOST_ASYNC_DECL stream_file(core::string_view file, flags open_flags = flags::read_write); + BOOST_ASYNC_DECL stream_file(native_handle_type h, const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL stream_file(core::string_view file, flags open_flags = flags::read_write, + const async::executor & executor = this_thread::get_executor()); private: BOOST_ASYNC_DECL void async_read_some_impl_(buffers::mutable_buffer_subspan buffer, async::completion_handler h) override; BOOST_ASYNC_DECL void async_write_some_impl_(buffers::const_buffer_subspan buffer, async::completion_handler h) override; diff --git a/include/boost/async/io/stream_socket.hpp b/include/boost/async/io/stream_socket.hpp index c27ede75..64565471 100644 --- a/include/boost/async/io/stream_socket.hpp +++ b/include/boost/async/io/stream_socket.hpp @@ -19,16 +19,17 @@ namespace boost::async::io struct [[nodiscard]] stream_socket final : stream, socket { // duplicate onto another thread - BOOST_ASYNC_DECL system::result duplicate(); + BOOST_ASYNC_DECL system::result duplicate(const async::executor & executor = this_thread::get_executor()); [[nodiscard]] BOOST_ASYNC_DECL system::result close() override; [[nodiscard]] BOOST_ASYNC_DECL system::result cancel() override; [[nodiscard]] BOOST_ASYNC_DECL bool is_open() const override; - BOOST_ASYNC_DECL stream_socket(); + BOOST_ASYNC_DECL stream_socket(const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL stream_socket(stream_socket && lhs); - BOOST_ASYNC_DECL stream_socket(native_handle_type h, protocol_type protocol = protocol_type()); - BOOST_ASYNC_DECL stream_socket(endpoint ep); + BOOST_ASYNC_DECL stream_socket(native_handle_type h, protocol_type protocol = protocol_type(), + const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL stream_socket(endpoint ep, const async::executor & executor = this_thread::get_executor()); private: BOOST_ASYNC_DECL void async_read_some_impl_(buffers::mutable_buffer_subspan buffer, async::completion_handler h) override; BOOST_ASYNC_DECL void async_write_some_impl_(buffers::const_buffer_subspan buffer, async::completion_handler h) override; diff --git a/include/boost/async/io/system_timer.hpp b/include/boost/async/io/system_timer.hpp index 5aa3339d..2e8e2317 100644 --- a/include/boost/async/io/system_timer.hpp +++ b/include/boost/async/io/system_timer.hpp @@ -33,9 +33,9 @@ struct system_timer final /// The time point type of the clock. typedef typename clock_type::time_point time_point; - BOOST_ASYNC_DECL system_timer(); - BOOST_ASYNC_DECL system_timer(const time_point& expiry_time); - BOOST_ASYNC_DECL system_timer(const duration& expiry_time); + BOOST_ASYNC_DECL system_timer(const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL system_timer(const time_point& expiry_time, const async::executor & executor = this_thread::get_executor()); + BOOST_ASYNC_DECL system_timer(const duration& expiry_time, const async::executor & executor = this_thread::get_executor()); BOOST_ASYNC_DECL void cancel(); diff --git a/src/io/acceptor.cpp b/src/io/acceptor.cpp index 1613b4b7..9fcfb167 100644 --- a/src/io/acceptor.cpp +++ b/src/io/acceptor.cpp @@ -9,8 +9,10 @@ namespace boost::async::io { -acceptor::acceptor() : acceptor_{this_thread::get_executor()} {} -acceptor::acceptor(endpoint ep) : acceptor_{this_thread::get_executor(), ep} {} +acceptor::acceptor(const async::executor & exec) + : acceptor_{exec} {} +acceptor::acceptor(endpoint ep, const async::executor & exec) + : acceptor_{exec, ep} {} system::result acceptor::bind(endpoint ep) diff --git a/src/io/datagram_socket.cpp b/src/io/datagram_socket.cpp index f4d13b1c..21ad53be 100644 --- a/src/io/datagram_socket.cpp +++ b/src/io/datagram_socket.cpp @@ -11,24 +11,23 @@ namespace boost::async::io { -system::result datagram_socket::duplicate() +system::result datagram_socket::duplicate(const async::executor & exec) { auto res = detail::io::duplicate_handle(datagram_socket_.native_handle()); if (!res) return res.error(); - - return {system::in_place_value, datagram_socket(*res)}; + return {system::in_place_value, datagram_socket(*res, local_endpoint()->protocol(), exec)}; } -datagram_socket::datagram_socket() - : socket(datagram_socket_), datagram_socket_(this_thread::get_executor()) +datagram_socket::datagram_socket(const async::executor & exec) + : socket(datagram_socket_), datagram_socket_(exec) { } -datagram_socket::datagram_socket(native_handle_type h, protocol_type protocol) - : socket(datagram_socket_), datagram_socket_(this_thread::get_executor(), protocol, h) +datagram_socket::datagram_socket(native_handle_type h, protocol_type protocol, const async::executor & exec) + : socket(datagram_socket_), datagram_socket_(exec, protocol, h) { } @@ -36,8 +35,8 @@ datagram_socket::datagram_socket(datagram_socket && lhs) : socket(datagram_socket_), datagram_socket_(std::move(lhs.datagram_socket_)) { } -datagram_socket::datagram_socket(endpoint ep) - : socket(datagram_socket_), datagram_socket_(this_thread::get_executor(), ep) +datagram_socket::datagram_socket(endpoint ep, const async::executor & exec) + : socket(datagram_socket_), datagram_socket_(exec, ep) { } diff --git a/src/io/pipe.cpp b/src/io/pipe.cpp index 7c46cc26..0b7f408c 100644 --- a/src/io/pipe.cpp +++ b/src/io/pipe.cpp @@ -14,9 +14,9 @@ namespace boost::async::io { -readable_pipe::readable_pipe() : pipe_(this_thread::get_executor()) {} -readable_pipe::readable_pipe(native_handle_type native_handle) - : pipe_(this_thread::get_executor(), native_handle) {} +readable_pipe::readable_pipe(const async::executor & exec) : pipe_(exec) {} +readable_pipe::readable_pipe(native_handle_type native_handle, const async::executor & exec) + : pipe_(exec, native_handle) {} system::result readable_pipe::close() { @@ -73,19 +73,19 @@ auto readable_pipe::release() -> system::result return h; } -system::result readable_pipe::duplicate() +system::result readable_pipe::duplicate(const async::executor & exec) { auto res = detail::io::duplicate_handle(pipe_.native_handle()); if (!res) return res.error(); - return readable_pipe(*res); + return readable_pipe(*res, std::move(exec)); } -writable_pipe::writable_pipe() : pipe_(this_thread::get_executor()) {} -writable_pipe::writable_pipe(native_handle_type native_handle) - : pipe_(this_thread::get_executor(), native_handle) {} +writable_pipe::writable_pipe(const async::executor & exec) : pipe_(std::move(exec)) {} +writable_pipe::writable_pipe(native_handle_type native_handle, const async::executor & exec) + : pipe_(std::move(exec), native_handle) {} system::result writable_pipe::close() { @@ -142,19 +142,19 @@ auto writable_pipe::release() -> system::result return h; } -system::result writable_pipe::duplicate() +system::result writable_pipe::duplicate(const async::executor & exec) { auto res = detail::io::duplicate_handle(pipe_.native_handle()); if (!res) return res.error(); - return writable_pipe(*res); + return writable_pipe(*res, std::move(exec)); } -system::result> make_pipe() +system::result> make_pipe(const async::executor & exec) { - readable_pipe rp{}; - writable_pipe wp{}; + readable_pipe rp{exec}; + writable_pipe wp{exec}; system::error_code ec; asio::connect_pipe(rp.pipe_, wp.pipe_, ec); diff --git a/src/io/popen.cpp b/src/io/popen.cpp index 46c2f952..1c222d45 100644 --- a/src/io/popen.cpp +++ b/src/io/popen.cpp @@ -11,25 +11,27 @@ namespace boost::async::io { popen::popen(boost::process::v2::filesystem::path executable, - std::initializer_list args, - process_initializer initializer) - : popen_(this_thread::get_executor(), - executable, - args, - initializer.stdio, - initializer.start_dir, - initializer.env) {} + std::initializer_list args, + process_initializer initializer, + const async::executor & exec) + : popen_(exec, + executable, + args, + initializer.stdio, + initializer.start_dir, + initializer.env) {} popen::popen(boost::process::v2::filesystem::path executable, - std::span args, - process_initializer initializer) - : popen_(this_thread::get_executor(), - executable, - args, - initializer.stdio, - initializer.start_dir, - initializer.env) {} + std::span args, + process_initializer initializer, + const async::executor & exec) + : popen_(exec, + executable, + args, + initializer.stdio, + initializer.start_dir, + initializer.env) {} pid_type popen::id() const {return popen_.id();} diff --git a/src/io/process.cpp b/src/io/process.cpp index 20e1ad45..e7b2049a 100644 --- a/src/io/process.cpp +++ b/src/io/process.cpp @@ -12,8 +12,9 @@ namespace boost::async::io process::process(boost::process::v2::filesystem::path executable, std::initializer_list args, - process_initializer initializer) - : process_(this_thread::get_executor(), + process_initializer initializer, + const async::executor & exec) + : process_(exec, executable, args, initializer.stdio, @@ -23,8 +24,9 @@ process::process(boost::process::v2::filesystem::path executable, process::process(boost::process::v2::filesystem::path executable, std::span args, - process_initializer initializer) - : process_(this_thread::get_executor(), + process_initializer initializer, + const async::executor & exec) + : process_(exec, executable, args, initializer.stdio, @@ -32,9 +34,9 @@ process::process(boost::process::v2::filesystem::path executable, initializer.env) {} -process::process(pid_type pid) : process_(this_thread::get_executor(), pid) {} -process::process(pid_type pid, native_handle_type native_handle) - : process_(this_thread::get_executor(), pid, native_handle) {} +process::process(pid_type pid, const async::executor & exec) : process_(exec, pid) {} +process::process(pid_type pid, native_handle_type native_handle, const async::executor & exec) + : process_(exec, pid, native_handle) {} void process::wait_op_::initiate(completion_handler handler) { diff --git a/src/io/resolver.cpp b/src/io/resolver.cpp index 1190bdd0..c46716f6 100644 --- a/src/io/resolver.cpp +++ b/src/io/resolver.cpp @@ -14,20 +14,38 @@ namespace boost::async::io { -resolver::resolver() : resolver_(this_thread::get_executor()) {} +resolver::resolver(const async::executor & exec) : resolver_(exec) {} void resolver::cancel() { resolver_.cancel(); } -void resolver::resolve_op_::initiate(completion_handler h) + +void do_initiate(asio::ip::basic_resolver & resolver_, + core::string_view host, core::string_view service, + completion_handler h) { using results_type = typename asio::ip::basic_resolver_results; resolver_.async_resolve( - async::io::ip, host_, service_, + async::io::ip, host, service, asio::deferred([](system::error_code ec, results_type res) - { - container::pmr::vector r{this_thread::get_allocator()}; - r.assign(res.begin(), res.end()); - return asio::deferred.values(ec, std::move(r)); - }))(std::move(h)); + { + container::pmr::vector r{this_thread::get_allocator()}; + r.assign(res.begin(), res.end()); + return asio::deferred.values(ec, std::move(r)); + }))(std::move(h)); +} + + +void resolver::resolve_op_::initiate( + completion_handler h) +{ + do_initiate(resolver_, host_, service_, std::move(h)); +} + +BOOST_ASYNC_DECL +void lookup::initiate( + completion_handler handler) +{ + auto & res = resolver_.emplace(handler.get_executor()); + do_initiate(res, host_, service_, std::move(handler)); } } \ No newline at end of file diff --git a/src/io/sleep.cpp b/src/io/sleep.cpp new file mode 100644 index 00000000..2fb0c10b --- /dev/null +++ b/src/io/sleep.cpp @@ -0,0 +1,34 @@ +// Copyright (c) 2023 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +namespace boost::async::detail::io +{ + +void steady_sleep::ready(async::handler h) +{ + if (time_ < std::chrono::steady_clock::now()) + h({}); +} +void steady_sleep::initiate(async::completion_handler complete) +{ + auto & timer = timer_.emplace(complete.get_executor(), time_); + timer.async_wait(std::move(complete)); +} + +void system_sleep::ready(async::handler h) +{ + if (time_ < std::chrono::system_clock::now()) + h({}); +} +void system_sleep::initiate(async::completion_handler complete) +{ + auto &timer = timer_.emplace(complete.get_executor(), time_); + timer.async_wait(std::move(complete)); +} + + +} \ No newline at end of file diff --git a/src/io/ssl.cpp b/src/io/ssl.cpp index 043f3866..b2cb9435 100644 --- a/src/io/ssl.cpp +++ b/src/io/ssl.cpp @@ -29,8 +29,8 @@ static asio::ssl::context & get_ssl_context() } -ssl_stream::ssl_stream() - : ssl_stream_base(this_thread::get_executor(), get_ssl_context()), socket(ssl_stream_.next_layer()) +ssl_stream::ssl_stream(const async::executor & exec) + : ssl_stream_base(exec, get_ssl_context()), socket(ssl_stream_.next_layer()) { } @@ -42,8 +42,8 @@ ssl_stream::ssl_stream(ssl_stream && lhs) ssl_stream::ssl_stream(stream_socket && socket_) : ssl_stream_base(std::move(socket_.stream_socket_), get_ssl_context()), socket(ssl_stream_.next_layer()) {} -ssl_stream::ssl_stream(asio::ssl::context & ctx) - : ssl_stream_base(this_thread::get_executor(), ctx), socket(ssl_stream_.next_layer()) {} +ssl_stream::ssl_stream(asio::ssl::context & ctx, const async::executor & exec) + : ssl_stream_base(exec, ctx), socket(ssl_stream_.next_layer()) {} ssl_stream::ssl_stream(asio::ssl::context & ctx, stream_socket && socket_) : ssl_stream_base(std::move(socket_.stream_socket_), ctx), socket(ssl_stream_.next_layer()) {} diff --git a/src/io/steady_timer.cpp b/src/io/steady_timer.cpp index 846c7edd..8a8c6ab4 100644 --- a/src/io/steady_timer.cpp +++ b/src/io/steady_timer.cpp @@ -12,9 +12,12 @@ namespace boost::async::io { -steady_timer::steady_timer() : timer_(this_thread::get_executor()) {} -steady_timer::steady_timer(const time_point &expiry_time) : timer_(this_thread::get_executor(), expiry_time) {} -steady_timer::steady_timer(const duration &expiry_time) : timer_(this_thread::get_executor(), expiry_time) {} +steady_timer::steady_timer(const async::executor & exec) + : timer_(exec) {} +steady_timer::steady_timer(const time_point &expiry_time, const async::executor & exec) + : timer_(exec, expiry_time) {} +steady_timer::steady_timer(const duration &expiry_time, const async::executor & exec) + : timer_(exec, expiry_time) {} void steady_timer::cancel() { diff --git a/src/io/stream_file.cpp b/src/io/stream_file.cpp index 2bb1c6e4..b4ac8832 100644 --- a/src/io/stream_file.cpp +++ b/src/io/stream_file.cpp @@ -13,24 +13,24 @@ namespace boost::async::io { -system::result stream_file::duplicate() +system::result stream_file::duplicate(const async::executor & exec) { auto res = detail::io::duplicate_handle(stream_file_.native_handle()); if (!res) return res.error(); - return {system::in_place_value, stream_file(*res)}; + return {system::in_place_value, stream_file(*res, exec)}; } -stream_file::stream_file() - : file(stream_file_), stream_file_(this_thread::get_executor()) +stream_file::stream_file(const async::executor & exec) + : file(stream_file_), stream_file_(exec) { } -stream_file::stream_file(native_handle_type h) - : file(stream_file_), stream_file_(this_thread::get_executor()) +stream_file::stream_file(native_handle_type h, const async::executor & exec) + : file(stream_file_), stream_file_(exec) { } @@ -39,8 +39,8 @@ stream_file::stream_file(stream_file && lhs) { } -stream_file::stream_file(core::string_view file_, flags open_flags) - : file(stream_file_), stream_file_(this_thread::get_executor(), std::string(file_), open_flags) +stream_file::stream_file(core::string_view file_, flags open_flags, const async::executor & exec) + : file(stream_file_), stream_file_(exec, std::string(file_), open_flags) { } diff --git a/src/io/stream_socket.cpp b/src/io/stream_socket.cpp index 7d96b8bf..65b3cfe7 100644 --- a/src/io/stream_socket.cpp +++ b/src/io/stream_socket.cpp @@ -11,24 +11,24 @@ namespace boost::async::io { -system::result stream_socket::duplicate() +system::result stream_socket::duplicate(const async::executor & exec) { auto res = detail::io::duplicate_handle(stream_socket_.native_handle()); if (!res) return res.error(); - return {system::in_place_value, stream_socket(*res)}; + return {system::in_place_value, stream_socket(*res, local_endpoint()->protocol(), exec)}; } -stream_socket::stream_socket() - : socket(stream_socket_), stream_socket_(this_thread::get_executor()) +stream_socket::stream_socket(const async::executor & exec) + : socket(stream_socket_), stream_socket_(exec) { } -stream_socket::stream_socket(native_handle_type h, protocol_type protocol) - : socket(stream_socket_), stream_socket_(this_thread::get_executor(), protocol, h) +stream_socket::stream_socket(native_handle_type h, protocol_type protocol, const async::executor & exec) + : socket(stream_socket_), stream_socket_(exec, protocol, h) { } @@ -36,8 +36,8 @@ stream_socket::stream_socket(stream_socket && lhs) : socket(stream_socket_), stream_socket_(std::move(lhs.stream_socket_)) { } -stream_socket::stream_socket(endpoint ep) - : socket(stream_socket_), stream_socket_(this_thread::get_executor(), ep) +stream_socket::stream_socket(endpoint ep, const async::executor & exec) + : socket(stream_socket_), stream_socket_(exec, ep) { } diff --git a/src/io/system_timer.cpp b/src/io/system_timer.cpp index b27b1572..685a050b 100644 --- a/src/io/system_timer.cpp +++ b/src/io/system_timer.cpp @@ -12,9 +12,12 @@ namespace boost::async::io { -system_timer::system_timer() : timer_(this_thread::get_executor()) {} -system_timer::system_timer(const time_point &expiry_time) : timer_(this_thread::get_executor(), expiry_time) {} -system_timer::system_timer(const duration &expiry_time) : timer_(this_thread::get_executor(), expiry_time) {} +system_timer::system_timer(const async::executor & exec) + : timer_(exec) {} +system_timer::system_timer(const time_point &expiry_time, const async::executor & exec) + : timer_(exec, expiry_time) {} +system_timer::system_timer(const duration &expiry_time, const async::executor & exec) + : timer_(exec, expiry_time) {} void system_timer::cancel() {