mirror of https://github.com/Icinga/icinga2.git
RedisConnection: replace std::shared_ptr<T> with Shared<T>::Ptr
This commit is contained in:
parent
cd44c5371a
commit
de5b3eb2c7
|
@ -15,6 +15,7 @@
|
|||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/variant/get.hpp>
|
||||
#include <exception>
|
||||
#include <future>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
@ -75,7 +76,7 @@ void RedisConnection::FireAndForgetQuery(RedisConnection::Query query, RedisConn
|
|||
LogQuery(query, msg);
|
||||
}
|
||||
|
||||
auto item (std::make_shared<decltype(WriteQueueItem().FireAndForgetQuery)::element_type>(std::move(query)));
|
||||
auto item (Shared<Query>::Make(std::move(query)));
|
||||
|
||||
asio::post(m_Strand, [this, item, priority]() {
|
||||
m_Queues.Writes[priority].emplace(WriteQueueItem{item, nullptr, nullptr, nullptr});
|
||||
|
@ -90,7 +91,7 @@ void RedisConnection::FireAndForgetQueries(RedisConnection::Queries queries, Red
|
|||
LogQuery(query, msg);
|
||||
}
|
||||
|
||||
auto item (std::make_shared<decltype(WriteQueueItem().FireAndForgetQueries)::element_type>(std::move(queries)));
|
||||
auto item (Shared<Queries>::Make(std::move(queries)));
|
||||
|
||||
asio::post(m_Strand, [this, item, priority]() {
|
||||
m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, item, nullptr, nullptr});
|
||||
|
@ -107,7 +108,7 @@ RedisConnection::Reply RedisConnection::GetResultOfQuery(RedisConnection::Query
|
|||
|
||||
std::promise<Reply> promise;
|
||||
auto future (promise.get_future());
|
||||
auto item (std::make_shared<decltype(WriteQueueItem().GetResultOfQuery)::element_type>(std::move(query), std::move(promise)));
|
||||
auto item (Shared<std::pair<Query, std::promise<Reply>>>::Make(std::move(query), std::move(promise)));
|
||||
|
||||
asio::post(m_Strand, [this, item, priority]() {
|
||||
m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, nullptr, item, nullptr});
|
||||
|
@ -128,7 +129,7 @@ RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Q
|
|||
|
||||
std::promise<Replies> promise;
|
||||
auto future (promise.get_future());
|
||||
auto item (std::make_shared<decltype(WriteQueueItem().GetResultsOfQueries)::element_type>(std::move(queries), std::move(promise)));
|
||||
auto item (Shared<std::pair<Queries, std::promise<Replies>>>::Make(std::move(queries), std::move(promise)));
|
||||
|
||||
asio::post(m_Strand, [this, item, priority]() {
|
||||
m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, nullptr, nullptr, item});
|
||||
|
@ -152,14 +153,14 @@ void RedisConnection::Connect(asio::yield_context& yc)
|
|||
Log(LogInformation, "IcingaDB")
|
||||
<< "Trying to connect to Redis server (async) on host '" << m_Host << ":" << m_Port << "'";
|
||||
|
||||
decltype(m_TcpConn) conn (new TcpConn(m_Strand.context()));
|
||||
auto conn (Shared<TcpConn>::Make(m_Strand.context()));
|
||||
icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc);
|
||||
m_TcpConn = std::move(conn);
|
||||
} else {
|
||||
Log(LogInformation, "IcingaDB")
|
||||
<< "Trying to connect to Redis server (async) on unix socket path '" << m_Path << "'";
|
||||
|
||||
decltype(m_UnixConn) conn (new UnixConn(m_Strand.context()));
|
||||
auto conn (Shared<UnixConn>::Make(m_Strand.context()));
|
||||
conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc);
|
||||
m_UnixConn = std::move(conn);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "base/atomic.hpp"
|
||||
#include "base/io-engine.hpp"
|
||||
#include "base/object.hpp"
|
||||
#include "base/shared.hpp"
|
||||
#include "base/string.hpp"
|
||||
#include "base/value.hpp"
|
||||
#include <boost/asio/spawn.hpp>
|
||||
|
@ -87,10 +88,10 @@ namespace icinga
|
|||
|
||||
struct WriteQueueItem
|
||||
{
|
||||
std::shared_ptr<Query> FireAndForgetQuery;
|
||||
std::shared_ptr<Queries> FireAndForgetQueries;
|
||||
std::shared_ptr<std::pair<Query, std::promise<Reply>>> GetResultOfQuery;
|
||||
std::shared_ptr<std::pair<Queries, std::promise<Replies>>> GetResultsOfQueries;
|
||||
Shared<Query>::Ptr FireAndForgetQuery;
|
||||
Shared<Queries>::Ptr FireAndForgetQueries;
|
||||
Shared<std::pair<Query, std::promise<Reply>>>::Ptr GetResultOfQuery;
|
||||
Shared<std::pair<Queries, std::promise<Replies>>>::Ptr GetResultsOfQueries;
|
||||
};
|
||||
|
||||
typedef boost::asio::ip::tcp Tcp;
|
||||
|
@ -133,8 +134,8 @@ namespace icinga
|
|||
int m_DbIndex;
|
||||
|
||||
boost::asio::io_context::strand m_Strand;
|
||||
std::shared_ptr<TcpConn> m_TcpConn;
|
||||
std::shared_ptr<UnixConn> m_UnixConn;
|
||||
Shared<TcpConn>::Ptr m_TcpConn;
|
||||
Shared<UnixConn>::Ptr m_UnixConn;
|
||||
Atomic<bool> m_Connecting, m_Connected, m_Started;
|
||||
|
||||
struct {
|
||||
|
|
Loading…
Reference in New Issue