Commit Graph

138 Commits

Author SHA1 Message Date
Christopher Kohlhoff
8e0762de49 Add default completion tokens.
Every I/O executor type now has an associated default completion token
type. This is specified via the `default_completion_token_type` trait.
This trait may be used in asynchronous operation declarations as
follows:

  template <
      typename IoObject,
      typename CompletionToken =
        typename default_completion_token_type<
          typename IoObject::executor_type
        >::type
    >
  auto async_foo(
      IoObject& io_object,
      CompletionToken&& token =
        typename default_completion_token_type<
          typename IoObject::executor_type
        >::type{}
    );

If not specialised, this trait type is `void`, meaning no default
completion token type is available for the given I/O executor.

The `default_completion_token_type` trait is specialised for the
`use_awaitable` completion token so that it may be used as shown in the
following example:

  auto socket = use_awaitable.as_default_on(tcp::socket(my_context));
  // ...
  co_await socket.async_connect(my_endpoint); // Defaults to use_awaitable.

In this example, type of the `socket` object is transformed from
`tcp::socket` to have an I/O executor with the default completion token
set to `use_awaitable`.

Alternatively, the socket type may be computed directly:

  using tcp_socket = use_awaitable_t<>::as_default_on_t<tcp::socket>;
  tcp_socket socket(my_context);
  // ...
  co_await socket.async_connect(my_endpoint); // Defaults to use_awaitable.
2019-10-30 20:51:58 +11:00
chris.kohlhoff
db788cab40 Fix doxygen generation in tutorial. 2019-07-09 19:20:10 +10:00
Christopher Kohlhoff
54cdc73c29 Suppress various unused variable warnings. 2019-03-07 16:18:56 +11:00
Christopher Kohlhoff
2f7af2e33c Update composed operations examples to use async_initiate and a new helper function async_compose. 2019-03-06 20:22:23 +11:00
Christopher Kohlhoff
9eb153718d Add a make_strand function.
The make_strand function creates a strand with a deduced Executor template
argument.
2019-03-02 16:02:42 +11:00
Christopher Kohlhoff
2b3c9a4693 Capture port by value to prevent dangling reference. 2019-02-28 20:15:59 +11:00
Christopher Kohlhoff
baca9a092f Promote coroutines TS support classes to asio namespace.
The awaitable<>, co_spawn(), this_coro, detached, and redirect_error
facilities have been moved from the asio::experimental namespace to
namespace asio. As part of this change, the this_coro::token() awaitable
has been superseded by the asio::use_awaitable completion token.

Please note that the use_awaitable and redirect_error completion tokens
work only with asynchronous operations that use the new form of
async_result with member function initiate(). Furthermore, when using
use_awaitable, please be aware that the asynchronous operation is not
initiated until co_await is applied to the awaitable<>.
2019-02-28 00:02:00 +11:00
Christopher Kohlhoff
c7bbd30491 Fix compile error in serialization example. 2019-02-17 20:00:35 -10:00
Christopher Kohlhoff
ae04c26689 Update copyright notices. 2019-02-17 19:59:39 -10:00
Christopher Kohlhoff
59066d80b2 Add custom I/O executor support to I/O objects.
All I/O objects now have an additional Executor template parameter. This
template parameter defaults to the asio::executor type (the polymorphic
executor wrapper) but can be used to specify a user-defined executor
type.

I/O objects' constructors and functions that previously took an
asio::io_context& now accept either an Executor or a reference to a
concrete ExecutionContext (such as asio::io_context or
asio::thread_pool).

One potential point of breakage in existing user code is when reusing an
I/O object's io_context for constructing another I/O object, as in:

    asio::steady_timer my_timer(my_socket.get_executor().context());

To fix this, either construct the second I/O object using the first I/O
object's executor:

    asio::steady_timer my_timer(my_socket.get_executor());

or otherwise explicitly pass the io_context:

    asio::steady_timer my_timer(my_io_context);
2019-02-17 19:59:29 -10:00
Christopher Kohlhoff
a72fbb0b86 Remove deprecated get_io_context and get_io_service functions. 2019-02-17 19:59:20 -10:00
Christopher Kohlhoff
e19f5bdc94 Add examples showing how to write composed operations. 2018-12-05 14:10:58 +11:00
Christopher Kohlhoff
cfb012268a Add C++11 version of SOCKS4 example. 2018-12-05 13:46:01 +11:00
Christopher Kohlhoff
c599605ce5 Add C++11 version of SSL example. 2018-12-05 13:38:52 +11:00
Christopher Kohlhoff
df899178fd Add C++11 version of timers example. 2018-12-05 13:35:57 +11:00
Christopher Kohlhoff
a25822b74c Add C++11 versions of timeouts examples. 2018-12-05 13:34:20 +11:00
Christopher Kohlhoff
e8f114260f Use new form of async_accept where socket is moved into the completion handler. 2018-12-05 13:30:20 +11:00
Christopher Kohlhoff
29bd1cb9ef Execution contexts must be publicly derived from asio::execution_context. 2018-12-05 13:29:23 +11:00
Christopher Kohlhoff
d6e731e145 Add back accidentally deleted import of 'os'. 2018-04-03 19:43:07 +10:00
Christopher Kohlhoff
41fbd65fc7 Need to link boost.chrono in tests and C++03 examples. 2018-04-03 19:41:26 +10:00
Christopher Kohlhoff
d23cb643d9 Fix cross-compilation support. 2018-04-01 21:45:55 +10:00
Christopher Kohlhoff
3ff065118d Fix includes in some cpp11 examples. 2018-04-01 15:28:38 +10:00
Christopher Kohlhoff
69d54db71f Update examples to use chrono rather than Boost.Date_Time.
N.B. The Windows-specific tick_count_timer example has been removed as
it has been superseded by timers based on the standard steady_clock.
It's also not clear how to map a wrapping time source to the standard
chrono concepts.
2018-04-01 15:28:38 +10:00
Christopher Kohlhoff
5672713c90 Change socket iostreams to use chrono by default.
Define BOOST_ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM to enable the
old Boost.Date_Time interface in basic_socket_streambuf and
basic_socket_iostream.
2018-04-01 15:28:37 +10:00
Christopher Kohlhoff
5a9af00480 Update timeout examples to use latest features.
* Use asio::steady_timer rather than asio::deadline_timer.
* Use asio::dynamic_buffer rather than asio::streambuf.
* Use timed asio::io_context::run_for() function for blocking clients.
* Add example showing a custom completion token for blocking with timeouts.
2018-04-01 08:42:42 +10:00
Christopher Kohlhoff
c5da00630b Clean up some experimental::co_spawn examples. 2018-03-09 20:58:42 +11:00
Christopher Kohlhoff
77714ac82b Add some more experimental::co_spawn examples. 2018-03-07 17:29:34 +11:00
Christopher Kohlhoff
e3226bf6e0 Add experimental::co_spawn examples. 2018-03-04 23:09:04 +11:00
Christopher Kohlhoff
886839cf55 Update copyright notices. 2018-03-04 21:59:30 +11:00
Christopher Kohlhoff
80944b1065 Update tutorial text to use 'io_context'. 2018-03-04 21:57:26 +11:00
Christopher Kohlhoff
a57cb2a7a6 Suppress recv truncation errors on Windows, to match POSIX behaviour. 2017-12-02 18:25:44 +11:00
Christopher Kohlhoff
d74cfaa90d Add custom handler tracking example. 2017-12-02 16:12:57 +11:00
Christopher Kohlhoff
86fd2f7abc Create C++11 versions of the fork, local, multicast and nonblocking examples. 2017-12-02 16:12:57 +11:00
Christopher Kohlhoff
9564bf226c Add executor examples. 2017-12-02 10:27:15 +11:00
Christopher Kohlhoff
094354f343 Remove old Jamfiles. 2017-12-02 09:51:28 +11:00
Christopher Kohlhoff
87c879b50b Use new post() in serialization example. 2017-12-02 09:03:15 +11:00
Christopher Kohlhoff
030647a0a7 Update invocation examples to use executors. 2017-12-02 09:03:15 +11:00
Christopher Kohlhoff
d83e96a444 Update allocation overview and examples to use new form. 2017-12-02 09:03:15 +11:00
Christopher Kohlhoff
246e555e0a Fix copy/paste error in comment. 2017-12-02 09:03:14 +11:00
Christopher Kohlhoff
6f71713b55 Fix boostification namespace qualification error. 2017-11-08 00:08:40 +11:00
Christopher Kohlhoff
b60e92b13e Initial merge of Networking TS compatibility.
Merged from chriskohlhoff/asio master branch as of commit
4a4d28b0d24c53236e229bd1b5f378c9964b1ebb.
2017-10-23 21:48:43 +11:00
Christopher Kohlhoff
f7fa336c91 Update copyright notices. 2017-03-05 22:43:47 +11:00
Christopher Kohlhoff
36eef63a9c Update copyright notices. 2016-09-11 11:35:40 +10:00
Christopher Kohlhoff
e249488285 Regenerate certificates for SSL example. 2015-12-10 22:51:53 +11:00
Jessica Hamilton
df50982934 Haiku: link to libnetwork 2015-12-10 22:45:24 +11:00
Christopher Kohlhoff
41bf42b8da Update copyright notices. 2015-03-20 00:14:19 +11:00
Christopher Kohlhoff
878b787fce Use std::endl in tutorial to ensure output is flushed. 2015-03-19 23:49:25 +11:00
Christopher Kohlhoff
d109f120fa Explicitly mark asio::strand as deprecated.
Use asio::io_service::strand instead.
2014-10-17 22:49:14 +11:00
Christopher Kohlhoff
9fb6520f08 Remove unused data member. 2014-05-04 10:06:45 +10:00
Christopher Kohlhoff
20544b9bca Fix sprintf format warning in example. 2014-05-04 10:06:45 +10:00