diff options
author | 2024-04-22 08:04:58 +1000 | |
---|---|---|
committer | 2024-04-22 08:04:58 +1000 | |
commit | 184292b730f4236bd4840e780fdad97ee060ec84 (patch) | |
tree | 67902161a465fe92aec78ca502de07092b8cde0f /3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp | |
parent | 24154bc1f00790f344120b3a85175d6f616c5ad0 (diff) |
3rdparty/asio: Updated to 1.30.2
Diffstat (limited to '3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp')
-rw-r--r-- | 3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp b/3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp index 95adffd604e..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-2021 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> @@ -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,19 +50,19 @@ 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: @@ -90,7 +91,7 @@ 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) @@ -98,6 +99,11 @@ int main(int argc, char* argv[]) std::make_shared<session>(io_context, std::move(socket))->go(); } } + }, + [](std::exception_ptr e) + { + if (e) + std::rethrow_exception(e); }); io_context.run(); |