Core/Threading: Fixed possible data races after making auth queries async by moving their processing to boost::asio::io_service::run threads
(cherry picked from commit f6bc87fe5df8b60ca0bf3a35f61305fd780a7e7d)
This commit is contained in:
1 parent
b95648ae27
commit
97fe228334
5 files changed
+13
-9
No files matched your search
@@ -17,7 +17,6 @@
|
||||
|
||||
#include "RBAC.h"
|
||||
#include "AccountMgr.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace rbac
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#ifndef _RBAC_H
|
||||
#define _RBAC_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
@@ -40,8 +40,11 @@ void WorldSocket::Start()
|
||||
stmt->setString(0, ip_address);
|
||||
stmt->setUInt32(1, inet_addr(ip_address.c_str()));
|
||||
|
||||
_queryCallback = std::bind(&WorldSocket::CheckIpCallback, this, std::placeholders::_1);
|
||||
_queryFuture = LoginDatabase.AsyncQuery(stmt);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queryLock);
|
||||
_queryCallback = io_service().wrap(std::bind(&WorldSocket::CheckIpCallback, this, std::placeholders::_1));
|
||||
_queryFuture = LoginDatabase.AsyncQuery(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSocket::CheckIpCallback(PreparedQueryResult result)
|
||||
@@ -79,7 +82,7 @@ bool WorldSocket::Update()
|
||||
return false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_queryLock);
|
||||
std::lock_guard<std::mutex> guard(_queryLock);
|
||||
if (_queryFuture.valid() && _queryFuture.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
|
||||
{
|
||||
auto callback = std::move(_queryCallback);
|
||||
@@ -394,8 +397,8 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
|
||||
stmt->setString(1, authSession->Account);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_queryLock);
|
||||
_queryCallback = std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1);
|
||||
std::lock_guard<std::mutex> guard(_queryLock);
|
||||
_queryCallback = io_service().wrap(std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1));
|
||||
_queryFuture = LoginDatabase.AsyncQuery(stmt);
|
||||
}
|
||||
}
|
||||
@@ -554,7 +557,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
|
||||
if (wardenActive)
|
||||
_worldSession->InitWarden(&account.SessionKey, account.OS);
|
||||
|
||||
_queryCallback = std::bind(&WorldSocket::LoadSessionPermissionsCallback, this, std::placeholders::_1);
|
||||
_queryCallback = io_service().wrap(std::bind(&WorldSocket::LoadSessionPermissionsCallback, this, std::placeholders::_1));
|
||||
_queryFuture = _worldSession->LoadPermissionsAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ private:
|
||||
|
||||
std::mutex _queryLock;
|
||||
PreparedQueryResultFuture _queryFuture;
|
||||
std::function<void(PreparedQueryResult)> _queryCallback;
|
||||
std::function<void(PreparedQueryResult&&)> _queryCallback;
|
||||
std::string _ipCountry;
|
||||
};
|
||||
|
||||
|
||||
@@ -160,6 +160,8 @@ protected:
|
||||
MessageBuffer _writeBuffer;
|
||||
#endif
|
||||
|
||||
boost::asio::io_service& io_service() { return _socket.get_io_service(); }
|
||||
|
||||
private:
|
||||
void ReadHandlerInternal(boost::system::error_code error, size_t transferredBytes)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user