Add convenience headers that correspond to standards proposal.

This commit is contained in:
Christopher Kohlhoff 2014-10-08 18:40:34 +11:00
parent f05ccf18df
commit 63780a33a9
23 changed files with 403 additions and 35 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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 <future>
#include "asio/package.hpp"
#include "asio/use_future.hpp"
#endif // ASIO_TS_FUTURE_HPP

View File

@ -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

View File

@ -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

View File

@ -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 <memory>
#include "asio/associated_allocator.hpp"
#endif // ASIO_TS_MEMORY_HPP

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <chrono>
#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

View File

@ -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

View File

@ -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

View File

@ -1,8 +1,5 @@
#include <asio/defer.hpp>
#include <asio/executor.hpp>
#include <asio/post.hpp>
#include <asio/strand.hpp>
#include <asio/system_executor.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/strand.hpp>
#include <condition_variable>
#include <deque>
#include <memory>
@ -212,7 +209,7 @@ private:
//------------------------------------------------------------------------------
#include <asio/thread_pool.hpp>
#include <asio/ts/thread_pool.hpp>
#include <iostream>
using asio::thread_pool;

View File

@ -1,8 +1,6 @@
#include <asio/dispatch.hpp>
#include <asio/executor_work.hpp>
#include <asio/post.hpp>
#include <asio/thread_pool.hpp>
#include <asio/wrap.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/thread_pool.hpp>
#include <asio/ts/type_traits.hpp>
#include <iostream>
#include <string>

View File

@ -1,9 +1,6 @@
#include <asio/associated_executor.hpp>
#include <asio/dispatch.hpp>
#include <asio/executor_work.hpp>
#include <asio/post.hpp>
#include <asio/thread_pool.hpp>
#include <asio/wrap.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/thread_pool.hpp>
#include <asio/ts/type_traits.hpp>
#include <iostream>
#include <string>

View File

@ -1,5 +1,5 @@
#include <asio/post.hpp>
#include <asio/thread_pool.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/thread_pool.hpp>
#include <iostream>
using asio::post;

View File

@ -1,6 +1,6 @@
#include <asio/package.hpp>
#include <asio/post.hpp>
#include <asio/thread_pool.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/future.hpp>
#include <asio/ts/thread_pool.hpp>
#include <iostream>
using asio::package;

View File

@ -1,6 +1,5 @@
#include <asio/dispatch.hpp>
#include <asio/execution_context.hpp>
#include <asio/thread_pool.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/thread_pool.hpp>
#include <condition_variable>
#include <memory>
#include <mutex>

View File

@ -1,9 +1,5 @@
#include <asio/associated_executor.hpp>
#include <asio/execution_context.hpp>
#include <asio/package.hpp>
#include <asio/post.hpp>
#include <asio/system_executor.hpp>
#include <asio/wrap.hpp>
#include <asio/ts/executor.hpp>
#include <asio/ts/future.hpp>
#include <condition_variable>
#include <future>
#include <memory>
@ -251,7 +247,7 @@ std::future<void> pipeline(F f, Tail... t)
//------------------------------------------------------------------------------
#include <asio/thread_pool.hpp>
#include <asio/ts/thread_pool.hpp>
#include <iostream>
#include <string>

View File

@ -1,5 +1,4 @@
#include <asio/dispatch.hpp>
#include <asio/execution_context.hpp>
#include <asio/ts/executor.hpp>
#include <condition_variable>
#include <iostream>
#include <memory>

View File

@ -0,0 +1,11 @@
.deps
.dirstamp
*.o
*.obj
*.exe
*_client
*_server
*.ilk
*.manifest
*.pdb
*.tds

View File

@ -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 <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <asio/ts/internet.hpp>
using asio::ip::tcp;
int main(int argc, char* argv[])
{
try
{
if (argc != 3)
{
std::cout << "Usage: http_client <server> <path>\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;
}