#include <exception>
#include <memory>
#include <thread>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
+#include <boost/asio/post.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/system/error_code.hpp>
return *m_Instance.Get();
}
-boost::asio::io_service& IoEngine::GetIoService()
+boost::asio::io_context& IoEngine::GetIoContext()
{
- return m_IoService;
+ return m_IoContext;
}
-IoEngine::IoEngine() : m_IoService(), m_KeepAlive(m_IoService), m_Threads(decltype(m_Threads)::size_type(std::thread::hardware_concurrency() * 2u)), m_AlreadyExpiredTimer(m_IoService)
+IoEngine::IoEngine() : m_IoContext(), m_KeepAlive(boost::asio::make_work_guard(m_IoContext)), m_Threads(decltype(m_Threads)::size_type(std::thread::hardware_concurrency() * 2u)), m_AlreadyExpiredTimer(m_IoContext)
{
m_AlreadyExpiredTimer.expires_at(boost::posix_time::neg_infin);
m_CpuBoundSemaphore.store(std::thread::hardware_concurrency() * 3u / 2u);
IoEngine::~IoEngine()
{
for (auto& thread : m_Threads) {
- m_IoService.post([]() {
+ boost::asio::post(m_IoContext, []() {
throw TerminateIoThread();
});
}
{
for (;;) {
try {
- m_IoService.run();
+ m_IoContext.run();
break;
} catch (const TerminateIoThread&) {
}
}
-AsioConditionVariable::AsioConditionVariable(boost::asio::io_service& io, bool init)
+AsioConditionVariable::AsioConditionVariable(boost::asio::io_context& io, bool init)
: m_Timer(io)
{
m_Timer.expires_at(init ? boost::posix_time::neg_infin : boost::posix_time::pos_infin);
#include <thread>
#include <vector>
#include <boost/asio/deadline_timer.hpp>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
namespace icinga
static IoEngine& Get();
- boost::asio::io_service& GetIoService();
+ boost::asio::io_context& GetIoContext();
private:
IoEngine();
static LazyInit<std::unique_ptr<IoEngine>> m_Instance;
- boost::asio::io_service m_IoService;
- boost::asio::io_service::work m_KeepAlive;
+ boost::asio::io_context m_IoContext;
+ boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_KeepAlive;
std::vector<std::thread> m_Threads;
boost::asio::deadline_timer m_AlreadyExpiredTimer;
std::atomic_int_fast32_t m_CpuBoundSemaphore;
class AsioConditionVariable
{
public:
- AsioConditionVariable(boost::asio::io_service& io, bool init = false);
+ AsioConditionVariable(boost::asio::io_context& io, bool init = false);
void Set();
void Clear();
{
using boost::asio::ip::tcp;
- tcp::resolver resolver (IoEngine::Get().GetIoService());
+ tcp::resolver resolver (IoEngine::Get().GetIoContext());
tcp::resolver::query query (node, service);
auto result (resolver.resolve(query));
auto current (result.begin());
{
using boost::asio::ip::tcp;
- tcp::resolver resolver (IoEngine::Get().GetIoService());
+ tcp::resolver resolver (IoEngine::Get().GetIoContext());
tcp::resolver::query query (node, service);
auto result (resolver.async_resolve(query, yc));
auto current (result.begin());
#include <memory>
#include <utility>
#include <boost/asio/buffered_stream.hpp>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/stream.hpp>
struct UnbufferedAsioTlsStreamParams
{
- boost::asio::io_service& IoService;
+ boost::asio::io_context& IoContext;
boost::asio::ssl::context& SslContext;
const String& Hostname;
};
public:
inline
UnbufferedAsioTlsStream(UnbufferedAsioTlsStreamParams& init)
- : stream(init.IoService, init.SslContext), m_VerifyOK(true), m_Hostname(init.Hostname)
+ : stream(init.IoContext, init.SslContext), m_VerifyOK(true), m_Hostname(init.Hostname)
{
}
{
public:
inline
- AsioTlsStream(boost::asio::io_service& ioService, boost::asio::ssl::context& sslContext, const String& hostname = String())
- : AsioTlsStream(UnbufferedAsioTlsStreamParams{ioService, sslContext, hostname})
+ AsioTlsStream(boost::asio::io_context& ioContext, boost::asio::ssl::context& sslContext, const String& hostname = String())
+ : AsioTlsStream(UnbufferedAsioTlsStreamParams{ioContext, sslContext, hostname})
{
}
String host = l_Url->GetHost();
String port = l_Url->GetPort();
- std::shared_ptr<AsioTlsStream> stream = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, host);
+ std::shared_ptr<AsioTlsStream> stream = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, host);
try {
icinga::Connect(stream->lowest_layer(), host, port);
throw;
}
- stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, GetHost());
+ stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, GetHost());
} else {
- stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoService());
+ stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoContext());
}
try {
throw;
}
- m_Stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, GetHost());
+ m_Stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, GetHost());
} else {
- m_Stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoService());
+ m_Stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoContext());
}
try {
Log(LogNotice, "GraphiteWriter")
<< "Reconnecting to Graphite on host '" << GetHost() << "' port '" << GetPort() << "'.";
- m_Stream = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoService());
+ m_Stream = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoContext());
try {
icinga::Connect(m_Stream->lowest_layer(), GetHost(), GetPort());
throw;
}
- stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, GetHost());
+ stream.first = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, GetHost());
} else {
- stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoService());
+ stream.second = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoContext());
}
try {
* http://opentsdb.net/docs/build/html/user_guide/writing/index.html#telnet
*/
- m_Stream = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoService());
+ m_Stream = std::make_shared<AsioTcpStream>(IoEngine::Get().GetIoContext());
try {
icinga::Connect(m_Stream->lowest_layer(), GetHost(), GetPort());
boost::replace_all(result, ":", "_");
return result;
-}
\ No newline at end of file
+}
return false;
}
- auto& io (IoEngine::Get().GetIoService());
+ auto& io (IoEngine::Get().GetIoContext());
auto acceptor (std::make_shared<tcp::acceptor>(io));
try {
{
namespace asio = boost::asio;
- auto& io (IoEngine::Get().GetIoService());
+ auto& io (IoEngine::Get().GetIoContext());
for (;;) {
try {
return;
}
- auto& io (IoEngine::Get().GetIoService());
+ auto& io (IoEngine::Get().GetIoContext());
asio::spawn(io, [this, endpoint, &io, sslContext](asio::yield_context yc) {
String host = endpoint->GetHost();
endpoint->AddClient(aclient);
- asio::spawn(IoEngine::Get().GetIoService(), [this, aclient, endpoint, needSync](asio::yield_context yc) {
+ asio::spawn(IoEngine::Get().GetIoContext(), [this, aclient, endpoint, needSync](asio::yield_context yc) {
CpuBoundWork syncClient (yc);
SyncClient(aclient, endpoint, needSync);
EventsRouter EventsRouter::m_Instance;
EventsInbox::EventsInbox(String filter, const String& filterSource)
- : m_Timer(IoEngine::Get().GetIoService())
+ : m_Timer(IoEngine::Get().GetIoContext())
{
std::unique_lock<std::mutex> lock (m_FiltersMutex);
m_Filter = m_Filters.find(filter);
#include <memory>
#include <stdexcept>
#include <boost/asio/error.hpp>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
auto const l_ServerHeader ("Icinga/" + Application::GetAppVersion());
HttpServerConnection::HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream)
- : HttpServerConnection(identity, authenticated, stream, IoEngine::Get().GetIoService())
+ : HttpServerConnection(identity, authenticated, stream, IoEngine::Get().GetIoContext())
{
}
-HttpServerConnection::HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, boost::asio::io_service& io)
+HttpServerConnection::HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, boost::asio::io_context& io)
: m_Stream(stream), m_Seen(Utility::GetTime()), m_IoStrand(io), m_ShuttingDown(false), m_HasStartedStreaming(false),
m_CheckLivenessTimer(io)
{
#include "base/tlsstream.hpp"
#include <memory>
#include <boost/asio/deadline_timer.hpp>
-#include <boost/asio/io_service.hpp>
-#include <boost/asio/io_service_strand.hpp>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/spawn.hpp>
namespace icinga
std::shared_ptr<AsioTlsStream> m_Stream;
double m_Seen;
String m_PeerAddress;
- boost::asio::io_service::strand m_IoStrand;
+ boost::asio::io_context::strand m_IoStrand;
bool m_ShuttingDown;
bool m_HasStartedStreaming;
boost::asio::deadline_timer m_CheckLivenessTimer;
- HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, boost::asio::io_service& io);
+ HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, boost::asio::io_context& io);
void ProcessMessages(boost::asio::yield_context yc);
void CheckLiveness(boost::asio::yield_context yc);
#include "base/tlsstream.hpp"
#include <memory>
#include <utility>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/system/system_error.hpp>
JsonRpcConnection::JsonRpcConnection(const String& identity, bool authenticated,
const std::shared_ptr<AsioTlsStream>& stream, ConnectionRole role)
- : JsonRpcConnection(identity, authenticated, stream, role, IoEngine::Get().GetIoService())
+ : JsonRpcConnection(identity, authenticated, stream, role, IoEngine::Get().GetIoContext())
{
}
JsonRpcConnection::JsonRpcConnection(const String& identity, bool authenticated,
- const std::shared_ptr<AsioTlsStream>& stream, ConnectionRole role, boost::asio::io_service& io)
+ const std::shared_ptr<AsioTlsStream>& stream, ConnectionRole role, boost::asio::io_context& io)
: m_Identity(identity), m_Authenticated(authenticated), m_Stream(stream), m_Role(role),
m_Timestamp(Utility::GetTime()), m_Seen(Utility::GetTime()), m_NextHeartbeat(0), m_IoStrand(io),
m_OutgoingMessagesQueued(io), m_WriterDone(io), m_ShuttingDown(false),
#include "base/workqueue.hpp"
#include <memory>
#include <vector>
-#include <boost/asio/io_service.hpp>
-#include <boost/asio/io_service_strand.hpp>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/spawn.hpp>
namespace icinga
double m_Timestamp;
double m_Seen;
double m_NextHeartbeat;
- boost::asio::io_service::strand m_IoStrand;
+ boost::asio::io_context::strand m_IoStrand;
std::vector<String> m_OutgoingMessagesQueue;
AsioConditionVariable m_OutgoingMessagesQueued;
AsioConditionVariable m_WriterDone;
bool m_ShuttingDown;
boost::asio::deadline_timer m_CheckLivenessTimer, m_HeartbeatTimer;
- JsonRpcConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, ConnectionRole role, boost::asio::io_service& io);
+ JsonRpcConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, ConnectionRole role, boost::asio::io_context& io);
void HandleIncomingMessages(boost::asio::yield_context yc);
void WriteOutgoingMessages(boost::asio::yield_context yc);
return std::shared_ptr<X509>();
}
- auto stream (std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, host));
+ auto stream (std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, host));
try {
Connect(stream->lowest_layer(), host, port);
return 1;
}
- auto stream (std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, host));
+ auto stream (std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, host));
try {
Connect(stream->lowest_layer(), host, port);
throw;
}
- std::shared_ptr<AsioTlsStream> stream = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoService(), *sslContext, host);
+ std::shared_ptr<AsioTlsStream> stream = std::make_shared<AsioTlsStream>(IoEngine::Get().GetIoContext(), *sslContext, host);
try {
icinga::Connect(stream->lowest_layer(), host, port);