116 Commits

Author SHA1 Message Date
Christopher Kohlhoff
1afbc5c12b Update copyright notices. 2025-03-04 22:57:26 +11:00
Christopher Kohlhoff
bbda620590 Add asio::config.
The asio::config class provides access to configuration variables that
are associated with an execution context. The class is intended for use
by asio internals, or by libraries or user-provided abstractions that
build on top of asio. These configuration variables will typically be
used to fine tune behaviour, such as enabling or disabling certain
optimisations.

When constructing an execution context, such as an io_context, the
caller may optionally pass a service_maker to install a concrete
configuration service into the context. For example:

  asio::io_context ctx{asio::config_from_env{}};

The configuration variables' values are accessed by using the
asio::config class, passing a section, key and default value:

  asio::config cfg{ctx};
  bool enable_locking = cfg.get("scheduler", "locking", true);

The initial set of configuration variables recognised by the asio
internals correspond to the concurrency hint and its special values:

  "scheduler" / "concurrency_hint" (int)
  "scheduler" / "locking" (bool)
  "reactor" / "registration_locking" (bool)
  "reactor" / "io_locking" (bool)
2024-10-30 23:01:37 +11:00
Christopher Kohlhoff
4b4487cbfe Add disposition_traits and no_error_t.
The disposition concept describes types that can be used to test whether
an asynchronous operation completed without error. This includes
error_code and exception_ptr, but can be extended to user types via
specialisation of the disposition_traits class template.

Generic code that is intended to work in terms of dispositions should
not use asio::disposition_traits directly, but instead:

* Test whether a disposition holds no error by comparing against
  asio::no_error (of type asio::no_error_t).

* Use asio::to_exception_ptr to convert a disposition to a
  std::exception_ptr.

* Use asio::throw_exception to throw an exception that corresponds to
  the disposition, after first testing the disposition against
  asio::no_error.

The asio::use_future completion token and asio::awaitable<>-based
coroutines have been updated to work generically in terms of
dispositions.
2024-10-30 22:59:32 +11:00
Christopher Kohlhoff
ec0908c562 Remove deprecated alias io_service. 2024-10-23 21:18:31 +11:00
Christopher Kohlhoff
4a2d50655d Move async_immediate to a public header. 2024-07-08 23:24:05 +10:00
Christopher Kohlhoff
5c01494f70 Promote co_composed to the asio namespace. 2024-07-02 07:54:20 +10:00
Christopher Kohlhoff
c4ef84506e Add composed.
The composed function creates an initiation function object from a stateful
implementation. It is similar to co_composed, but for regular function objects
rather than C++20 coroutines.

For example:

  struct async_echo_implementation
  {
    tcp::socket& socket_;
    boost::asio::mutable_buffer buffer_;
    enum { starting, reading, writing } state_;

    template <typename Self>
    void operator()(Self& self,
        boost::system::error_code error,
        std::size_t n)
    {
      switch (state_)
      {
      case starting:
        state_ = reading;
        socket_.async_read_some(
            buffer_, std::move(self));
        break;
      case reading:
        if (error)
        {
          self.complete(error, 0);
        }
        else
        {
          state_ = writing;
          boost::asio::async_write(socket_, buffer_,
              boost::asio::transfer_exactly(n),
              std::move(self));
        }
        break;
      case writing:
        self.complete(error, n);
        break;
      }
    }
  };

  template <typename CompletionToken>
  auto async_echo(tcp::socket& socket,
      boost::asio::mutable_buffer buffer,
      CompletionToken&& token)
  {
    return boost::asio::async_initiate<CompletionToken,
      void(boost::system::error_code, std::size_t)>(
        boost::asio::composed(
          async_echo_implementation{socket, buffer,
            async_echo_implementation::starting}, socket),
        token, boost::system::error_code{}, 0);
  }

The async_compose function has been changed to be a thin wrapper around
composed. However, unlike async_compose, composed allows arguments to be passed
to the stateful implementation when the operation is initiated.
2024-07-02 07:34:51 +10:00
Christopher Kohlhoff
6a817c4374 Add cancel_at and cancel_after completion token adapters. 2024-06-26 22:46:51 +10:00
Christopher Kohlhoff
6f43f7470c Move default_completion_token to its own header. 2024-06-26 22:40:13 +10:00
Christopher Kohlhoff
c36d3ef338 Update copyright notices. 2024-03-05 07:51:17 +11:00
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
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:🎏: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
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
b67260f30a Add any_completion_handler.hpp to convenience header. 2022-11-03 17:31:53 +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
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
2117b3ee7e Expose recycling_allocator as part of public interface. 2022-03-04 20:56:45 +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
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
028630b0f8 Add support for portable pipes.
This change add supports for pipes on POSIX and Windows (when I/O
completion ports are available). For example, to create and use a
connected pair of pipe objects:

  asio::readable_pipe read_end;
  asio::writable_pipe write_end;
  asio::connect_pipe(read_end, write_end);

  write_end.async_write_some(my_write_buffer,
      [](error_code e, size_t n)
      {
        // ...
      });

  read_end.async_read_some(my_read_buffer,
      [](error_code e, size_t n)
      {
        // ...
      });
2021-10-27 13:47:03 +11:00
Christopher Kohlhoff
c6b9f33dcf Add support for files.
This change adds support for stream-oriented and random-access files.
For example, to write to a newly created stream-oriented file:

  asio::stream_file file(
      my_io_context, "/path/to/file",
      asio::stream_file::write_only
        | asio::stream_file::create
        | asio::stream_file::truncate);

  file.async_write_some(my_buffer,
      [](error_code e, size_t n)
      {
        // ...
      });

or to read from a random-access file:

  asio::random_access_file file(
      my_io_context, "/path/to/file",
      asio::random_access_file::read_only);

  file.async_read_some_at(1234, my_buffer,
      [](error_code e, size_t n)
      {
        // ...
      });

This feature currently supports I/O completion ports on Windows, and
io_uring on Linux (define BOOST_ASIO_HAS_IO_URING to enable).
2021-10-25 12:15:08 +11:00
Christopher Kohlhoff
4e9f42b73f Add cancellation_state. 2021-06-28 10:10:27 +10:00
Christopher Kohlhoff
f8b37f0c90 Add bind_cancellation_slot function and cancellation_slot_binder adapter. 2021-06-28 10:10:07 +10:00
Christopher Kohlhoff
6dc719f036 Add associated_cancellation_slot associator. 2021-06-28 10:08:23 +10:00
Christopher Kohlhoff
3521da0834 Add cancellation_signal and cancellation_slot. 2021-06-28 10:08:05 +10:00
Christopher Kohlhoff
23c2400f99 Add cancellation_type enum. 2021-06-28 10:07:51 +10:00
Christopher Kohlhoff
e618857ff3 Add associator trait.
The associator trait is used to generically forward associators, such as
associated_executor<> and associated_allocator<>, through intermediate
completion handlers. For example:

    template <typename Handler>
    struct intermediate_handler
    {
      Handler handler_;

      template <typename... Args>
      void operator()(Args&... args)
      {
        // ...
      }
    };

    namespace boost {
    namespace asio {

      template <
          template <typename, typename> class Associator,
          typename Handler,
          typename DefaultCandidate>
      struct associator<
          Associator,
          intermediate_handler<Handler>,
          DefaultCandidate>
      {
        using type =
          typename Associator<Handler, DefaultCandidate>::type;

        static type get(
            const intermediate_handler<Handler>& h,
            const DefaultCandidate& c = DefaultCandidate()) noexcept
        {
          return Associator<Handler, DefaultCandidate>::get(
              h.handler_, c);
        }
      };

    } // namespace asio
    } // namespace boost
2021-06-05 17:43:30 +10:00
Christopher Kohlhoff
723982b867 Update copyright notices. 2021-02-25 08:29:05 +11:00
Christopher Kohlhoff
38514aca66 Add execution::bulk_execute customisation point object. 2020-07-02 00:23:04 +10:00
Christopher Kohlhoff
19c06f6931 Add execution::scheduler concept and execution::is_scheduler trait. 2020-06-30 22:39:08 +10:00
Christopher Kohlhoff
8081d7ee9d Add execution::schedule() customisation point object. 2020-06-30 22:38:09 +10:00
Christopher Kohlhoff
7edcde3d97 Add execution::connect() customisation point object. 2020-06-30 22:15:35 +10:00
Christopher Kohlhoff
84bf100253 Add execution::receiver_invocation_error exception. 2020-06-30 22:09:54 +10:00
Christopher Kohlhoff
63d35468c0 Add execution::sender concepts and traits.
This change adds the concept:

  * execution::sender

the traits:

  * execution::sender_traits

and the tag type:

  * execution::sender_base

It also adds the following traits that correspond to the concepts:

  * execution::is_sender
2020-06-30 22:09:19 +10:00
Christopher Kohlhoff
4569c722ec Add execution::operation_state concept and execution::is_operation_state trait. 2020-06-30 22:08:19 +10:00
Christopher Kohlhoff
ca3a44ea3c Add execution::start() customisation point object. 2020-06-30 22:07:21 +10:00
Christopher Kohlhoff
4d8e791a8f Add execution::receiver concepts and traits.
This change adds the concepts:

  * execution::receiver
  * execution::receiver_of

and the trait:

  * execution::is_nothrow_receiver_of

It also adds the following traits that correspond to the concepts:

  * execution::is_receiver
  * execution::is_receiver_of
2020-06-30 22:02:21 +10:00
Christopher Kohlhoff
b68f15843c Add execution::set_value() customisation point object. 2020-06-30 21:55:37 +10:00
Christopher Kohlhoff
bd5acb1d51 Add execution::set_done() customisation point object. 2020-06-30 21:54:13 +10:00