From 63780a33a9517f77f7a608da9049e0582d7ae748 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Wed, 8 Oct 2014 18:40:34 +1100 Subject: [PATCH] Add convenience headers that correspond to standards proposal. --- asio/include/Makefile.am | 11 +++ asio/include/asio/ts/buffer.hpp | 25 +++++ asio/include/asio/ts/executor.hpp | 29 ++++++ asio/include/asio/ts/future.hpp | 23 +++++ asio/include/asio/ts/internet.hpp | 34 +++++++ asio/include/asio/ts/io_service.hpp | 20 ++++ asio/include/asio/ts/memory.hpp | 22 +++++ asio/include/asio/ts/socket.hpp | 27 ++++++ asio/include/asio/ts/strand.hpp | 20 ++++ asio/include/asio/ts/thread_pool.hpp | 20 ++++ asio/include/asio/ts/timer.hpp | 26 ++++++ asio/include/asio/ts/type_traits.hpp | 21 +++++ asio/src/examples/cpp14/Makefile.am | 4 +- asio/src/examples/cpp14/executors/actor.cpp | 9 +- asio/src/examples/cpp14/executors/async_1.cpp | 8 +- asio/src/examples/cpp14/executors/async_2.cpp | 9 +- .../cpp14/executors/bank_account_1.cpp | 4 +- .../cpp14/executors/bank_account_2.cpp | 6 +- .../examples/cpp14/executors/fork_join.cpp | 5 +- .../src/examples/cpp14/executors/pipeline.cpp | 10 +- .../cpp14/executors/priority_scheduler.cpp | 3 +- asio/src/examples/cpp14/iostreams/.gitignore | 11 +++ .../examples/cpp14/iostreams/http_client.cpp | 91 +++++++++++++++++++ 23 files changed, 403 insertions(+), 35 deletions(-) create mode 100644 asio/include/asio/ts/buffer.hpp create mode 100644 asio/include/asio/ts/executor.hpp create mode 100644 asio/include/asio/ts/future.hpp create mode 100644 asio/include/asio/ts/internet.hpp create mode 100644 asio/include/asio/ts/io_service.hpp create mode 100644 asio/include/asio/ts/memory.hpp create mode 100644 asio/include/asio/ts/socket.hpp create mode 100644 asio/include/asio/ts/strand.hpp create mode 100644 asio/include/asio/ts/thread_pool.hpp create mode 100644 asio/include/asio/ts/timer.hpp create mode 100644 asio/include/asio/ts/type_traits.hpp create mode 100644 asio/src/examples/cpp14/iostreams/.gitignore create mode 100644 asio/src/examples/cpp14/iostreams/http_client.cpp diff --git a/asio/include/Makefile.am b/asio/include/Makefile.am index ad3feb15..e00d8a2f 100644 --- a/asio/include/Makefile.am +++ b/asio/include/Makefile.am @@ -417,6 +417,17 @@ nobase_include_HEADERS = \ asio/thread.hpp \ asio/thread_pool.hpp \ asio/time_traits.hpp \ + asio/ts/buffer.hpp \ + asio/ts/executor.hpp \ + asio/ts/future.hpp \ + asio/ts/internet.hpp \ + asio/ts/io_service.hpp \ + asio/ts/memory.hpp \ + asio/ts/socket.hpp \ + asio/ts/strand.hpp \ + asio/ts/thread_pool.hpp \ + asio/ts/timer.hpp \ + asio/ts/type_traits.hpp \ asio/unyield.hpp \ asio/use_future.hpp \ asio/uses_executor.hpp \ diff --git a/asio/include/asio/ts/buffer.hpp b/asio/include/asio/ts/buffer.hpp new file mode 100644 index 00000000..5064c375 --- /dev/null +++ b/asio/include/asio/ts/buffer.hpp @@ -0,0 +1,25 @@ +// +// ts/buffer.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_BUFFER_HPP +#define ASIO_TS_BUFFER_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/buffer.hpp" +#include "asio/streambuf.hpp" +#include "asio/completion_condition.hpp" +#include "asio/read.hpp" +#include "asio/write.hpp" +#include "asio/read_until.hpp" + +#endif // ASIO_TS_BUFFER_HPP diff --git a/asio/include/asio/ts/executor.hpp b/asio/include/asio/ts/executor.hpp new file mode 100644 index 00000000..5d306745 --- /dev/null +++ b/asio/include/asio/ts/executor.hpp @@ -0,0 +1,29 @@ +// +// ts/executor.hpp +// ~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_EXECUTOR_HPP +#define ASIO_TS_EXECUTOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/execution_context.hpp" +#include "asio/is_executor.hpp" +#include "asio/associated_executor.hpp" +#include "asio/wrap.hpp" +#include "asio/executor_work.hpp" +#include "asio/system_executor.hpp" +#include "asio/executor.hpp" +#include "asio/dispatch.hpp" +#include "asio/post.hpp" +#include "asio/defer.hpp" + +#endif // ASIO_TS_EXECUTOR_HPP diff --git a/asio/include/asio/ts/future.hpp b/asio/include/asio/ts/future.hpp new file mode 100644 index 00000000..08a5d647 --- /dev/null +++ b/asio/include/asio/ts/future.hpp @@ -0,0 +1,23 @@ +// +// ts/future.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_FUTURE_HPP +#define ASIO_TS_FUTURE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include + +#include "asio/package.hpp" +#include "asio/use_future.hpp" + +#endif // ASIO_TS_FUTURE_HPP diff --git a/asio/include/asio/ts/internet.hpp b/asio/include/asio/ts/internet.hpp new file mode 100644 index 00000000..3fe39918 --- /dev/null +++ b/asio/include/asio/ts/internet.hpp @@ -0,0 +1,34 @@ +// +// ts/internet.hpp +// ~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_INTERNET_HPP +#define ASIO_TS_INTERNET_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/ip/address.hpp" +#include "asio/ip/address_v4.hpp" +#include "asio/ip/address_v6.hpp" +#include "asio/ip/bad_address_cast.hpp" +#include "asio/ip/basic_endpoint.hpp" +#include "asio/ip/basic_resolver_query.hpp" +#include "asio/ip/basic_resolver_entry.hpp" +#include "asio/ip/basic_resolver_iterator.hpp" +#include "asio/ip/basic_resolver.hpp" +#include "asio/ip/host_name.hpp" +#include "asio/ip/tcp.hpp" +#include "asio/ip/udp.hpp" +#include "asio/ip/v6_only.hpp" +#include "asio/ip/unicast.hpp" +#include "asio/ip/multicast.hpp" + +#endif // ASIO_TS_INTERNET_HPP diff --git a/asio/include/asio/ts/io_service.hpp b/asio/include/asio/ts/io_service.hpp new file mode 100644 index 00000000..908d8cd9 --- /dev/null +++ b/asio/include/asio/ts/io_service.hpp @@ -0,0 +1,20 @@ +// +// ts/io_service.hpp +// ~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_IO_SERVICE_HPP +#define ASIO_TS_IO_SERVICE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/io_service.hpp" + +#endif // ASIO_TS_IO_SERVICE_HPP diff --git a/asio/include/asio/ts/memory.hpp b/asio/include/asio/ts/memory.hpp new file mode 100644 index 00000000..a462f0ce --- /dev/null +++ b/asio/include/asio/ts/memory.hpp @@ -0,0 +1,22 @@ +// +// ts/memory.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_MEMORY_HPP +#define ASIO_TS_MEMORY_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include + +#include "asio/associated_allocator.hpp" + +#endif // ASIO_TS_MEMORY_HPP diff --git a/asio/include/asio/ts/socket.hpp b/asio/include/asio/ts/socket.hpp new file mode 100644 index 00000000..67f53ce6 --- /dev/null +++ b/asio/include/asio/ts/socket.hpp @@ -0,0 +1,27 @@ +// +// ts/socket.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_SOCKET_HPP +#define ASIO_TS_SOCKET_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/socket_base.hpp" +#include "asio/basic_socket.hpp" +#include "asio/basic_datagram_socket.hpp" +#include "asio/basic_stream_socket.hpp" +#include "asio/basic_socket_acceptor.hpp" +#include "asio/basic_socket_streambuf.hpp" +#include "asio/basic_socket_iostream.hpp" +#include "asio/connect.hpp" + +#endif // ASIO_TS_SOCKET_HPP diff --git a/asio/include/asio/ts/strand.hpp b/asio/include/asio/ts/strand.hpp new file mode 100644 index 00000000..4fcd83c5 --- /dev/null +++ b/asio/include/asio/ts/strand.hpp @@ -0,0 +1,20 @@ +// +// ts/strand.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_STRAND_HPP +#define ASIO_TS_STRAND_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/strand.hpp" + +#endif // ASIO_TS_STRAND_HPP diff --git a/asio/include/asio/ts/thread_pool.hpp b/asio/include/asio/ts/thread_pool.hpp new file mode 100644 index 00000000..fafceb9b --- /dev/null +++ b/asio/include/asio/ts/thread_pool.hpp @@ -0,0 +1,20 @@ +// +// ts/thread_pool.hpp +// ~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_THREAD_POOL_HPP +#define ASIO_TS_THREAD_POOL_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/thread_pool.hpp" + +#endif // ASIO_TS_THREAD_POOL_HPP diff --git a/asio/include/asio/ts/timer.hpp b/asio/include/asio/ts/timer.hpp new file mode 100644 index 00000000..f6d32634 --- /dev/null +++ b/asio/include/asio/ts/timer.hpp @@ -0,0 +1,26 @@ +// +// ts/timer.hpp +// ~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_TIMER_HPP +#define ASIO_TS_TIMER_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include + +#include "asio/wait_traits.hpp" +#include "asio/basic_waitable_timer.hpp" +#include "asio/system_timer.hpp" +#include "asio/steady_timer.hpp" +#include "asio/high_resolution_timer.hpp" + +#endif // ASIO_TS_TIMER_HPP diff --git a/asio/include/asio/ts/type_traits.hpp b/asio/include/asio/ts/type_traits.hpp new file mode 100644 index 00000000..fd1b92da --- /dev/null +++ b/asio/include/asio/ts/type_traits.hpp @@ -0,0 +1,21 @@ +// +// ts/type_traits.hpp +// ~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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) +// + +#ifndef ASIO_TS_TYPE_TRAITS_HPP +#define ASIO_TS_TYPE_TRAITS_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/handler_type.hpp" +#include "asio/async_result.hpp" + +#endif // ASIO_TS_TYPE_TRAITS_HPP diff --git a/asio/src/examples/cpp14/Makefile.am b/asio/src/examples/cpp14/Makefile.am index 175c1a32..78236aed 100644 --- a/asio/src/examples/cpp14/Makefile.am +++ b/asio/src/examples/cpp14/Makefile.am @@ -17,7 +17,8 @@ noinst_PROGRAMS = \ executors/bank_account_2 \ executors/fork_join \ executors/pipeline \ - executors/priority_scheduler + executors/priority_scheduler \ + iostreams/http_client AM_CXXFLAGS = -I$(srcdir)/../../../include @@ -29,6 +30,7 @@ executors_bank_account_2_SOURCES = executors/bank_account_2.cpp executors_fork_join_SOURCES = executors/fork_join.cpp executors_pipeline_SOURCES = executors/pipeline.cpp executors_priority_scheduler_SOURCES = executors/priority_scheduler.cpp +iostreams_http_client_SOURCES = iostreams/http_client.cpp MAINTAINERCLEANFILES = \ $(srcdir)/Makefile.in diff --git a/asio/src/examples/cpp14/executors/actor.cpp b/asio/src/examples/cpp14/executors/actor.cpp index 8263f2e2..2c0e717a 100644 --- a/asio/src/examples/cpp14/executors/actor.cpp +++ b/asio/src/examples/cpp14/executors/actor.cpp @@ -1,8 +1,5 @@ -#include -#include -#include -#include -#include +#include +#include #include #include #include @@ -212,7 +209,7 @@ private: //------------------------------------------------------------------------------ -#include +#include #include using asio::thread_pool; diff --git a/asio/src/examples/cpp14/executors/async_1.cpp b/asio/src/examples/cpp14/executors/async_1.cpp index acefaf19..53d4673c 100644 --- a/asio/src/examples/cpp14/executors/async_1.cpp +++ b/asio/src/examples/cpp14/executors/async_1.cpp @@ -1,8 +1,6 @@ -#include -#include -#include -#include -#include +#include +#include +#include #include #include diff --git a/asio/src/examples/cpp14/executors/async_2.cpp b/asio/src/examples/cpp14/executors/async_2.cpp index ef794b07..7af467d1 100644 --- a/asio/src/examples/cpp14/executors/async_2.cpp +++ b/asio/src/examples/cpp14/executors/async_2.cpp @@ -1,9 +1,6 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include diff --git a/asio/src/examples/cpp14/executors/bank_account_1.cpp b/asio/src/examples/cpp14/executors/bank_account_1.cpp index 85f7d958..4e52faea 100644 --- a/asio/src/examples/cpp14/executors/bank_account_1.cpp +++ b/asio/src/examples/cpp14/executors/bank_account_1.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include using asio::post; diff --git a/asio/src/examples/cpp14/executors/bank_account_2.cpp b/asio/src/examples/cpp14/executors/bank_account_2.cpp index 4b8dcd5f..bc1341ad 100644 --- a/asio/src/examples/cpp14/executors/bank_account_2.cpp +++ b/asio/src/examples/cpp14/executors/bank_account_2.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include using asio::package; diff --git a/asio/src/examples/cpp14/executors/fork_join.cpp b/asio/src/examples/cpp14/executors/fork_join.cpp index f9dcdb39..918376ba 100644 --- a/asio/src/examples/cpp14/executors/fork_join.cpp +++ b/asio/src/examples/cpp14/executors/fork_join.cpp @@ -1,6 +1,5 @@ -#include -#include -#include +#include +#include #include #include #include diff --git a/asio/src/examples/cpp14/executors/pipeline.cpp b/asio/src/examples/cpp14/executors/pipeline.cpp index b71da0ef..bcf5d4bc 100644 --- a/asio/src/examples/cpp14/executors/pipeline.cpp +++ b/asio/src/examples/cpp14/executors/pipeline.cpp @@ -1,9 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include @@ -251,7 +247,7 @@ std::future pipeline(F f, Tail... t) //------------------------------------------------------------------------------ -#include +#include #include #include diff --git a/asio/src/examples/cpp14/executors/priority_scheduler.cpp b/asio/src/examples/cpp14/executors/priority_scheduler.cpp index 34bb5039..37665082 100644 --- a/asio/src/examples/cpp14/executors/priority_scheduler.cpp +++ b/asio/src/examples/cpp14/executors/priority_scheduler.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include #include diff --git a/asio/src/examples/cpp14/iostreams/.gitignore b/asio/src/examples/cpp14/iostreams/.gitignore new file mode 100644 index 00000000..bc2b4f8f --- /dev/null +++ b/asio/src/examples/cpp14/iostreams/.gitignore @@ -0,0 +1,11 @@ +.deps +.dirstamp +*.o +*.obj +*.exe +*_client +*_server +*.ilk +*.manifest +*.pdb +*.tds diff --git a/asio/src/examples/cpp14/iostreams/http_client.cpp b/asio/src/examples/cpp14/iostreams/http_client.cpp new file mode 100644 index 00000000..d9eb207a --- /dev/null +++ b/asio/src/examples/cpp14/iostreams/http_client.cpp @@ -0,0 +1,91 @@ +// +// http_client.cpp +// ~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2014 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 +#include +#include +#include +#include + +using asio::ip::tcp; + +int main(int argc, char* argv[]) +{ + try + { + if (argc != 3) + { + std::cout << "Usage: http_client \n"; + std::cout << "Example:\n"; + std::cout << " http_client www.boost.org /LICENSE_1_0.txt\n"; + return 1; + } + + asio::ip::tcp::iostream s; + + // The entire sequence of I/O operations must complete within 60 seconds. + // If an expiry occurs, the socket is automatically closed and the stream + // becomes bad. + s.expires_after(std::chrono::seconds(60)); + + // Establish a connection to the server. + s.connect(argv[1], "http"); + if (!s) + { + std::cout << "Unable to connect: " << s.error().message() << "\n"; + return 1; + } + + // Send the request. We specify the "Connection: close" header so that the + // server will close the socket after transmitting the response. This will + // allow us to treat all data up until the EOF as the content. + s << "GET " << argv[2] << " HTTP/1.0\r\n"; + s << "Host: " << argv[1] << "\r\n"; + s << "Accept: */*\r\n"; + s << "Connection: close\r\n\r\n"; + + // By default, the stream is tied with itself. This means that the stream + // automatically flush the buffered output before attempting a read. It is + // not necessary not explicitly flush the stream at this point. + + // Check that response is OK. + std::string http_version; + s >> http_version; + unsigned int status_code; + s >> status_code; + std::string status_message; + std::getline(s, status_message); + if (!s || http_version.substr(0, 5) != "HTTP/") + { + std::cout << "Invalid response\n"; + return 1; + } + if (status_code != 200) + { + std::cout << "Response returned with status code " << status_code << "\n"; + return 1; + } + + // Process the response headers, which are terminated by a blank line. + std::string header; + while (std::getline(s, header) && header != "\r") + std::cout << header << "\n"; + std::cout << "\n"; + + // Write the remaining data to output. + std::cout << s.rdbuf(); + } + catch (std::exception& e) + { + std::cout << "Exception: " << e.what() << "\n"; + } + + return 0; +}