summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/src/examples/cpp11/spawn
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/src/examples/cpp11/spawn')
-rw-r--r--3rdparty/asio/src/examples/cpp11/spawn/echo_server.cpp20
-rw-r--r--3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp6
2 files changed, 17 insertions, 9 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();
diff --git a/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp b/3rdparty/asio/src/examples/cpp11/spawn/parallel_grep.cpp
index fc2c6ecd1c2..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-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/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.