]> granicus.if.org Git - icinga2/commitdiff
Quality: Replace deprecated Boost IO service code 7490/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Mon, 9 Sep 2019 13:11:38 +0000 (15:11 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 9 Sep 2019 13:27:57 +0000 (15:27 +0200)
https://github.com/boostorg/asio/issues/110
https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/example/cpp03/services/logger_service.hpp

18 files changed:
lib/base/io-engine.cpp
lib/base/io-engine.hpp
lib/base/tcpsocket.hpp
lib/base/tlsstream.hpp
lib/cli/consolecommand.cpp
lib/perfdata/elasticsearchwriter.cpp
lib/perfdata/gelfwriter.cpp
lib/perfdata/graphitewriter.cpp
lib/perfdata/influxdbwriter.cpp
lib/perfdata/opentsdbwriter.cpp
lib/remote/apilistener.cpp
lib/remote/eventqueue.cpp
lib/remote/httpserverconnection.cpp
lib/remote/httpserverconnection.hpp
lib/remote/jsonrpcconnection.cpp
lib/remote/jsonrpcconnection.hpp
lib/remote/pkiutility.cpp
plugins/check_nscp_api.cpp

index e3c36b54be8255af2da6b1475ad23d0560515946..5dd3ee59cf6237d58e3b8d00bf4dfbdae0297fd8 100644 (file)
@@ -7,8 +7,9 @@
 #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>
 
@@ -78,12 +79,12 @@ IoEngine& IoEngine::Get()
        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);
@@ -96,7 +97,7 @@ IoEngine::IoEngine() : m_IoService(), m_KeepAlive(m_IoService), m_Threads(declty
 IoEngine::~IoEngine()
 {
        for (auto& thread : m_Threads) {
-               m_IoService.post([]() {
+               boost::asio::post(m_IoContext, []() {
                        throw TerminateIoThread();
                });
        }
@@ -110,7 +111,7 @@ void IoEngine::RunEventLoop()
 {
        for (;;) {
                try {
-                       m_IoService.run();
+                       m_IoContext.run();
 
                        break;
                } catch (const TerminateIoThread&) {
@@ -122,7 +123,7 @@ void IoEngine::RunEventLoop()
        }
 }
 
-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);
index e54f414bceb59f2927f6e3617b2d7a85b0b2128f..1c6d460454242ad658da9bf5b49923e6a43f1da3 100644 (file)
@@ -10,7 +10,7 @@
 #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
@@ -75,7 +75,7 @@ public:
 
        static IoEngine& Get();
 
-       boost::asio::io_service& GetIoService();
+       boost::asio::io_context& GetIoContext();
 
 private:
        IoEngine();
@@ -84,8 +84,8 @@ private:
 
        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;
@@ -103,7 +103,7 @@ class TerminateIoThread : public std::exception
 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();
index 5c6a9fcb91fb69d355f1be3c3d7d72432c8ca4b7..e0f502256460aa0fb9168538a3041920dfbf526d 100644 (file)
@@ -38,7 +38,7 @@ void Connect(Socket& socket, const String& node, const String& service)
 {
        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());
@@ -67,7 +67,7 @@ void Connect(Socket& socket, const String& node, const String& service, boost::a
 {
        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());
index 44fe0b9c542b0f824a2979f15f7005a1b3ebe9bc..70a4591147334cc684b4fb8df2a2d57f6d4057ac 100644 (file)
@@ -11,7 +11,7 @@
 #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>
@@ -21,7 +21,7 @@ namespace icinga
 
 struct UnbufferedAsioTlsStreamParams
 {
-       boost::asio::io_service& IoService;
+       boost::asio::io_context& IoContext;
        boost::asio::ssl::context& SslContext;
        const String& Hostname;
 };
@@ -33,7 +33,7 @@ class UnbufferedAsioTlsStream : public AsioTcpTlsStream
 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)
        {
        }
 
@@ -71,8 +71,8 @@ class AsioTlsStream : public boost::asio::buffered_stream<UnbufferedAsioTlsStrea
 {
 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})
        {
        }
 
index 848b8b07cc8326c41d6510e90e6ec2e51a1b6c71..9f8a2cf8a6298da94b11e7fa74606e5e487ed94b 100644 (file)
@@ -537,7 +537,7 @@ std::shared_ptr<AsioTlsStream> ConsoleCommand::Connect()
        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);
index 962148f946b46756a4efa38718451cb0cbc374c7..7798ad8dc91e178b093a3becc1ece85127135310 100644 (file)
@@ -598,9 +598,9 @@ OptionalTlsStream ElasticsearchWriter::Connect()
                        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 {
index 9846aedc8f7f5928100fa1f440cf720796b667f1..c778a381335c8d2ff118b39e900f690c616c2897 100644 (file)
@@ -173,9 +173,9 @@ void GelfWriter::ReconnectInternal()
                        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 {
index 9eb2e84a6ee2b93b53405a2e8fc251d6141ab6c6..642926f661a79d9759f04a302a86e371c3a61899 100644 (file)
@@ -187,7 +187,7 @@ void GraphiteWriter::ReconnectInternal()
        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());
index 86d8128de65b103da21cfa1283658ac4fac34dcd..1e02e52134fa05c39d7d02223783f3a72e62c594 100644 (file)
@@ -187,9 +187,9 @@ OptionalTlsStream InfluxdbWriter::Connect()
                        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 {
index 0e54b28467c2653e2d0e9c4067c7edf26283e8f5..b936b3083e3aebb7ea84d53679f6c30a478ed819 100644 (file)
@@ -121,7 +121,7 @@ void OpenTsdbWriter::ReconnectTimerHandler()
         * 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());
@@ -338,4 +338,4 @@ String OpenTsdbWriter::EscapeMetric(const String& str)
        boost::replace_all(result, ":", "_");
 
        return result;
-}
\ No newline at end of file
+}
index 5a2ca048cb5f8176a91f5ad0e5e0d369ec138e19..5d82b6dc8218adf6d627d8d68712eefd3164c48b 100644 (file)
@@ -363,7 +363,7 @@ bool ApiListener::AddListener(const String& node, const String& service)
                return false;
        }
 
-       auto& io (IoEngine::Get().GetIoService());
+       auto& io (IoEngine::Get().GetIoContext());
        auto acceptor (std::make_shared<tcp::acceptor>(io));
 
        try {
@@ -427,7 +427,7 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const std
 {
        namespace asio = boost::asio;
 
-       auto& io (IoEngine::Get().GetIoService());
+       auto& io (IoEngine::Get().GetIoContext());
 
        for (;;) {
                try {
@@ -460,7 +460,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
                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();
@@ -664,7 +664,7 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
 
                        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);
index 2a7869d459d30176df8c38d09feec1df8d75d3bc..5b6219c1062354a46305decb5abe6063e8ea1087 100644 (file)
@@ -131,7 +131,7 @@ std::map<String, EventsInbox::Filter> EventsInbox::m_Filters ({{"", EventsInbox:
 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);
index 524916b4e735bddb6229054f9c4ae7135cb2b7cd..556f6085726e8eb46d7bf97d3df2a8bdcd5bd1a2 100644 (file)
@@ -22,7 +22,7 @@
 #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>
@@ -35,11 +35,11 @@ using namespace icinga;
 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)
 {
index b697d5381790f5355a6f98727320b5c610ad6c60..43851e76e3499b2bfa27d4678f6833c6a78f3ce1 100644 (file)
@@ -8,8 +8,8 @@
 #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
@@ -38,12 +38,12 @@ private:
        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);
index 5a26812a22ad19be31e1a86d6fa4bef86b297fce..eb9a946a4fc61b7f41ae677a7f28e89be4fd32c6 100644 (file)
@@ -16,7 +16,7 @@
 #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>
@@ -31,12 +31,12 @@ static RingBuffer l_TaskStats (15 * 60);
 
 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),
index 2b18353082bdd9e347c619550978f760a37c4405..0fbf6c605af6d65d4083d6e196d1fba860a84f16 100644 (file)
@@ -11,8 +11,8 @@
 #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
@@ -73,14 +73,14 @@ private:
        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);
index 3fddd1a67a2cbee1ee8213af0df9389e223c66ac..a95e3554cbde6a6c04908318c9eb162a7d62f351 100644 (file)
@@ -93,7 +93,7 @@ std::shared_ptr<X509> PkiUtility::FetchCert(const String& host, const String& po
                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);
@@ -161,7 +161,7 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const
                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);
index a9009c47e0cc3ec08042e7646a2510047abbbcae..1339ccbacea40fbc0e897c510dcca565a12a2e11 100644 (file)
@@ -186,7 +186,7 @@ static std::shared_ptr<AsioTlsStream> Connect(const String& host, const String&
                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);