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

103 Commits

Author SHA1 Message Date
Christopher Kohlhoff
edbde3cdce Disable deprecated messages when building tests. 2025-11-04 23:48:36 +11:00
Christopher Kohlhoff
f49a0add53 Add redirect_disposition completion token adapter. 2025-11-04 23:42:51 +11:00
Christopher Kohlhoff
5fa261e86d Add inline_or_executor<> and inline_or(). 2025-10-30 08:28:04 +11:00
Christopher Kohlhoff
84c45dbe48 Add inline_executor. 2025-10-29 22:58:47 +11:00
Christopher Kohlhoff
1afbc5c12b Update copyright notices. 2025-03-04 22:57:26 +11:00
Christopher Kohlhoff
7955d57329 Add unit test for spawn(). 2024-11-06 07:55:31 +11:00
Rene Rivera
a31cca5ec1 Add support for modular build structure. 2024-10-31 21:42:07 +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
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
c36d3ef338 Update copyright notices. 2024-03-05 07:51:17 +11:00
Christopher Kohlhoff
cb2535142e Add unit test for any_completion_handler. 2023-07-05 20:08:49 +10:00
Christopher Kohlhoff
e4c5a437b3 Add unit test for any_completion_executor. 2023-07-05 20:08:01 +10:00
Christopher Kohlhoff
78593611ff Add unit test for any_io_executor. 2023-07-05 20:07:33 +10: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
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
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
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
5145c8f83d Add self-container-header checks for cancellation functionality. 2021-07-01 10:52:01 +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
723982b867 Update copyright notices. 2021-02-25 08:29:05 +11:00
Christopher Kohlhoff
fcd09b9c81 Build execution tests. 2020-06-26 16:42:45 +10:00
Christopher Kohlhoff
0a662cb309 Add static_thread_pool (as thread_pool in standard executor form). 2020-06-23 10:36:49 +10:00
Christopher Kohlhoff
f34dd4cf2b Add unit test for thread_pool. 2020-06-22 20:55:57 +10:00
Christopher Kohlhoff
4b552cfd5b Update copyright notices. 2020-04-07 11:15:42 +10: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
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
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
0b2db4b84e Remove deprecated services support. 2019-02-17 19:59:01 -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
886839cf55 Update copyright notices. 2018-03-04 21:59:30 +11:00
Christopher Kohlhoff
077ed86047 Add headers for TS compatibility. 2017-12-02 10:23:24 +11:00