2
0
mirror of https://github.com/boostorg/asio.git synced 2026-02-02 20:32:08 +00:00

Allow bind_executor to be used as a partial completion token.

This commit is contained in:
Christopher Kohlhoff
2024-06-26 22:43:11 +10:00
parent 561e752d92
commit 85535cec19
2 changed files with 136 additions and 16 deletions

View File

@@ -21,22 +21,10 @@
#include <boost/asio/steady_timer.hpp>
#include "unit_test.hpp"
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/deadline_timer.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/steady_timer.hpp>
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
using namespace boost::asio;
namespace bindns = std;
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
typedef deadline_timer timer;
namespace chronons = boost::posix_time;
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
typedef steady_timer timer;
namespace chronons = boost::asio::chrono;
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
void increment(int* count)
{
@@ -184,10 +172,46 @@ void bind_executor_to_completion_token_v2_test()
BOOST_ASIO_CHECK(count == 1);
}
void partial_bind_executor_test()
{
io_context ioc1;
io_context ioc2;
int count = 0;
timer t(ioc1, chronons::seconds(1));
t.async_wait(bind_executor(ioc2.get_executor()))(
bindns::bind(&increment, &count));
ioc1.run();
BOOST_ASIO_CHECK(count == 0);
ioc2.run();
BOOST_ASIO_CHECK(count == 1);
t.expires_after(chronons::seconds(1));
t.async_wait()(
bind_executor(ioc2.get_executor()))(
incrementer_token_v2(&count));
ioc1.restart();
ioc1.run();
BOOST_ASIO_CHECK(count == 1);
ioc2.restart();
ioc2.run();
BOOST_ASIO_CHECK(count == 2);
}
BOOST_ASIO_TEST_SUITE
(
"bind_executor",
BOOST_ASIO_TEST_CASE(bind_executor_to_function_object_test)
BOOST_ASIO_TEST_CASE(bind_executor_to_completion_token_v1_test)
BOOST_ASIO_TEST_CASE(bind_executor_to_completion_token_v2_test)
BOOST_ASIO_TEST_CASE(partial_bind_executor_test)
)