summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/src/examples/cpp03/tutorial
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/src/examples/cpp03/tutorial')
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime1/client.cpp57
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime2/server.cpp50
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime3/server.cpp119
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime4/client.cpp52
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime5/server.cpp53
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime6/server.cpp89
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/daytime7/server.cpp160
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/timer1/timer.cpp24
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/timer2/timer.cpp29
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/timer3/timer.cpp43
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/timer4/timer.cpp54
-rw-r--r--3rdparty/asio/src/examples/cpp03/tutorial/timer5/timer.cpp80
12 files changed, 0 insertions, 810 deletions
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime1/client.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime1/client.cpp
deleted file mode 100644
index 292a05ef039..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime1/client.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// client.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <boost/array.hpp>
-#include <asio.hpp>
-
-using asio::ip::tcp;
-
-int main(int argc, char* argv[])
-{
- try
- {
- if (argc != 2)
- {
- std::cerr << "Usage: client <host>" << std::endl;
- return 1;
- }
-
- asio::io_context io_context;
-
- tcp::resolver resolver(io_context);
- tcp::resolver::results_type endpoints =
- resolver.resolve(argv[1], "daytime");
-
- tcp::socket socket(io_context);
- asio::connect(socket, endpoints);
-
- for (;;)
- {
- boost::array<char, 128> buf;
- asio::error_code error;
-
- size_t len = socket.read_some(asio::buffer(buf), error);
-
- if (error == asio::error::eof)
- break; // Connection closed cleanly by peer.
- else if (error)
- throw asio::system_error(error); // Some other error.
-
- std::cout.write(buf.data(), len);
- }
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime2/server.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime2/server.cpp
deleted file mode 100644
index 16dfa0101a0..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime2/server.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-// server.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <ctime>
-#include <iostream>
-#include <string>
-#include <asio.hpp>
-
-using asio::ip::tcp;
-
-std::string make_daytime_string()
-{
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
-}
-
-int main()
-{
- try
- {
- asio::io_context io_context;
-
- tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 13));
-
- for (;;)
- {
- tcp::socket socket(io_context);
- acceptor.accept(socket);
-
- std::string message = make_daytime_string();
-
- asio::error_code ignored_error;
- asio::write(socket, asio::buffer(message), ignored_error);
- }
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime3/server.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime3/server.cpp
deleted file mode 100644
index 268401ffc6a..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime3/server.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-//
-// server.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <ctime>
-#include <iostream>
-#include <string>
-#include <boost/bind/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <asio.hpp>
-
-using asio::ip::tcp;
-
-std::string make_daytime_string()
-{
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
-}
-
-class tcp_connection
- : public boost::enable_shared_from_this<tcp_connection>
-{
-public:
- typedef boost::shared_ptr<tcp_connection> pointer;
-
- static pointer create(asio::io_context& io_context)
- {
- return pointer(new tcp_connection(io_context));
- }
-
- tcp::socket& socket()
- {
- return socket_;
- }
-
- void start()
- {
- message_ = make_daytime_string();
-
- asio::async_write(socket_, asio::buffer(message_),
- boost::bind(&tcp_connection::handle_write, shared_from_this(),
- asio::placeholders::error,
- asio::placeholders::bytes_transferred));
- }
-
-private:
- tcp_connection(asio::io_context& io_context)
- : socket_(io_context)
- {
- }
-
- void handle_write(const asio::error_code& /*error*/,
- size_t /*bytes_transferred*/)
- {
- }
-
- tcp::socket socket_;
- std::string message_;
-};
-
-class tcp_server
-{
-public:
- tcp_server(asio::io_context& io_context)
- : io_context_(io_context),
- acceptor_(io_context, tcp::endpoint(tcp::v4(), 13))
- {
- start_accept();
- }
-
-private:
- void start_accept()
- {
- tcp_connection::pointer new_connection =
- tcp_connection::create(io_context_);
-
- acceptor_.async_accept(new_connection->socket(),
- boost::bind(&tcp_server::handle_accept, this, new_connection,
- asio::placeholders::error));
- }
-
- void handle_accept(tcp_connection::pointer new_connection,
- const asio::error_code& error)
- {
- if (!error)
- {
- new_connection->start();
- }
-
- start_accept();
- }
-
- asio::io_context& io_context_;
- tcp::acceptor acceptor_;
-};
-
-int main()
-{
- try
- {
- asio::io_context io_context;
- tcp_server server(io_context);
- io_context.run();
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime4/client.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime4/client.cpp
deleted file mode 100644
index 24a325e0e88..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime4/client.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-//
-// client.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <boost/array.hpp>
-#include <asio.hpp>
-
-using asio::ip::udp;
-
-int main(int argc, char* argv[])
-{
- try
- {
- if (argc != 2)
- {
- std::cerr << "Usage: client <host>" << std::endl;
- return 1;
- }
-
- asio::io_context io_context;
-
- udp::resolver resolver(io_context);
- udp::endpoint receiver_endpoint =
- *resolver.resolve(udp::v4(), argv[1], "daytime").begin();
-
- udp::socket socket(io_context);
- socket.open(udp::v4());
-
- boost::array<char, 1> send_buf = {{ 0 }};
- socket.send_to(asio::buffer(send_buf), receiver_endpoint);
-
- boost::array<char, 128> recv_buf;
- udp::endpoint sender_endpoint;
- size_t len = socket.receive_from(
- asio::buffer(recv_buf), sender_endpoint);
-
- std::cout.write(recv_buf.data(), len);
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime5/server.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime5/server.cpp
deleted file mode 100644
index 0634b067ada..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime5/server.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// server.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <ctime>
-#include <iostream>
-#include <string>
-#include <boost/array.hpp>
-#include <asio.hpp>
-
-using asio::ip::udp;
-
-std::string make_daytime_string()
-{
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
-}
-
-int main()
-{
- try
- {
- asio::io_context io_context;
-
- udp::socket socket(io_context, udp::endpoint(udp::v4(), 13));
-
- for (;;)
- {
- boost::array<char, 1> recv_buf;
- udp::endpoint remote_endpoint;
- socket.receive_from(asio::buffer(recv_buf), remote_endpoint);
-
- std::string message = make_daytime_string();
-
- asio::error_code ignored_error;
- socket.send_to(asio::buffer(message),
- remote_endpoint, 0, ignored_error);
- }
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime6/server.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime6/server.cpp
deleted file mode 100644
index ccf8b54e41c..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime6/server.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-//
-// server.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <ctime>
-#include <iostream>
-#include <string>
-#include <boost/array.hpp>
-#include <boost/bind/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <asio.hpp>
-
-using asio::ip::udp;
-
-std::string make_daytime_string()
-{
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
-}
-
-class udp_server
-{
-public:
- udp_server(asio::io_context& io_context)
- : socket_(io_context, udp::endpoint(udp::v4(), 13))
- {
- start_receive();
- }
-
-private:
- void start_receive()
- {
- socket_.async_receive_from(
- asio::buffer(recv_buffer_), remote_endpoint_,
- boost::bind(&udp_server::handle_receive, this,
- asio::placeholders::error,
- asio::placeholders::bytes_transferred));
- }
-
- void handle_receive(const asio::error_code& error,
- std::size_t /*bytes_transferred*/)
- {
- if (!error)
- {
- boost::shared_ptr<std::string> message(
- new std::string(make_daytime_string()));
-
- socket_.async_send_to(asio::buffer(*message), remote_endpoint_,
- boost::bind(&udp_server::handle_send, this, message,
- asio::placeholders::error,
- asio::placeholders::bytes_transferred));
-
- start_receive();
- }
- }
-
- void handle_send(boost::shared_ptr<std::string> /*message*/,
- const asio::error_code& /*error*/,
- std::size_t /*bytes_transferred*/)
- {
- }
-
- udp::socket socket_;
- udp::endpoint remote_endpoint_;
- boost::array<char, 1> recv_buffer_;
-};
-
-int main()
-{
- try
- {
- asio::io_context io_context;
- udp_server server(io_context);
- io_context.run();
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/daytime7/server.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/daytime7/server.cpp
deleted file mode 100644
index 2fec1084dbf..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/daytime7/server.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-//
-// server.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <ctime>
-#include <iostream>
-#include <string>
-#include <boost/array.hpp>
-#include <boost/bind/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <asio.hpp>
-
-using asio::ip::tcp;
-using asio::ip::udp;
-
-std::string make_daytime_string()
-{
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
-}
-
-class tcp_connection
- : public boost::enable_shared_from_this<tcp_connection>
-{
-public:
- typedef boost::shared_ptr<tcp_connection> pointer;
-
- static pointer create(asio::io_context& io_context)
- {
- return pointer(new tcp_connection(io_context));
- }
-
- tcp::socket& socket()
- {
- return socket_;
- }
-
- void start()
- {
- message_ = make_daytime_string();
-
- asio::async_write(socket_, asio::buffer(message_),
- boost::bind(&tcp_connection::handle_write, shared_from_this()));
- }
-
-private:
- tcp_connection(asio::io_context& io_context)
- : socket_(io_context)
- {
- }
-
- void handle_write()
- {
- }
-
- tcp::socket socket_;
- std::string message_;
-};
-
-class tcp_server
-{
-public:
- tcp_server(asio::io_context& io_context)
- : io_context_(io_context),
- acceptor_(io_context, tcp::endpoint(tcp::v4(), 13))
- {
- start_accept();
- }
-
-private:
- void start_accept()
- {
- tcp_connection::pointer new_connection =
- tcp_connection::create(io_context_);
-
- acceptor_.async_accept(new_connection->socket(),
- boost::bind(&tcp_server::handle_accept, this, new_connection,
- asio::placeholders::error));
- }
-
- void handle_accept(tcp_connection::pointer new_connection,
- const asio::error_code& error)
- {
- if (!error)
- {
- new_connection->start();
- }
-
- start_accept();
- }
-
- asio::io_context& io_context_;
- tcp::acceptor acceptor_;
-};
-
-class udp_server
-{
-public:
- udp_server(asio::io_context& io_context)
- : socket_(io_context, udp::endpoint(udp::v4(), 13))
- {
- start_receive();
- }
-
-private:
- void start_receive()
- {
- socket_.async_receive_from(
- asio::buffer(recv_buffer_), remote_endpoint_,
- boost::bind(&udp_server::handle_receive, this,
- asio::placeholders::error));
- }
-
- void handle_receive(const asio::error_code& error)
- {
- if (!error)
- {
- boost::shared_ptr<std::string> message(
- new std::string(make_daytime_string()));
-
- socket_.async_send_to(asio::buffer(*message), remote_endpoint_,
- boost::bind(&udp_server::handle_send, this, message));
-
- start_receive();
- }
- }
-
- void handle_send(boost::shared_ptr<std::string> /*message*/)
- {
- }
-
- udp::socket socket_;
- udp::endpoint remote_endpoint_;
- boost::array<char, 1> recv_buffer_;
-};
-
-int main()
-{
- try
- {
- asio::io_context io_context;
- tcp_server server1(io_context);
- udp_server server2(io_context);
- io_context.run();
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/timer1/timer.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/timer1/timer.cpp
deleted file mode 100644
index 35ad17c6496..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/timer1/timer.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// timer.cpp
-// ~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <asio.hpp>
-
-int main()
-{
- asio::io_context io;
-
- asio::steady_timer t(io, asio::chrono::seconds(5));
- t.wait();
-
- std::cout << "Hello, world!" << std::endl;
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/timer2/timer.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/timer2/timer.cpp
deleted file mode 100644
index 10f0b528a44..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/timer2/timer.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// timer.cpp
-// ~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <asio.hpp>
-
-void print(const asio::error_code& /*e*/)
-{
- std::cout << "Hello, world!" << std::endl;
-}
-
-int main()
-{
- asio::io_context io;
-
- asio::steady_timer t(io, asio::chrono::seconds(5));
- t.async_wait(&print);
-
- io.run();
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/timer3/timer.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/timer3/timer.cpp
deleted file mode 100644
index b2e27b73dc5..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/timer3/timer.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// timer.cpp
-// ~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <asio.hpp>
-#include <boost/bind/bind.hpp>
-
-void print(const asio::error_code& /*e*/,
- asio::steady_timer* t, int* count)
-{
- if (*count < 5)
- {
- std::cout << *count << std::endl;
- ++(*count);
-
- t->expires_at(t->expiry() + asio::chrono::seconds(1));
- t->async_wait(boost::bind(print,
- asio::placeholders::error, t, count));
- }
-}
-
-int main()
-{
- asio::io_context io;
-
- int count = 0;
- asio::steady_timer t(io, asio::chrono::seconds(1));
- t.async_wait(boost::bind(print,
- asio::placeholders::error, &t, &count));
-
- io.run();
-
- std::cout << "Final count is " << count << std::endl;
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/timer4/timer.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/timer4/timer.cpp
deleted file mode 100644
index ebc6d0999dd..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/timer4/timer.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// timer.cpp
-// ~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <asio.hpp>
-#include <boost/bind/bind.hpp>
-
-class printer
-{
-public:
- printer(asio::io_context& io)
- : timer_(io, asio::chrono::seconds(1)),
- count_(0)
- {
- timer_.async_wait(boost::bind(&printer::print, this));
- }
-
- ~printer()
- {
- std::cout << "Final count is " << count_ << std::endl;
- }
-
- void print()
- {
- if (count_ < 5)
- {
- std::cout << count_ << std::endl;
- ++count_;
-
- timer_.expires_at(timer_.expiry() + asio::chrono::seconds(1));
- timer_.async_wait(boost::bind(&printer::print, this));
- }
- }
-
-private:
- asio::steady_timer timer_;
- int count_;
-};
-
-int main()
-{
- asio::io_context io;
- printer p(io);
- io.run();
-
- return 0;
-}
diff --git a/3rdparty/asio/src/examples/cpp03/tutorial/timer5/timer.cpp b/3rdparty/asio/src/examples/cpp03/tutorial/timer5/timer.cpp
deleted file mode 100644
index f17c9d67f94..00000000000
--- a/3rdparty/asio/src/examples/cpp03/tutorial/timer5/timer.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-// timer.cpp
-// ~~~~~~~~~
-//
-// Copyright (c) 2003-2021 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 <iostream>
-#include <asio.hpp>
-#include <boost/bind/bind.hpp>
-
-class printer
-{
-public:
- printer(asio::io_context& io)
- : strand_(asio::make_strand(io)),
- timer1_(io, asio::chrono::seconds(1)),
- timer2_(io, asio::chrono::seconds(1)),
- count_(0)
- {
- timer1_.async_wait(asio::bind_executor(strand_,
- boost::bind(&printer::print1, this)));
-
- timer2_.async_wait(asio::bind_executor(strand_,
- boost::bind(&printer::print2, this)));
- }
-
- ~printer()
- {
- std::cout << "Final count is " << count_ << std::endl;
- }
-
- void print1()
- {
- if (count_ < 10)
- {
- std::cout << "Timer 1: " << count_ << std::endl;
- ++count_;
-
- timer1_.expires_at(timer1_.expiry() + asio::chrono::seconds(1));
-
- timer1_.async_wait(asio::bind_executor(strand_,
- boost::bind(&printer::print1, this)));
- }
- }
-
- void print2()
- {
- if (count_ < 10)
- {
- std::cout << "Timer 2: " << count_ << std::endl;
- ++count_;
-
- timer2_.expires_at(timer2_.expiry() + asio::chrono::seconds(1));
-
- timer2_.async_wait(asio::bind_executor(strand_,
- boost::bind(&printer::print2, this)));
- }
- }
-
-private:
- asio::strand<asio::io_context::executor_type> strand_;
- asio::steady_timer timer1_;
- asio::steady_timer timer2_;
- int count_;
-};
-
-int main()
-{
- asio::io_context io;
- printer p(io);
- asio::thread t(boost::bind(&asio::io_context::run, &io));
- io.run();
- t.join();
-
- return 0;
-}