Skip to content

Commit 520aed6

Browse files
authored
Merge pull request #10278 from Icinga/boost187
Bump Boost shipped for Windows to v1.87
2 parents 9cc3971 + d3fae44 commit 520aed6

10 files changed

+48
-76
lines changed

doc/win-dev.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function ThrowOnNativeFailure {
1313

1414
$VsVersion = 2019
1515
$MsvcVersion = '14.2'
16-
$BoostVersion = @(1, 86, 0)
16+
$BoostVersion = @(1, 87, 0)
1717
$OpensslVersion = '3_0_15'
1818

1919
switch ($Env:BITS) {

lib/base/io-engine.hpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
#include <utility>
1717
#include <vector>
1818
#include <stdexcept>
19+
#include <boost/context/fixedsize_stack.hpp>
1920
#include <boost/exception/all.hpp>
2021
#include <boost/asio/deadline_timer.hpp>
2122
#include <boost/asio/io_context.hpp>
2223
#include <boost/asio/spawn.hpp>
2324

25+
#if BOOST_VERSION >= 108700
26+
# include <boost/asio/detached.hpp>
27+
#endif // BOOST_VERSION >= 108700
28+
2429
namespace icinga
2530
{
2631

@@ -100,24 +105,32 @@ class IoEngine
100105

101106
template <typename Handler, typename Function>
102107
static void SpawnCoroutine(Handler& h, Function f) {
103-
104-
boost::asio::spawn(h,
105-
[f](boost::asio::yield_context yc) {
106-
108+
auto wrapper = [f = std::move(f)](boost::asio::yield_context yc) {
109+
try {
110+
f(yc);
111+
} catch (const std::exception& ex) {
112+
Log(LogCritical, "IoEngine") << "Exception in coroutine: " << DiagnosticInformation(ex);
113+
} catch (...) {
107114
try {
108-
f(yc);
109-
} catch (const boost::coroutines::detail::forced_unwind &) {
110-
// Required for proper stack unwinding when coroutines are destroyed.
111-
// https://github.com/boostorg/coroutine/issues/39
112-
throw;
113-
} catch (const std::exception& ex) {
114-
Log(LogCritical, "IoEngine") << "Exception in coroutine: " << DiagnosticInformation(ex);
115-
} catch (...) {
116115
Log(LogCritical, "IoEngine", "Exception in coroutine!");
116+
} catch (...) {
117117
}
118-
},
119-
boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
118+
119+
// Required for proper stack unwinding when coroutines are destroyed.
120+
// https://github.com/boostorg/coroutine/issues/39
121+
throw;
122+
}
123+
};
124+
125+
#if BOOST_VERSION >= 108700
126+
boost::asio::spawn(h,
127+
std::allocator_arg, boost::context::fixedsize_stack(GetCoroutineStackSize()),
128+
std::move(wrapper),
129+
boost::asio::detached
120130
);
131+
#else // BOOST_VERSION >= 108700
132+
boost::asio::spawn(h, std::move(wrapper), boost::coroutines::attributes(GetCoroutineStackSize()));
133+
#endif // BOOST_VERSION >= 108700
121134
}
122135

123136
static inline

lib/base/tcpsocket.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void Connect(Socket& socket, const String& node, const String& service)
4141
using boost::asio::ip::tcp;
4242

4343
tcp::resolver resolver (IoEngine::Get().GetIoContext());
44-
tcp::resolver::query query (node, service);
45-
auto result (resolver.resolve(query));
44+
auto result (resolver.resolve(node.GetData(), service.GetData()));
4645
auto current (result.begin());
4746

4847
for (;;) {
@@ -72,8 +71,7 @@ void Connect(Socket& socket, const String& node, const String& service, boost::a
7271
using boost::asio::ip::tcp;
7372

7473
tcp::resolver resolver (IoEngine::Get().GetIoContext());
75-
tcp::resolver::query query (node, service);
76-
auto result (resolver.async_resolve(query, yc));
74+
auto result (resolver.async_resolve(node.GetData(), service.GetData(), yc));
7775
auto current (result.begin());
7876

7977
for (;;) {

lib/icingadb/redisconnection.cpp

+4-37
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ void RedisConnection::Connect(asio::yield_context& yc)
377377
}
378378

379379
break;
380-
} catch (const boost::coroutines::detail::forced_unwind&) {
381-
throw;
382380
} catch (const std::exception& ex) {
383381
Log(LogCritical, "IcingaDB")
384382
<< "Cannot connect to " << m_Host << ":" << m_Port << ": " << ex.what();
@@ -408,17 +406,10 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
408406
for (auto i (item.Amount); i; --i) {
409407
ReadOne(yc);
410408
}
411-
} catch (const boost::coroutines::detail::forced_unwind&) {
412-
throw;
413409
} catch (const std::exception& ex) {
414410
Log(LogCritical, "IcingaDB")
415411
<< "Error during receiving the response to a query which has been fired and forgotten: " << ex.what();
416412

417-
continue;
418-
} catch (...) {
419-
Log(LogCritical, "IcingaDB")
420-
<< "Error during receiving the response to a query which has been fired and forgotten";
421-
422413
continue;
423414
}
424415

@@ -432,9 +423,7 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
432423

433424
try {
434425
reply = ReadOne(yc);
435-
} catch (const boost::coroutines::detail::forced_unwind&) {
436-
throw;
437-
} catch (...) {
426+
} catch (const std::exception&) {
438427
promise.set_exception(std::current_exception());
439428

440429
continue;
@@ -455,9 +444,7 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
455444
for (auto i (item.Amount); i; --i) {
456445
try {
457446
replies.emplace_back(ReadOne(yc));
458-
} catch (const boost::coroutines::detail::forced_unwind&) {
459-
throw;
460-
} catch (...) {
447+
} catch (const std::exception&) {
461448
promise.set_exception(std::current_exception());
462449
break;
463450
}
@@ -551,19 +538,11 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
551538

552539
try {
553540
WriteOne(item, yc);
554-
} catch (const boost::coroutines::detail::forced_unwind&) {
555-
throw;
556541
} catch (const std::exception& ex) {
557542
Log msg (LogCritical, "IcingaDB", "Error during sending query");
558543
LogQuery(item, msg);
559544
msg << " which has been fired and forgotten: " << ex.what();
560545

561-
return;
562-
} catch (...) {
563-
Log msg (LogCritical, "IcingaDB", "Error during sending query");
564-
LogQuery(item, msg);
565-
msg << " which has been fired and forgotten";
566-
567546
return;
568547
}
569548

@@ -587,19 +566,11 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
587566
WriteOne(query, yc);
588567
++i;
589568
}
590-
} catch (const boost::coroutines::detail::forced_unwind&) {
591-
throw;
592569
} catch (const std::exception& ex) {
593570
Log msg (LogCritical, "IcingaDB", "Error during sending query");
594571
LogQuery(item[i], msg);
595572
msg << " which has been fired and forgotten: " << ex.what();
596573

597-
return;
598-
} catch (...) {
599-
Log msg (LogCritical, "IcingaDB", "Error during sending query");
600-
LogQuery(item[i], msg);
601-
msg << " which has been fired and forgotten";
602-
603574
return;
604575
}
605576

@@ -618,9 +589,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
618589

619590
try {
620591
WriteOne(item.first, yc);
621-
} catch (const boost::coroutines::detail::forced_unwind&) {
622-
throw;
623-
} catch (...) {
592+
} catch (const std::exception&) {
624593
item.second.set_exception(std::current_exception());
625594

626595
return;
@@ -645,9 +614,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
645614
for (auto& query : item.first) {
646615
WriteOne(query, yc);
647616
}
648-
} catch (const boost::coroutines::detail::forced_unwind&) {
649-
throw;
650-
} catch (...) {
617+
} catch (const std::exception&) {
651618
item.second.set_exception(std::current_exception());
652619

653620
return;

lib/icingadb/redisconnection.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ RedisConnection::Reply RedisConnection::ReadOne(StreamPtr& stream, boost::asio::
389389

390390
try {
391391
return ReadRESP(*strm, yc);
392-
} catch (const boost::coroutines::detail::forced_unwind&) {
393-
throw;
394-
} catch (...) {
392+
} catch (const std::exception&) {
395393
if (m_Connecting.exchange(false)) {
396394
m_Connected.store(false);
397395
stream = nullptr;
@@ -427,9 +425,7 @@ void RedisConnection::WriteOne(StreamPtr& stream, RedisConnection::Query& query,
427425
try {
428426
WriteRESP(*strm, query, yc);
429427
strm->async_flush(yc);
430-
} catch (const boost::coroutines::detail::forced_unwind&) {
431-
throw;
432-
} catch (...) {
428+
} catch (const std::exception&) {
433429
if (m_Connecting.exchange(false)) {
434430
m_Connected.store(false);
435431
stream = nullptr;

lib/remote/apilistener.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ bool ApiListener::AddListener(const String& node, const String& service)
439439

440440
try {
441441
tcp::resolver resolver (io);
442-
tcp::resolver::query query (node, service, tcp::resolver::query::passive);
443-
444-
auto result (resolver.resolve(query));
442+
auto result (resolver.resolve(node.GetData(), service.GetData(), tcp::resolver::passive));
445443
auto current (result.begin());
446444

447445
for (;;) {

lib/remote/jsonrpcconnection.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message)
212212

213213
Ptr keepAlive (this);
214214

215-
m_IoStrand.post([this, keepAlive, message]() { SendMessageInternal(message); });
215+
boost::asio::post(m_IoStrand, [this, keepAlive, message] { SendMessageInternal(message); });
216216
}
217217

218218
void JsonRpcConnection::SendRawMessage(const String& message)
@@ -223,7 +223,7 @@ void JsonRpcConnection::SendRawMessage(const String& message)
223223

224224
Ptr keepAlive (this);
225225

226-
m_IoStrand.post([this, keepAlive, message]() {
226+
boost::asio::post(m_IoStrand, [this, keepAlive, message] {
227227
if (m_ShuttingDown) {
228228
return;
229229
}

test/base-io-engine.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE(timeout_run)
1717
boost::asio::io_context::strand strand (io);
1818
int called = 0;
1919

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

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

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

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

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

7777
{
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_cancelled)
100100
boost::asio::io_context::strand strand (io);
101101
int called = 0;
102102

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

@@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_scope)
131131
boost::asio::io_context::strand strand (io);
132132
int called = 0;
133133

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

137137
{

tools/win32/configure-dev.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ if (-not (Test-Path env:OPENSSL_ROOT_DIR)) {
3434
$env:OPENSSL_ROOT_DIR = 'c:\local\OpenSSL-Win64'
3535
}
3636
if (-not (Test-Path env:BOOST_ROOT)) {
37-
$env:BOOST_ROOT = 'c:\local\boost_1_86_0'
37+
$env:BOOST_ROOT = 'c:\local\boost_1_87_0'
3838
}
3939
if (-not (Test-Path env:BOOST_LIBRARYDIR)) {
40-
$env:BOOST_LIBRARYDIR = 'c:\local\boost_1_86_0\lib64-msvc-14.2'
40+
$env:BOOST_LIBRARYDIR = 'c:\local\boost_1_87_0\lib64-msvc-14.2'
4141
}
4242
if (-not (Test-Path env:FLEX_BINARY)) {
4343
$env:FLEX_BINARY = 'C:\ProgramData\chocolatey\bin\win_flex.exe'

tools/win32/configure.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ if (-not (Test-Path env:OPENSSL_ROOT_DIR)) {
3636
$env:OPENSSL_ROOT_DIR = "c:\local\OpenSSL_3_0_15-Win${env:BITS}"
3737
}
3838
if (-not (Test-Path env:BOOST_ROOT)) {
39-
$env:BOOST_ROOT = "c:\local\boost_1_86_0-Win${env:BITS}"
39+
$env:BOOST_ROOT = "c:\local\boost_1_87_0-Win${env:BITS}"
4040
}
4141
if (-not (Test-Path env:BOOST_LIBRARYDIR)) {
42-
$env:BOOST_LIBRARYDIR = "c:\local\boost_1_86_0-Win${env:BITS}\lib${env:BITS}-msvc-14.2"
42+
$env:BOOST_LIBRARYDIR = "c:\local\boost_1_87_0-Win${env:BITS}\lib${env:BITS}-msvc-14.2"
4343
}
4444
if (-not (Test-Path env:FLEX_BINARY)) {
4545
$env:FLEX_BINARY = 'C:\ProgramData\chocolatey\bin\win_flex.exe'

0 commit comments

Comments
 (0)