2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-26 18:22:09 +00:00
Commit Graph

77 Commits

Author SHA1 Message Date
Christopher Kohlhoff
57a8c85f6d Remove deprecated handler allocation hooks. 2023-10-26 00:44:01 +11:00
Christopher Kohlhoff
944758cdaf Remove deprecated handler invocation hook. 2023-10-26 00:44:00 +11:00
Christopher Kohlhoff
eae55c14d3 Remove deprecated execution functionality. 2023-10-26 00:43:05 +11:00
Christopher Kohlhoff
a788ad8457 Fix links to experimental::promise reference page. 2023-04-05 21:43:14 +10:00
Christopher Kohlhoff
adfeed2b5d Add any_completion_handler to the documentation. 2023-03-07 00:04:56 +11:00
Christopher Kohlhoff
d341036043 Add protocol for AF_UNIX+SOCK_SEQPACKET. 2023-03-01 23:08:42 +11:00
Christopher Kohlhoff
0f5ed97183 Add bind_immediate_executor function and immediate_executor_binder adapter. 2023-03-01 23:05:44 +11:00
Christopher Kohlhoff
e199980569 Add associated_immediate_executor associator. 2023-03-01 23:04:58 +11:00
Christopher Kohlhoff
35e93e4e90 Update copyright notices. 2023-03-01 23:03:03 +11:00
Christopher Kohlhoff
9e03478ba1 Add range-based experimental::make_parallel_group().
Added new overloads of experimental::make_parallel_group that may be used
to launch a dynamically-sized set of asynchronous operations, where all
operations are the same type. For example:

  using op_type = decltype(
      socket1.async_read_some(
        boost::asio::buffer(data1),
        boost::asio::deferred
      )
    );

  std::vector<op_type> ops;

  ops.push_back(
      socket1.async_read_some(
        boost::asio::buffer(data1),
        boost::asio::deferred
      )
    );

  ops.push_back(
      socket2.async_read_some(
        boost::asio::buffer(data2),
        boost::asio::deferred
      )
    );

  boost::asio::experimental::make_parallel_group(ops).async_wait(
      boost::asio::experimental::wait_for_all(),
      [](
          std::vector<std::size_t> completion_order,
          std::vector<boost::system::error_code> e,
          std::vector<std::size_t> n
        )
      {
        for (std::size_t i = 0; i < completion_order.size(); ++i)
        {
          std::size_t idx = completion_order[i];
          std::cout << "socket " << idx << " finished: ";
          std::cout << e[idx] << ", " << n[idx] << "\n";
        }
      }
    );

Thanks go to Klemens Morgenstern for supplying part of this implementation.
2022-11-03 00:48:45 +11:00
Christopher Kohlhoff
7b8d9b4f5f Fix link to experimental::co_composed. 2022-11-01 13:49:17 +11:00
Christopher Kohlhoff
1c0f3c36be Add experimental::co_composed.
The following example illustrates a simple asynchronous operation that
implements an echo protocol in terms of a coroutine:

  template <typename CompletionToken>
  auto async_echo(tcp::socket& socket,
      CompletionToken&& token)
  {
    return boost::asio::async_initiate<
      CompletionToken, void(boost::system::error_code)>(
        boost::asio::experimental::co_composed<
          void(boost::system::error_code)>(
            [](auto state, tcp::socket& socket) -> void
            {
              try
              {
                state.throw_if_cancelled(true);
                state.reset_cancellation_state(
                  boost::asio::enable_terminal_cancellation());

                for (;;)
                {
                  char data[1024];
                  std::size_t n = co_await socket.async_read_some(
                      boost::asio::buffer(data), boost::asio::deferred);

                  co_await boost::asio::async_write(socket,
                      boost::asio::buffer(data, n), boost::asio::deferred);
                }
              }
              catch (const boost::system::system_error& e)
              {
                co_return {e.code()};
              }
            }, socket),
        token, std::ref(socket));
  }
2022-11-01 11:35:07 +11:00
Christopher Kohlhoff
64448e6a19 Add any_completion_handler<>.
The any_completion_handler<> template can be used to type-erase
completion handlers. A typical use case is to enable separate
compilation of asynchronous operation implementations. For example:

  // Header file:

  void async_sleep_impl(
      boost::asio::any_completion_handler<void(boost::system::error_code)> handler,
      boost::asio::any_io_executor ex, std::chrono::nanoseconds duration);

  template <typename CompletionToken>
  inline auto async_sleep(boost::asio::any_io_executor ex,
      std::chrono::nanoseconds duration, CompletionToken&& token)
  {
    return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code)>(
        async_sleep_impl, token, std::move(ex), duration);
  }

  // Separately compiled source file:

  void async_sleep_impl(
      boost::asio::any_completion_handler<void(boost::system::error_code)> handler,
      boost::asio::any_io_executor ex, std::chrono::nanoseconds duration)
  {
    auto timer = std::make_shared<boost::asio::steady_timer>(ex, duration);
    timer->async_wait(boost::asio::consign(std::move(handler), timer));
  }
2022-11-01 11:00:16 +11:00
Christopher Kohlhoff
ed722fb0a3 Add consign completion token adapter.
The consign completion token adapter can be used to attach additional
values to a completion handler. This is typically used to keep at least
one copy of an object, such as a smart pointer, alive until the
completion handler is called.

For example:

  auto timer1 = std::make_shared<boost::asio::steady_timer>(my_io_context);
  timer1->expires_after(std::chrono::seconds(1));
  timer1->async_wait(
      boost::asio::consign(
        [](boost::system::error_code ec)
        {
          // ...
        },
        timer1
      )
    );

  auto timer2 = std::make_shared<boost::asio::steady_timer>(my_io_context);
  timer2->expires_after(std::chrono::seconds(30));
  std::future<void> f =
    timer2->async_wait(
      boost::asio::consign(
        boost::asio::use_future,
        timer2
      )
    );
2022-11-01 11:00:15 +11:00
Christopher Kohlhoff
9c9b76f0ee Add any_completion_executor. 2022-11-01 11:00:15 +11:00
Christopher Kohlhoff
8603d5c39b Deprecate concepts, traits, functions and customisation points related to senders and receivers. 2022-11-01 11:00:15 +11:00
Christopher Kohlhoff
17e08c23fe Deprecate execution::execute member function.
Use execute as a member function.
2022-11-01 10:44:37 +11:00
Christopher Kohlhoff
32f8f72fcc Add use_promise and use_promise_t to the quick reference. 2022-08-01 09:25:54 +10:00
Christopher Kohlhoff
63972a52c0 Add completion_signature_of trait.
The completion_signature_of trait (and corresponding type alias
completion_signature_of_t) may be used to determine the completion
signature of an asynchronous operation. For example:

  auto d = my_timer.async_wait(asio::deferred);
  using sig = asio::completion_signature_of<decltype(d)>::type;
  // sig is void(error_code)

or with a handcrafted asynchronous operation:

  struct my_async_op
  {
    asio::ip::tcp::socket& socket_ = ...;

    template <typename Token>
    auto operator()(asio::const_buffer data, Token&& token)
    {
      return asio::async_write(socket_, data,
          std::forward<Token>(token));
    }
  };

  using sig =
    asio::completion_signature_of<
      my_async_op, asio::const_buffer>::type;
  // sig is void(error_code, size_t)
2022-06-30 01:08:13 +10:00
Christopher Kohlhoff
73efb7492c Add is_async_operation trait and async_operation concept.
The is_async_operation trait may be used to determine if a function
object, and optional arguments, may be called to initiate an
asynchronous operation. For example, when using asio::deferred

  auto d = my_timer.async_wait(asio::deferred);
  static_assert(asio::is_async_operation<decltype(d)>::value);

or with a handcrafted asynchronous operation:

  struct my_async_op
  {
    asio::ip::tcp::socket& socket_ = ...;

    template <typename Token>
    auto operator()(asio::const_buffer data, Token&& token)
    {
      return asio::async_write(socket_, data,
          std::forward<Token>(token));
    }
  };

  static_assert(
      asio::is_async_operation<
        my_async_op, asio::const_buffer>::value);
2022-06-30 01:08:13 +10:00
Christopher Kohlhoff
4c216747dc Move deferred to the asio namespace.
This is no longer an experimental facility. The names deferred and
deferred_t have been temporarily retained as deprecated entities under
the asio::experimental namespace, for backwards compatibility.
2022-06-30 01:08:13 +10:00
Christopher Kohlhoff
34f5627723 Move prepend to the asio namespace.
This is no longer an experimental facility. The names prepend and
prepend_t have been temporarily retained as deprecated entities under
the asio::experimental namespace, for backwards compatibility.
2022-06-30 00:43:16 +10:00
Christopher Kohlhoff
f7356fbe90 Move append to the asio namespace.
This is no longer an experimental facility. The names append and
append_t have been temporarily retained as deprecated entities under
the asio::experimental namespace, for backwards compatibility.
2022-06-30 00:43:16 +10:00
Christopher Kohlhoff
a312a46715 Move as_tuple to the asio namespace.
This is no longer an experimental facility. The names as_tuple and
as_tuple_t have been temporarily retained as deprecated entities under
the asio::experimental namespace, for backwards compatibility.
2022-06-30 00:43:16 +10:00
Christopher Kohlhoff
d35b87ff27 Update documentation for dispatch, post, and defer. 2022-03-04 21:06:50 +11:00
Christopher Kohlhoff
2117b3ee7e Expose recycling_allocator as part of public interface. 2022-03-04 20:56:45 +11:00
Christopher Kohlhoff
7162c9675d Rework reference documentation in terms of completion tokens. 2022-03-02 22:13:21 +11:00
Christopher Kohlhoff
3cd04eee90 Add bind_allocator. 2022-03-02 21:57:41 +11:00
Christopher Kohlhoff
ff58013a23 Update copyright notices. 2022-03-02 21:23:52 +11:00
Christopher Kohlhoff
495e6367af Add experimental support for channels.
This adds experimental::channel and experimental::concurrent_channel.
Channels may be used to send completions as messages. For example:

  // Create a channel with no buffer space.
  channel<void(error_code, size_t)> ch(ctx);

  // The call to try_send fails as there is no buffer
  // space and no waiting receive operations.
  bool ok = ch.try_send(asio::error::eof, 123);
  assert(!ok);

  // The async_send operation blocks until a receive
  // operation consumes the message.
  ch.async_send(asio::error::eof, 123,
      [](error_code ec)
      {
        // ...
      });

  // The async_receive consumes the message. Both the
  // async_send and async_receive operations complete
  // immediately.
  ch.async_receive(
      [](error_code ec, size_t n)
      {
        // ...
      });
2021-11-04 01:56:32 +11:00
Christopher Kohlhoff
d8359719e1 Add support for registered buffers.
The mutable_registered_buffer and const_registered_buffer classes are
buffer sequence types that represented registered buffers. These buffers
are obtained by first performing a buffer registration:

  auto my_registration =
    asio::register_buffers(
        my_execution_context,
        my_buffer_sequence);

The registration object must be maintained for as long as the buffer
registration is required. The supplied buffer sequence represents the
memory location or locations that will be registered, and the caller
must ensure they remain valid for as long as they are registered. The
registration is automatically removed when the registration object is
destroyed. There can be at most one active registration per execution
context.

The registration object is a container of registered buffers. Buffers
may be obtained from it by iterating over the container, or via direct
index access:

  asio::mutable_registered_buffer my_buffer
    = my_registration[i];

The registered buffers may then be passed directly to operations:

  asio::async_read(my_socket, my_buffer,
      [](error_code ec, size_t n)
      {
        // ...
      });

Buffer registration supports the io_uring backend when used with read
and write operations on descriptors, files, pipes, and sockets.
2021-10-29 20:54:56 +11:00
Christopher Kohlhoff
b4fb33ec64 Add files and pipes to quick reference. 2021-10-27 13:50:20 +11:00
Christopher Kohlhoff
17ef2577d8 Fix this_coro::throw_if_cancelled link in reference index. 2021-07-07 23:52:08 +10:00
Christopher Kohlhoff
15b4f0eee2 Add new experimental facilities to the quick reference. 2021-07-07 22:47:10 +10:00
Christopher Kohlhoff
aa52f655e7 Add cancellation-related type requirements to quick reference. 2021-07-01 10:10:41 +10:00
Christopher Kohlhoff
0b0c4664d0 Add cancellation to reference documentation. 2021-06-28 10:14:54 +10:00
Christopher Kohlhoff
723982b867 Update copyright notices. 2021-02-25 08:29:05 +11:00
Christopher Kohlhoff
311d355ab4 Add experimental::as_single completion token adapter.
The as_single completion token adapter can be used to specify that the
completion handler arguments should be combined into a single argument.
For completion signatures with a single parameter, the argument is
passed through as-is. For signatures with two or more parameters, the
arguments are combined into a tuple.

The as_single adapter may be used in conjunction with use_awaitable and
structured bindings as follows:

    auto [e, n] = co_await socket.async_read_some(
        boost::asio::buffer(data), as_single(use_awaitable));

Alternatively, it may be used as a default completion token like so:

    using default_token = as_single_t<use_awaitable_t<>>;
    using tcp_socket = default_token::as_default_on_t<tcp::socket>;
    // ...
    awaitable<void> do_read(tcp_socket socket)
    {
      // ...
      auto [e, n] = co_await socket.async_read_some(boost::asio::buffer(data));
      // ...
    }
2020-11-02 14:03:09 +11:00
Christopher Kohlhoff
d8af4e6287 Add new execution facilities to quick reference. 2020-07-06 23:53:55 +10:00
Christopher Kohlhoff
93eb961014 Add new execution facilities to quick reference. 2020-06-23 11:08:25 +10:00
Christopher Kohlhoff
62dad58386 Add ssl::host_name_verification.
The ssl::host_name_verification class is a drop-in replacement for
ssl::rfc2818_verification, which it supersedes. The
ssl::rfc2818_verification class has been marked as deprecated.

Thanks to Arvid Norberg for providing the implementation.
2020-04-07 11:44:28 +10:00
Christopher Kohlhoff
4b552cfd5b Update copyright notices. 2020-04-07 11:15:42 +10:00
Christopher Kohlhoff
81dc9a91c2 Documentation for default completion tokens. 2019-12-04 23:40:58 +11:00
Christopher Kohlhoff
2e19dc524b Add more missing entries to quick reference. 2019-03-31 22:20:48 +11:00
Christopher Kohlhoff
b85528b585 Add new entities to quick reference. 2019-03-06 20:22:23 +11:00
Christopher Kohlhoff
688ea91d69 Fix cross references. 2019-03-03 19:58:48 +11:00
Christopher Kohlhoff
83278307e1 Add ip::resolver_base to quick reference and cross reference it from ip::basic_resolver. 2019-03-02 16:09:08 +11:00
Christopher Kohlhoff
ae04c26689 Update copyright notices. 2019-02-17 19:59:39 -10:00
Christopher Kohlhoff
4d7a656b66 Add experimental features to documentation. 2018-03-04 23:09:04 +11:00
Christopher Kohlhoff
886839cf55 Update copyright notices. 2018-03-04 21:59:30 +11:00