diff options
Diffstat (limited to '3rdparty/asio/src/examples/cpp11/spawn')
-rw-r--r-- | 3rdparty/asio/src/examples/cpp11/spawn/.gitignore | 12 | ||||
-rw-r--r-- | 3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp | 33 | ||||
-rw-r--r-- | 3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp | 6 |
3 files changed, 25 insertions, 26 deletions
diff --git a/3rdparty/asio/src/examples/cpp11/spawn/.gitignore b/3rdparty/asio/src/examples/cpp11/spawn/.gitignore deleted file mode 100644 index 6b8a121e099..00000000000 --- a/3rdparty/asio/src/examples/cpp11/spawn/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.dirstamp -parallel_grep -*.o -*.obj -*.exe -*_server -*_client -*.ilk -*.manifest -*.pdb -*.tds diff --git a/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp b/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp index 5397a4efe22..ae949d60bef 100644 --- a/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp +++ b/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp @@ -2,12 +2,13 @@ // echo_server.cpp // ~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // 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 <asio/detached.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/spawn.hpp> @@ -21,10 +22,10 @@ using asio::ip::tcp; class session : public std::enable_shared_from_this<session> { public: - explicit session(tcp::socket socket) + explicit session(asio::io_context& io_context, tcp::socket socket) : socket_(std::move(socket)), - timer_(socket_.get_io_context()), - strand_(socket_.get_io_context()) + timer_(io_context), + strand_(io_context.get_executor()) { } @@ -39,7 +40,7 @@ public: char data[128]; for (;;) { - timer_.expires_from_now(std::chrono::seconds(10)); + timer_.expires_after(std::chrono::seconds(10)); std::size_t n = socket_.async_read_some(asio::buffer(data), yield); asio::async_write(socket_, asio::buffer(data, n), yield); } @@ -49,25 +50,25 @@ public: socket_.close(); timer_.cancel(); } - }); + }, asio::detached); asio::spawn(strand_, [this, self](asio::yield_context yield) { while (socket_.is_open()) { - asio::error_code ignored_ec; + std::error_code ignored_ec; timer_.async_wait(yield[ignored_ec]); - if (timer_.expires_from_now() <= std::chrono::seconds(0)) + if (timer_.expiry() <= asio::steady_timer::clock_type::now()) socket_.close(); } - }); + }, asio::detached); } private: tcp::socket socket_; asio::steady_timer timer_; - asio::io_context::strand strand_; + asio::strand<asio::io_context::executor_type> strand_; }; int main(int argc, char* argv[]) @@ -90,11 +91,19 @@ int main(int argc, char* argv[]) for (;;) { - asio::error_code ec; + std::error_code ec; tcp::socket socket(io_context); acceptor.async_accept(socket, yield[ec]); - if (!ec) std::make_shared<session>(std::move(socket))->go(); + if (!ec) + { + std::make_shared<session>(io_context, std::move(socket))->go(); + } } + }, + [](std::exception_ptr e) + { + if (e) + std::rethrow_exception(e); }); io_context.run(); diff --git a/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp b/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp index 954d9472bbe..f4a5b1136dc 100644 --- a/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp +++ b/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp @@ -2,12 +2,13 @@ // parallel_grep.cpp // ~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // 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 <asio/detached.hpp> #include <asio/dispatch.hpp> #include <asio/post.hpp> #include <asio/spawn.hpp> @@ -17,6 +18,7 @@ #include <iostream> #include <string> +using asio::detached; using asio::dispatch; using asio::spawn; using asio::strand; @@ -69,7 +71,7 @@ int main(int argc, char* argv[]) if (++line_num % 10 == 0) post(yield); } - }); + }, detached); } // Join the thread pool to wait for all the spawned tasks to complete. |