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/cpp03/services/daytime_client.cpp | |
parent | 24154bc1f00790f344120b3a85175d6f616c5ad0 (diff) |
3rdparty/asio: Updated to 1.30.2
Diffstat (limited to '3rdparty/asio/src/examples/cpp03/services/daytime_client.cpp')
-rw-r--r-- | 3rdparty/asio/src/examples/cpp03/services/daytime_client.cpp | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/3rdparty/asio/src/examples/cpp03/services/daytime_client.cpp b/3rdparty/asio/src/examples/cpp03/services/daytime_client.cpp deleted file mode 100644 index b4e7ea602d7..00000000000 --- a/3rdparty/asio/src/examples/cpp03/services/daytime_client.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// daytime_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 <asio.hpp> -#include <boost/bind/bind.hpp> -#include <iostream> -#include "logger.hpp" - -using asio::ip::tcp; - -char read_buffer[1024]; - -void read_handler(const asio::error_code& e, - std::size_t bytes_transferred, tcp::socket* s) -{ - if (!e) - { - std::cout.write(read_buffer, bytes_transferred); - - s->async_read_some(asio::buffer(read_buffer), - boost::bind(read_handler, asio::placeholders::error, - asio::placeholders::bytes_transferred, s)); - } - else - { - asio::execution_context& context = asio::query( - s->get_executor(), asio::execution::context); - services::logger logger(context, "read_handler"); - - std::string msg = "Read error: "; - msg += e.message(); - logger.log(msg); - } -} - -void connect_handler(const asio::error_code& e, tcp::socket* s) -{ - asio::execution_context& context = asio::query( - s->get_executor(), asio::execution::context); - services::logger logger(context, "connect_handler"); - - if (!e) - { - logger.log("Connection established"); - - s->async_read_some(asio::buffer(read_buffer), - boost::bind(read_handler, asio::placeholders::error, - asio::placeholders::bytes_transferred, s)); - } - else - { - std::string msg = "Unable to establish connection: "; - msg += e.message(); - logger.log(msg); - } -} - -int main(int argc, char* argv[]) -{ - try - { - if (argc != 2) - { - std::cerr << "Usage: daytime_client <host>" << std::endl; - return 1; - } - - asio::io_context io_context; - - // Set the name of the file that all logger instances will use. - services::logger logger(io_context, ""); - logger.use_file("log.txt"); - - // Resolve the address corresponding to the given host. - tcp::resolver resolver(io_context); - tcp::resolver::results_type endpoints = - resolver.resolve(argv[1], "daytime"); - - // Start an asynchronous connect. - tcp::socket socket(io_context); - asio::async_connect(socket, endpoints, - boost::bind(connect_handler, - asio::placeholders::error, &socket)); - - // Run the io_context until all operations have finished. - io_context.run(); - } - catch (std::exception& e) - { - std::cerr << e.what() << std::endl; - } - - return 0; -} |