mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Added compatibility layer for boost 1.66 and future std:: networking stuff
* Based on work done by @dimiandre in PR #21173 Closes #21171 Closes #21173
This commit is contained in:
@@ -19,18 +19,18 @@
|
||||
#include "Log.h"
|
||||
#include "AppenderConsole.h"
|
||||
#include "AppenderFile.h"
|
||||
#include "AsioHacksImpl.h"
|
||||
#include "Common.h"
|
||||
#include "Config.h"
|
||||
#include "Errors.h"
|
||||
#include "Logger.h"
|
||||
#include "LogMessage.h"
|
||||
#include "LogOperation.h"
|
||||
#include "Strand.h"
|
||||
#include "Util.h"
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
Log::Log() : AppenderId(0), lowestLogLevel(LOG_LEVEL_FATAL), _ioService(nullptr), _strand(nullptr)
|
||||
Log::Log() : AppenderId(0), lowestLogLevel(LOG_LEVEL_FATAL), _ioContext(nullptr), _strand(nullptr)
|
||||
{
|
||||
m_logsTimestamp = "_" + GetTimestampStr();
|
||||
RegisterAppender<AppenderConsole>();
|
||||
@@ -228,11 +228,10 @@ void Log::write(std::unique_ptr<LogMessage>&& msg) const
|
||||
{
|
||||
Logger const* logger = GetLoggerByType(msg->type);
|
||||
|
||||
if (_ioService)
|
||||
if (_ioContext)
|
||||
{
|
||||
auto logOperation = std::make_shared<LogOperation>(logger, std::move(msg));
|
||||
|
||||
_ioService->post(_strand->wrap([logOperation](){ logOperation->call(); }));
|
||||
std::shared_ptr<LogOperation> logOperation = std::make_shared<LogOperation>(logger, std::move(msg));
|
||||
Trinity::Asio::post(*_ioContext, Trinity::Asio::bind_executor(*_strand, [logOperation]() { logOperation->call(); }));
|
||||
}
|
||||
else
|
||||
logger->write(msg.get());
|
||||
@@ -367,12 +366,12 @@ Log* Log::instance()
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void Log::Initialize(boost::asio::io_service* ioService)
|
||||
void Log::Initialize(Trinity::Asio::IoContext* ioContext)
|
||||
{
|
||||
if (ioService)
|
||||
if (ioContext)
|
||||
{
|
||||
_ioService = ioService;
|
||||
_strand = new Trinity::AsioStrand(*ioService);
|
||||
_ioContext = ioContext;
|
||||
_strand = new Trinity::Asio::Strand(*ioContext);
|
||||
}
|
||||
|
||||
LoadFromConfig();
|
||||
@@ -382,7 +381,7 @@ void Log::SetSynchronous()
|
||||
{
|
||||
delete _strand;
|
||||
_strand = nullptr;
|
||||
_ioService = nullptr;
|
||||
_ioContext = nullptr;
|
||||
}
|
||||
|
||||
void Log::LoadFromConfig()
|
||||
|
||||
@@ -31,11 +31,11 @@ class Appender;
|
||||
class Logger;
|
||||
struct LogMessage;
|
||||
|
||||
namespace boost
|
||||
namespace Trinity
|
||||
{
|
||||
namespace asio
|
||||
namespace Asio
|
||||
{
|
||||
class io_service;
|
||||
class IoContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class TC_COMMON_API Log
|
||||
public:
|
||||
static Log* instance();
|
||||
|
||||
void Initialize(boost::asio::io_service* ioService);
|
||||
void Initialize(Trinity::Asio::IoContext* ioContext);
|
||||
void SetSynchronous(); // Not threadsafe - should only be called from main() after all threads are joined
|
||||
void LoadFromConfig();
|
||||
void Close();
|
||||
@@ -122,8 +122,8 @@ class TC_COMMON_API Log
|
||||
std::string m_logsDir;
|
||||
std::string m_logsTimestamp;
|
||||
|
||||
boost::asio::io_service* _ioService;
|
||||
Trinity::AsioStrand* _strand;
|
||||
Trinity::Asio::IoContext* _ioContext;
|
||||
Trinity::Asio::Strand* _strand;
|
||||
};
|
||||
|
||||
#define sLog Log::instance()
|
||||
|
||||
Reference in New Issue
Block a user