-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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_; asio::mutable_buffer buffer_; enum { starting, reading, writing } state_; template <typename Self> void operator()(Self& self, asio::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; asio::async_write(socket_, buffer_, asio::transfer_exactly(n), std::move(self)); } break; case writing: self.complete(error, n); break; } } }; template <typename CompletionToken> auto async_echo(tcp::socket& socket, asio::mutable_buffer buffer, CompletionToken&& token) { return asio::async_initiate<CompletionToken, void(asio::error_code, std::size_t)>( asio::composed( async_echo_implementation{socket, buffer, async_echo_implementation::starting}, socket), token, asio::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.
- Loading branch information
1 parent
62ca124
commit 7a161ee
Showing
9 changed files
with
961 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.