Skip to content

Commit 21aaefc

Browse files
committed
Thirdparty: update Asio to 1.20
1 parent f2144c0 commit 21aaefc

File tree

9 files changed

+243
-15
lines changed

9 files changed

+243
-15
lines changed

thirdparty/asio/asio/cancellation_state.hpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,38 @@ class cancellation_state
8686
}
8787

8888
/// Construct and attach to a parent slot to create a new child slot.
89+
/**
90+
* Initialises the cancellation state so that it allows terminal cancellation
91+
* only. Equivalent to <tt>cancellation_state(slot,
92+
* enable_terminal_cancellation())</tt>.
93+
*
94+
* @param slot The parent cancellation slot to which the state will be
95+
* attached.
96+
*/
8997
template <typename CancellationSlot>
9098
ASIO_CONSTEXPR explicit cancellation_state(CancellationSlot slot)
9199
: impl_(slot.is_connected() ? &slot.template emplace<impl<> >() : 0)
92100
{
93101
}
94102

95103
/// Construct and attach to a parent slot to create a new child slot.
104+
/**
105+
* @param slot The parent cancellation slot to which the state will be
106+
* attached.
107+
*
108+
* @param filter A function object that is used to transform incoming
109+
* cancellation signals as they are received from the parent slot. This
110+
* function object must have the signature:
111+
* @code asio::cancellation_type_t filter(
112+
* asio::cancellation_type_t); @endcode
113+
*
114+
* The library provides the following pre-defined cancellation filters:
115+
*
116+
* @li asio::disable_cancellation
117+
* @li asio::enable_terminal_cancellation
118+
* @li asio::enable_partial_cancellation
119+
* @li asio::enable_total_cancellation
120+
*/
96121
template <typename CancellationSlot, typename Filter>
97122
ASIO_CONSTEXPR cancellation_state(CancellationSlot slot, Filter filter)
98123
: impl_(slot.is_connected()
@@ -102,6 +127,29 @@ class cancellation_state
102127
}
103128

104129
/// Construct and attach to a parent slot to create a new child slot.
130+
/**
131+
* @param slot The parent cancellation slot to which the state will be
132+
* attached.
133+
*
134+
* @param in_filter A function object that is used to transform incoming
135+
* cancellation signals as they are received from the parent slot. This
136+
* function object must have the signature:
137+
* @code asio::cancellation_type_t in_filter(
138+
* asio::cancellation_type_t); @endcode
139+
*
140+
* @param out_filter A function object that is used to transform outcoming
141+
* cancellation signals as they are relayed to the child slot. This function
142+
* object must have the signature:
143+
* @code asio::cancellation_type_t out_filter(
144+
* asio::cancellation_type_t); @endcode
145+
*
146+
* The library provides the following pre-defined cancellation filters:
147+
*
148+
* @li asio::disable_cancellation
149+
* @li asio::enable_terminal_cancellation
150+
* @li asio::enable_partial_cancellation
151+
* @li asio::enable_total_cancellation
152+
*/
105153
template <typename CancellationSlot, typename InFilter, typename OutFilter>
106154
ASIO_CONSTEXPR cancellation_state(CancellationSlot slot,
107155
InFilter in_filter, OutFilter out_filter)
@@ -122,7 +170,7 @@ class cancellation_state
122170
return impl_ ? impl_->signal_.slot() : cancellation_slot();
123171
}
124172

125-
/// Returns specified cancellation types have been triggered.
173+
/// Returns the cancellation types that have been triggered.
126174
cancellation_type_t cancelled() const ASIO_NOEXCEPT
127175
{
128176
return impl_ ? impl_->cancelled_ : cancellation_type_t();

thirdparty/asio/asio/co_spawn.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ struct awaitable_signature<awaitable<void, Executor>>
9595
* std::cout << "transferred " << n << "\n";
9696
* });
9797
* @endcode
98+
*
99+
* @par Per-Operation Cancellation
100+
* The new thread of execution is created with a cancellation state that
101+
* supports @c cancellation_type::terminal values only. To change the
102+
* cancellation state, call asio::this_coro::reset_cancellation_state.
98103
*/
99104
template <typename Executor, typename T, typename AwaitableExecutor,
100105
ASIO_COMPLETION_TOKEN_FOR(
@@ -151,6 +156,11 @@ co_spawn(const Executor& ex, awaitable<T, AwaitableExecutor> a,
151156
* echo(std::move(my_tcp_socket)),
152157
* asio::detached);
153158
* @endcode
159+
*
160+
* @par Per-Operation Cancellation
161+
* The new thread of execution is created with a cancellation state that
162+
* supports @c cancellation_type::terminal values only. To change the
163+
* cancellation state, call asio::this_coro::reset_cancellation_state.
154164
*/
155165
template <typename Executor, typename AwaitableExecutor,
156166
ASIO_COMPLETION_TOKEN_FOR(
@@ -215,6 +225,11 @@ co_spawn(const Executor& ex, awaitable<void, AwaitableExecutor> a,
215225
* std::cout << "transferred " << n << "\n";
216226
* });
217227
* @endcode
228+
*
229+
* @par Per-Operation Cancellation
230+
* The new thread of execution is created with a cancellation state that
231+
* supports @c cancellation_type::terminal values only. To change the
232+
* cancellation state, call asio::this_coro::reset_cancellation_state.
218233
*/
219234
template <typename ExecutionContext, typename T, typename AwaitableExecutor,
220235
ASIO_COMPLETION_TOKEN_FOR(
@@ -274,6 +289,11 @@ co_spawn(ExecutionContext& ctx, awaitable<T, AwaitableExecutor> a,
274289
* echo(std::move(my_tcp_socket)),
275290
* asio::detached);
276291
* @endcode
292+
*
293+
* @par Per-Operation Cancellation
294+
* The new thread of execution is created with a cancellation state that
295+
* supports @c cancellation_type::terminal values only. To change the
296+
* cancellation state, call asio::this_coro::reset_cancellation_state.
277297
*/
278298
template <typename ExecutionContext, typename AwaitableExecutor,
279299
ASIO_COMPLETION_TOKEN_FOR(
@@ -309,7 +329,6 @@ co_spawn(ExecutionContext& ctx, awaitable<void, AwaitableExecutor> a,
309329
* Otherwise, the function signature of the completion handler must be:
310330
* @code void handler(std::exception_ptr, R); @endcode
311331
*
312-
*
313332
* @par Example
314333
* @code
315334
* asio::awaitable<std::size_t> echo(tcp::socket socket)
@@ -361,6 +380,11 @@ co_spawn(ExecutionContext& ctx, awaitable<void, AwaitableExecutor> a,
361380
* }
362381
* }, asio::detached);
363382
* @endcode
383+
*
384+
* @par Per-Operation Cancellation
385+
* The new thread of execution is created with a cancellation state that
386+
* supports @c cancellation_type::terminal values only. To change the
387+
* cancellation state, call asio::this_coro::reset_cancellation_state.
364388
*/
365389
template <typename Executor, typename F,
366390
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
@@ -392,7 +416,6 @@ co_spawn(const Executor& ex, F&& f,
392416
* Otherwise, the function signature of the completion handler must be:
393417
* @code void handler(std::exception_ptr, R); @endcode
394418
*
395-
*
396419
* @par Example
397420
* @code
398421
* asio::awaitable<std::size_t> echo(tcp::socket socket)
@@ -444,6 +467,11 @@ co_spawn(const Executor& ex, F&& f,
444467
* }
445468
* }, asio::detached);
446469
* @endcode
470+
*
471+
* @par Per-Operation Cancellation
472+
* The new thread of execution is created with a cancellation state that
473+
* supports @c cancellation_type::terminal values only. To change the
474+
* cancellation state, call asio::this_coro::reset_cancellation_state.
447475
*/
448476
template <typename ExecutionContext, typename F,
449477
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<

thirdparty/asio/asio/experimental/coro.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ struct coro_promise final :
956956
}
957957

958958
template <execution_context Context, typename... Args>
959-
coro_promise(Context& ctx, Args &&...) noexcept
959+
coro_promise(Context&& ctx, Args&&...) noexcept
960960
: executor_(ctx.get_executor())
961961
{
962962
}

thirdparty/asio/asio/experimental/detail/coro_promise_allocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct coro_promise_allocator
4242
}
4343

4444
template <execution_context Context, typename... Args>
45-
void* operator new(const std::size_t size, Context& ctx, Args&&... args)
45+
void* operator new(const std::size_t size, Context&& ctx, Args&&... args)
4646
{
4747
return coro_promise_allocator::operator new(size,
4848
ctx.get_executor(), std::forward<Args>(args)...);
@@ -89,7 +89,7 @@ struct coro_promise_allocator<Coroutine, Executor, Allocator, true>
8989

9090
template <execution_context Context, typename... Args>
9191
void* operator new(const std::size_t size,
92-
Context& ctx, Args&&... args) noexcept
92+
Context&& ctx, Args&&... args) noexcept
9393
{
9494
return coro_promise_allocator::operator new(size,
9595
ctx.get_executor(), std::forward<Args>(args)...);

thirdparty/asio/asio/experimental/detail/partial_promise.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ namespace std {
9494

9595
template<typename ... Args>
9696
struct coroutine_traits<
97-
std::experimental::coroutine_handle<coro::partial_promise>, Args...>
97+
coroutine_handle<asio::experimental::detail::partial_promise>,
98+
Args...>
9899
{
99-
using promise_type = coro::partial_promise;
100+
using promise_type = asio::experimental::detail::partial_promise;
100101
};
101102

102103
} // namespace std

thirdparty/asio/asio/experimental/parallel_group.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ void parallel_group_launch(Condition cancellation_condition, Handler handler,
9898
} // namespace detail
9999

100100
/// A group of asynchronous operations that may be launched in parallel.
101+
/**
102+
* See the documentation for asio::experimental::make_parallel_group for
103+
* a usage example.
104+
*/
101105
template <typename... Ops>
102106
class parallel_group
103107
{
@@ -113,6 +117,27 @@ class parallel_group
113117
typename detail::parallel_op_signature<Ops>::type...>::type signature;
114118

115119
/// Initiate an asynchronous wait for the group of operations.
120+
/**
121+
* Launches the group and asynchronously waits for completion.
122+
*
123+
* @param cancellation_condition A function object, called on completion of
124+
* an operation within the group, that is used to determine whether to cancel
125+
* the remaining operations. The function object is passed the arguments of
126+
* the completed operation's handler. To trigger cancellation of the remaining
127+
* operations, it must return a asio::cancellation_type value other
128+
* than <tt>asio::cancellation_type::none</tt>.
129+
*
130+
* @param token A completion token whose signature is comprised of
131+
* a @c std::array<std::size_t, N> indicating the completion order of the
132+
* operations, followed by all operations' completion handler arguments.
133+
*
134+
* The library provides the following @c cancellation_condition types:
135+
*
136+
* @li asio::experimental::wait_for_all
137+
* @li asio::experimental::wait_for_one
138+
* @li asio::experimental::wait_for_one_error
139+
* @li asio::experimental::wait_for_one_success
140+
*/
116141
template <typename CancellationCondition,
117142
ASIO_COMPLETION_TOKEN_FOR(signature) CompletionToken>
118143
auto async_wait(CancellationCondition cancellation_condition,
@@ -138,6 +163,42 @@ class parallel_group
138163
};
139164

140165
/// Create a group of operations that may be launched in parallel.
166+
/**
167+
* For example:
168+
* @code asio::experimental::make_parallel_group(
169+
* [&](auto token)
170+
* {
171+
* return in.async_read_some(asio::buffer(data), token);
172+
* },
173+
* [&](auto token)
174+
* {
175+
* return timer.async_wait(token);
176+
* }
177+
* ).async_wait(
178+
* asio::experimental::wait_for_all(),
179+
* [](
180+
* std::array<std::size_t, 2> completion_order,
181+
* std::error_code ec1, std::size_t n1,
182+
* std::error_code ec2
183+
* )
184+
* {
185+
* switch (completion_order[0])
186+
* {
187+
* case 0:
188+
* {
189+
* std::cout << "descriptor finished: " << ec1 << ", " << n1 << "\n";
190+
* }
191+
* break;
192+
* case 1:
193+
* {
194+
* std::cout << "timer finished: " << ec2 << "\n";
195+
* }
196+
* break;
197+
* }
198+
* }
199+
* );
200+
* @endcode
201+
*/
141202
template <typename... Ops>
142203
inline parallel_group<Ops...> make_parallel_group(Ops... ops)
143204
{

thirdparty/asio/asio/experimental/promise.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct promise<void(Ts...), Executor>
8989

9090
void cancel(cancellation_type level = cancellation_type::all)
9191
{
92-
if (impl_)
92+
if (impl_ && !impl_->done)
9393
{
9494
asio::dispatch(impl_->executor,
9595
[level, impl = impl_]{impl->cancel.emit(level);});
@@ -145,7 +145,7 @@ struct promise<void(Ts...), Executor>
145145
{
146146
[ct, s=self]<std::size_t... Idx>(std::index_sequence<Idx...>)
147147
{
148-
(get<Idx>(s->tup).cancel(ct), ... );
148+
(std::get<Idx>(s->tup).cancel(ct), ... );
149149
}(std::make_index_sequence<sizeof...(Ps)>{});
150150
}
151151
};
@@ -225,7 +225,7 @@ struct promise<void(Ts...), Executor>
225225
{
226226
[level, s=self]<std::size_t... Idx>(std::index_sequence<Idx...>)
227227
{
228-
(get<Idx>(s->tup).cancel(level), ... );
228+
(std::get<Idx>(s->tup).cancel(level), ... );
229229
}(std::make_index_sequence<sizeof...(Ps)>{});
230230
}
231231
};
@@ -246,10 +246,11 @@ struct promise<void(Ts...), Executor>
246246
{
247247
return [impl]<typename... Args>(Args&& ... args)
248248
{
249-
get<I>(impl->partial_result).emplace(std::forward<Args>(args)...);
250-
if ((get<Idx>(impl->partial_result) && ...)) // we're done.
249+
std::get<I>(impl->partial_result).emplace(
250+
std::forward<Args>(args)...);
251+
if ((std::get<Idx>(impl->partial_result) && ...)) // we're done.
251252
{
252-
impl->result = {*get<Idx>(impl->partial_result)...};
253+
impl->result = {*std::get<Idx>(impl->partial_result)...};
253254

254255
impl->done = true;
255256
if (auto f = std::exchange(impl->completion, nullptr); !!f)

0 commit comments

Comments
 (0)