2
0
mirror of https://github.com/boostorg/asio.git synced 2026-02-22 01:32:08 +00:00
Commit Graph

311 Commits

Author SHA1 Message Date
Christopher Kohlhoff
b57d962907 Fix redirect_error compatibility with new completion tokens. 2023-04-04 20:20:47 +10:00
Christopher Kohlhoff
19cff007b0 Fix as_tuple compatibility with legacy completion tokens. 2023-04-04 20:20:47 +10:00
Christopher Kohlhoff
d6a4d3b898 Add interoperability between channels and associated_immediate_executor. 2023-03-08 21:05:44 +11:00
Christopher Kohlhoff
d6cad8835e Expose sigaction() flags via optional argument to signal_set::add.
When registering a signal, it is now possible to pass flags that specify
the behaviour associated with the signal. These flags are specified as
an enum type in a new class, signal_set_base, and are passed to the
underlying sigaction() call. For example:

  asio::signal_set sigs(my_io_context);
  sigs.add(SIGINT, asio::signal_set::flags::restart);

Specifying flags other than flags::dont_care will fail unless
sigaction() is supported by the target operating system. Since signal
registration is global, conflicting flags (multiple registrations that
pass differing flags other than flags::dont_care) will also result in
an error.
2023-03-07 00:04:56 +11:00
Christopher Kohlhoff
730441dcbb Ensure buffered messages can still be received when channel is closed. 2023-03-06 23:37:39 +11:00
Christopher Kohlhoff
d341036043 Add protocol for AF_UNIX+SOCK_SEQPACKET. 2023-03-01 23:08:42 +11:00
Christopher Kohlhoff
387f74f575 Add user-defined literals for asio buffer types.
The _buf literal suffix, defined in namespace asio::buffer_literals, may
be used to create const_buffer objects from string, binary integer, and
hexadecimal integer literals. These buffer literals may be arbitrarily
long. For example:

  using namespace asio::buffer_literals;

  asio::const_buffer b1 = "hello"_buf;
  asio::const_buffer b2 = 0xdeadbeef_buf;
  asio::const_buffer b3 = 0x01234567'89abcdef'01234567'89abcdef_buf;
  asio::const_buffer b4 = 0b1010101011001100_buf;

The memory associated with a buffer literal is valid for the lifetime of
the program. This means that the buffer can be safely used with
asynchronous operations:

  async_write(my_socket, "hello"_buf, my_handler);
2023-03-01 23:07:32 +11:00
Christopher Kohlhoff
6550b831d3 Support immediate completion with reactor-based sockets and descriptors. 2023-03-01 23:07:02 +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
7811479a80 Fix compatibility between co_spawn and any_completion_handler. 2022-12-07 07:34:26 +11:00
Christopher Kohlhoff
56c1f0f647 Cleaned up promise and made it an async_op. 2022-11-03 17:31:32 +11:00
Christopher Kohlhoff
09716d71f3 Enabled deferred awaiting for coros, regularized use_coro, and fixed allocator handling.
This means that use_coro does not return a coro object, just like
use_awaitable does, i.e. it's an overhead that buys us type erasure.
Allocators can now be set for coro by including allocator_arg in the
coro signature.
2022-11-03 17:29:53 +11:00
Christopher Kohlhoff
68ef2b45d4 Add channel buffer specialisation for R(error_code). 2022-11-01 11:35:07 +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
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
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
22f4d42fd6 Add nothrow constructor overloads to execution::any_executor<>. 2022-11-01 09:29:19 +11:00
Christopher Kohlhoff
3292226107 Correctly mark compile-only test cases. 2022-07-05 20:41:39 +10:00
Christopher Kohlhoff
9e75820ee0 Add missing release() member functions to windows overlapped handles. 2022-07-05 20:27:16 +10:00
Christopher Kohlhoff
0733511a4c Add missing release() member functions to pipes. 2022-07-05 20:27:06 +10:00
Christopher Kohlhoff
46f49024e1 Removed all & race from promise - parallel_group covers most of it now. 2022-06-30 13:41:25 +10:00
Christopher Kohlhoff
2eda791fcd Add converting move construction/assignment to pipes. 2022-06-30 12:17:54 +10:00
Christopher Kohlhoff
4ef2cd0054 Add converting move construction/assignment to serial ports. 2022-06-30 12:17:39 +10:00
Christopher Kohlhoff
ca858d3ecd Add tests for converting move construction/assignment of files. 2022-06-30 12:17:16 +10:00
Christopher Kohlhoff
de2d299455 Add converting move construction/assignment to Windows stream and random-access handles. 2022-06-30 12:17:04 +10:00
Christopher Kohlhoff
5ce5e7e8ff Add converting move construction/assignment to Windows object_handle. 2022-06-30 12:16:44 +10:00
Christopher Kohlhoff
15e9e956b7 Add converting move construction/assignment to posix descriptors. 2022-06-30 12:16:25 +10:00
Christopher Kohlhoff
af93ac1ca9 Add buffer() overloads for contiguous containers, such as std::span. 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
45bd682d9a Make experimental::prepend compatible with C++11. 2022-06-30 00:43:16 +10:00
Christopher Kohlhoff
6f8e8c847d Make experimental::append compatible with C++11. 2022-06-30 00:43:16 +10:00
Christopher Kohlhoff
2117b3ee7e Expose recycling_allocator as part of public interface. 2022-03-04 20:56:45 +11:00
Christopher Kohlhoff
001d6213ca Work around shutdown ordering issue in coro/executor test. 2022-03-04 20:56:45 +11:00
Christopher Kohlhoff
31f93ed401 Fix "'this' pointer is null" warnings. 2022-03-02 21:57:42 +11:00
Christopher Kohlhoff
fc021c78b2 Fix bind_cancellation_slot compatibility with legacy completion tokens. 2022-03-02 21:57:42 +11:00
Christopher Kohlhoff
784575a3d3 Fix bind_executor compatibility with legacy completion tokens. 2022-03-02 21:57:42 +11:00
Christopher Kohlhoff
0bfa387d2c Add missing implementation of basic_file::release(). 2022-03-02 21:57:42 +11:00
Christopher Kohlhoff
600cf024f1 Add unit test for experimental::as_tuple. 2022-03-02 21:57:42 +11:00
Christopher Kohlhoff
3cd04eee90 Add bind_allocator. 2022-03-02 21:57:41 +11:00
Christopher Kohlhoff
20ed628d43 Fix associator specialisations for append and prepend. 2022-03-02 21:24:01 +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
5b72b72b72 Improvements to asio::experimental::coro.
* Added overload so member functions can provide an explicit executor.
* Added co_spawn for coro tasks.
* Added reference and overview documentation.
* Adopted awaitable cancellation model.
* Refactored implementation.
2021-11-04 01:41:25 +11:00
Christopher Kohlhoff
5a706991b5 Add missing file synchronisation functions. 2021-11-04 01:34:52 +11:00