Skip to content

Commit

Permalink
If possible, don't use boost::asio::spawn() overload removed in v1.87
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jan 10, 2025
1 parent 5e19a3d commit fc72bb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/base/io-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
#include <utility>
#include <vector>
#include <stdexcept>
#include <boost/context/fixedsize_stack.hpp>
#include <boost/exception/all.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>

#if BOOST_VERSION >= 108000
# include <boost/asio/detached.hpp>
#endif // BOOST_VERSION >= 108000

namespace icinga
{

Expand Down Expand Up @@ -102,6 +107,10 @@ class IoEngine
static void SpawnCoroutine(Handler& h, Function f) {

boost::asio::spawn(h,
#if BOOST_VERSION >= 108000
std::allocator_arg_t(),
boost::context::fixedsize_stack(GetCoroutineStackSize()),
#endif // BOOST_VERSION >= 108000
[f](boost::asio::yield_context yc) {

try {
Expand All @@ -119,7 +128,11 @@ class IoEngine
throw;
}
},
#if BOOST_VERSION >= 108000
boost::asio::detached
#else // BOOST_VERSION >= 108000
boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
#endif // BOOST_VERSION >= 108000
);
}

Expand Down
10 changes: 5 additions & 5 deletions test/base-io-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE(timeout_run)
boost::asio::io_context::strand strand (io);
int called = 0;

boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
boost::asio::deadline_timer timer (io);

Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });
Expand All @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(timeout_cancelled)
boost::asio::io_context::strand strand (io);
int called = 0;

boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
boost::asio::deadline_timer timer (io);
Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });

Expand All @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(timeout_scope)
boost::asio::io_context::strand strand (io);
int called = 0;

boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
boost::asio::deadline_timer timer (io);

{
Expand Down Expand Up @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_cancelled)
boost::asio::io_context::strand strand (io);
int called = 0;

boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
boost::asio::deadline_timer timer (io);
Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });

Expand Down Expand Up @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_scope)
boost::asio::io_context::strand strand (io);
int called = 0;

boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
boost::asio::deadline_timer timer (io);

{
Expand Down

0 comments on commit fc72bb7

Please sign in to comment.