Skip to content

Commit 5cd36d3

Browse files
committed
Sync capy changes
Upstream introduced capy::continuation as the executor-facing schedulable unit, so executors now take continuation& in dispatch and post. io_result also tightened to std::error_code. Update the bcrypt async ops to hold a continuation member and dispatch through it, and switch json_sink to std::error_code at the io_result boundary. Test executors updated to match the new concept.
1 parent 772b3c7 commit 5cd36d3

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

include/boost/http/bcrypt.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <boost/system/error_code.hpp>
4242
#include <boost/system/is_error_code_enum.hpp>
4343

44+
#include <boost/capy/continuation.hpp>
4445
#include <boost/capy/task.hpp>
4546
#include <boost/capy/ex/executor_ref.hpp>
4647
#include <boost/capy/ex/io_env.hpp>
@@ -524,6 +525,7 @@ struct hash_async_op
524525
version ver_;
525526
result result_;
526527
std::exception_ptr ep_;
528+
capy::continuation cont_;
527529

528530
bool await_ready() const noexcept
529531
{
@@ -534,21 +536,22 @@ struct hash_async_op
534536
std::coroutine_handle<void> cont,
535537
capy::io_env const* env)
536538
{
539+
cont_.h = cont;
537540
auto caller_ex = env->executor;
538541
auto& pool = capy::get_system_context();
539542
auto sys_ex = pool.get_executor();
540543
capy::run_async(sys_ex,
541-
[this, cont, caller_ex]
544+
[this, caller_ex]
542545
(result r) mutable
543546
{
544547
result_ = r;
545-
caller_ex.dispatch(cont).resume();
548+
caller_ex.dispatch(cont_).resume();
546549
},
547-
[this, cont, caller_ex]
550+
[this, caller_ex]
548551
(std::exception_ptr ep) mutable
549552
{
550553
ep_ = ep;
551-
caller_ex.dispatch(cont).resume();
554+
caller_ex.dispatch(cont_).resume();
552555
}
553556
)(hash_task(password_, rounds_, ver_));
554557
}
@@ -567,6 +570,7 @@ struct compare_async_op
567570
hash_buf hash_str_;
568571
bool result_ = false;
569572
std::exception_ptr ep_;
573+
capy::continuation cont_;
570574

571575
bool await_ready() const noexcept
572576
{
@@ -577,21 +581,22 @@ struct compare_async_op
577581
std::coroutine_handle<void> cont,
578582
capy::io_env const* env)
579583
{
584+
cont_.h = cont;
580585
auto caller_ex = env->executor;
581586
auto& pool = capy::get_system_context();
582587
auto sys_ex = pool.get_executor();
583588
capy::run_async(sys_ex,
584-
[this, cont, caller_ex]
589+
[this, caller_ex]
585590
(bool ok) mutable
586591
{
587592
result_ = ok;
588-
caller_ex.dispatch(cont).resume();
593+
caller_ex.dispatch(cont_).resume();
589594
},
590-
[this, cont, caller_ex]
595+
[this, caller_ex]
591596
(std::exception_ptr ep) mutable
592597
{
593598
ep_ = ep;
594-
caller_ex.dispatch(cont).resume();
599+
caller_ex.dispatch(cont_).resume();
595600
}
596601
)(compare_task(password_, hash_str_));
597602
}

include/boost/http/json/json_sink.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class json_sink
6060
capy::immediate<capy::io_result<std::size_t>>
6161
write_impl(CB const& buffers, bool eof)
6262
{
63-
system::error_code ec;
63+
std::error_code ec;
6464
std::size_t total = 0;
6565
auto const end = capy::end(buffers);
6666
for(auto it = capy::begin(buffers); it != end; ++it)
@@ -71,14 +71,14 @@ class json_sink
7171
buf.size(),
7272
ec);
7373
total += n;
74-
if(ec.failed())
75-
return {ec, total};
74+
if(ec)
75+
return capy::ready(ec, total);
7676
}
7777
if(eof)
7878
{
7979
parser_.finish(ec);
80-
if(ec.failed())
81-
return {ec, total};
80+
if(ec)
81+
return capy::ready(ec, total);
8282
}
8383
return capy::ready(total);
8484
}
@@ -188,11 +188,11 @@ class json_sink
188188
capy::immediate<capy::io_result<>>
189189
write_eof()
190190
{
191-
system::error_code ec;
191+
std::error_code ec;
192192
parser_.finish(ec);
193-
if(ec.failed())
194-
return {ec};
195-
return {};
193+
if(ec)
194+
return capy::ready(ec);
195+
return capy::ready();
196196
}
197197

198198
/** Check if parsing is complete.

test/unit/bcrypt.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <boost/http/bcrypt.hpp>
1111

12+
#include <boost/capy/continuation.hpp>
1213
#include <boost/capy/ex/execution_context.hpp>
1314
#include <boost/capy/ex/run_async.hpp>
1415
#include <boost/capy/ex/system_context.hpp>
@@ -50,14 +51,14 @@ struct test_executor
5051
void on_work_started() const noexcept {}
5152
void on_work_finished() const noexcept {}
5253

53-
std::coroutine_handle<> dispatch(std::coroutine_handle<void> h) const
54+
std::coroutine_handle<> dispatch(capy::continuation& c) const
5455
{
55-
return h;
56+
return c.h;
5657
}
5758

58-
void post(std::coroutine_handle<void> h) const
59+
void post(capy::continuation& c) const
5960
{
60-
h.resume();
61+
c.h.resume();
6162
}
6263
};
6364

test/unit/json/json_sink.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/capy/buffers.hpp>
1414
#include <boost/capy/buffers/make_buffer.hpp>
1515
#include <boost/capy/concept/write_sink.hpp>
16+
#include <boost/capy/continuation.hpp>
1617
#include <boost/capy/ex/execution_context.hpp>
1718
#include <boost/capy/ex/run_async.hpp>
1819
#include <boost/capy/io_result.hpp>
@@ -67,16 +68,16 @@ struct test_executor
6768
void on_work_started() const noexcept {}
6869
void on_work_finished() const noexcept {}
6970

70-
std::coroutine_handle<> dispatch(std::coroutine_handle<void> h) const
71+
std::coroutine_handle<> dispatch(capy::continuation& c) const
7172
{
7273
if(dispatch_count_)
7374
++(*dispatch_count_);
74-
return h;
75+
return c.h;
7576
}
7677

77-
void post(std::coroutine_handle<void> h) const
78+
void post(capy::continuation& c) const
7879
{
79-
h.resume();
80+
c.h.resume();
8081
}
8182
};
8283

0 commit comments

Comments
 (0)