mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Network: Cleanup asio using directives
This commit is contained in:
@@ -51,7 +51,6 @@
|
||||
|
||||
#include "Hacks/boost_program_options_with_filesystem_path.h"
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
using namespace boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ void Battlenet::Session::GameAccountInfo::LoadResult(Field* fields)
|
||||
DisplayName = Name;
|
||||
}
|
||||
|
||||
Battlenet::Session::Session(tcp::socket&& socket) : BattlenetSocket(std::move(socket)), _accountInfo(new AccountInfo()), _gameAccountInfo(nullptr), _locale(),
|
||||
Battlenet::Session::Session(boost::asio::ip::tcp::socket&& socket) : BattlenetSocket(std::move(socket)), _accountInfo(new AccountInfo()), _gameAccountInfo(nullptr), _locale(),
|
||||
_os(), _build(0), _ipCountry(), _authed(false), _requestToken(0)
|
||||
{
|
||||
_headerLengthBuffer.Resize(2);
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <google/protobuf/message.h>
|
||||
#include <memory>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
namespace pb = google::protobuf;
|
||||
|
||||
class ServiceBase;
|
||||
@@ -111,7 +109,7 @@ namespace Battlenet
|
||||
std::unordered_map<uint32, GameAccountInfo> GameAccounts;
|
||||
};
|
||||
|
||||
explicit Session(tcp::socket&& socket);
|
||||
explicit Session(boost::asio::ip::tcp::socket&& socket);
|
||||
~Session();
|
||||
|
||||
void Start() override;
|
||||
|
||||
@@ -35,9 +35,9 @@ NetworkThread<Battlenet::Session>* Battlenet::SessionManager::CreateThreads() co
|
||||
return new NetworkThread<Session>[GetNetworkThreadCount()];
|
||||
}
|
||||
|
||||
void Battlenet::SessionManager::OnSocketAccept(tcp::socket&& sock, uint32 threadIndex)
|
||||
void Battlenet::SessionManager::OnSocketAccept(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex)
|
||||
{
|
||||
sSessionMgr.OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
|
||||
sSessionMgr.OnSocketOpen(std::forward<boost::asio::ip::tcp::socket>(sock), threadIndex);
|
||||
}
|
||||
|
||||
Battlenet::SessionManager& Battlenet::SessionManager::Instance()
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Battlenet
|
||||
NetworkThread<Session>* CreateThreads() const override;
|
||||
|
||||
private:
|
||||
static void OnSocketAccept(tcp::socket&& sock, uint32 threadIndex);
|
||||
static void OnSocketAccept(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ struct CompressedWorldPacket
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
std::string const WorldSocket::ServerConnectionInitialize("WORLD OF WARCRAFT CONNECTION - SERVER TO CLIENT - V2");
|
||||
std::string const WorldSocket::ClientConnectionInitialize("WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER - V2");
|
||||
uint32 const WorldSocket::MinSizeForCompression = 0x400;
|
||||
@@ -58,7 +56,7 @@ uint8 const WorldSocket::SessionKeySeed[16] = { 0x58, 0xCB, 0xCF, 0x40, 0xFE, 0x
|
||||
uint8 const WorldSocket::ContinuedSessionSeed[16] = { 0x16, 0xAD, 0x0C, 0xD4, 0x46, 0xF9, 0x4F, 0xB2, 0xEF, 0x7D, 0xEA, 0x2A, 0x17, 0x66, 0x4D, 0x2F };
|
||||
uint8 const WorldSocket::EncryptionKeySeed[16] = { 0xE9, 0x75, 0x3C, 0x50, 0x90, 0x93, 0x61, 0xDA, 0x3B, 0x07, 0xEE, 0xFA, 0xFF, 0x9D, 0x41, 0xB8 };
|
||||
|
||||
WorldSocket::WorldSocket(tcp::socket&& socket) : Socket(std::move(socket)),
|
||||
WorldSocket::WorldSocket(boost::asio::ip::tcp::socket&& socket) : Socket(std::move(socket)),
|
||||
_type(CONNECTION_TYPE_REALM), _key(0), _OverSpeedPings(0),
|
||||
_worldSession(nullptr), _authed(false), _canRequestHotfixes(true), _sendBufferSize(4096), _compressionStream(nullptr)
|
||||
{
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#include "WorldSocket.h"
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
static void OnSocketAccept(tcp::socket&& sock, uint32 threadIndex)
|
||||
static void OnSocketAccept(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex)
|
||||
{
|
||||
sWorldSocketMgr.OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
|
||||
sWorldSocketMgr.OnSocketOpen(std::forward<boost::asio::ip::tcp::socket>(sock), threadIndex);
|
||||
}
|
||||
|
||||
class WorldSocketThread : public NetworkThread<WorldSocket>
|
||||
@@ -120,7 +120,7 @@ void WorldSocketMgr::StopNetwork()
|
||||
sScriptMgr->OnNetworkStop();
|
||||
}
|
||||
|
||||
void WorldSocketMgr::OnSocketOpen(tcp::socket&& sock, uint32 threadIndex)
|
||||
void WorldSocketMgr::OnSocketOpen(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex)
|
||||
{
|
||||
// set some options here
|
||||
if (_socketSystemSendBufferSize >= 0)
|
||||
@@ -148,7 +148,7 @@ void WorldSocketMgr::OnSocketOpen(tcp::socket&& sock, uint32 threadIndex)
|
||||
|
||||
//sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
|
||||
|
||||
BaseSocketMgr::OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
|
||||
BaseSocketMgr::OnSocketOpen(std::forward<boost::asio::ip::tcp::socket>(sock), threadIndex);
|
||||
}
|
||||
|
||||
NetworkThread<WorldSocket>* WorldSocketMgr::CreateThreads() const
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
/// Stops all network threads, It will wait for all running threads .
|
||||
void StopNetwork() override;
|
||||
|
||||
void OnSocketOpen(tcp::socket&& sock, uint32 threadIndex) override;
|
||||
void OnSocketOpen(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex) override;
|
||||
|
||||
std::size_t GetApplicationSendBufferSize() const { return _socketApplicationSendBufferSize; }
|
||||
|
||||
|
||||
@@ -25,14 +25,12 @@
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
#define TRINITY_MAX_LISTEN_CONNECTIONS boost::asio::socket_base::max_listen_connections
|
||||
|
||||
class AsyncAcceptor
|
||||
{
|
||||
public:
|
||||
typedef void(*AcceptCallback)(tcp::socket&& newSocket, uint32 threadIndex);
|
||||
typedef void(*AcceptCallback)(boost::asio::ip::tcp::socket&& newSocket, uint32 threadIndex);
|
||||
|
||||
AsyncAcceptor(Trinity::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port) :
|
||||
_acceptor(ioContext), _endpoint(Trinity::Net::make_address(bindIp), port),
|
||||
@@ -48,7 +46,7 @@ public:
|
||||
{
|
||||
auto [tmpSocket, tmpThreadIndex] = _socketFactory();
|
||||
// TODO: get rid of temporary variables (clang 15 cannot handle variables from structured bindings as lambda captures)
|
||||
tcp::socket* socket = tmpSocket;
|
||||
boost::asio::ip::tcp::socket* socket = tmpSocket;
|
||||
uint32 threadIndex = tmpThreadIndex;
|
||||
_acceptor.async_accept(*socket, [this, socket, threadIndex](boost::system::error_code error)
|
||||
{
|
||||
@@ -116,16 +114,16 @@ public:
|
||||
_acceptor.close(err);
|
||||
}
|
||||
|
||||
void SetSocketFactory(std::function<std::pair<tcp::socket*, uint32>()> func) { _socketFactory = func; }
|
||||
void SetSocketFactory(std::function<std::pair<boost::asio::ip::tcp::socket*, uint32>()> func) { _socketFactory = func; }
|
||||
|
||||
private:
|
||||
std::pair<tcp::socket*, uint32> DefeaultSocketFactory() { return std::make_pair(&_socket, 0); }
|
||||
std::pair<boost::asio::ip::tcp::socket*, uint32> DefeaultSocketFactory() { return std::make_pair(&_socket, 0); }
|
||||
|
||||
tcp::acceptor _acceptor;
|
||||
tcp::endpoint _endpoint;
|
||||
tcp::socket _socket;
|
||||
boost::asio::ip::tcp::acceptor _acceptor;
|
||||
boost::asio::ip::tcp::endpoint _endpoint;
|
||||
boost::asio::ip::tcp::socket _socket;
|
||||
std::atomic<bool> _closed;
|
||||
std::function<std::pair<tcp::socket*, uint32>()> _socketFactory;
|
||||
std::function<std::pair<boost::asio::ip::tcp::socket*, uint32>()> _socketFactory;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
template<class SocketType>
|
||||
class NetworkThread
|
||||
{
|
||||
@@ -88,7 +86,7 @@ public:
|
||||
SocketAdded(sock);
|
||||
}
|
||||
|
||||
tcp::socket* GetSocketForAccept() { return &_acceptSocket; }
|
||||
boost::asio::ip::tcp::socket* GetSocketForAccept() { return &_acceptSocket; }
|
||||
|
||||
protected:
|
||||
virtual void SocketAdded(std::shared_ptr<SocketType> /*sock*/) { }
|
||||
@@ -169,7 +167,7 @@ private:
|
||||
SocketContainer _newSockets;
|
||||
|
||||
Trinity::Asio::IoContext _ioContext;
|
||||
tcp::socket _acceptSocket;
|
||||
boost::asio::ip::tcp::socket _acceptSocket;
|
||||
Trinity::Asio::DeadlineTimer _updateTimer;
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <type_traits>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
#define READ_BLOCK_SIZE 4096
|
||||
#ifdef BOOST_ASIO_HAS_IOCP
|
||||
#define TC_SOCKET_USE_IOCP
|
||||
@@ -61,11 +59,11 @@ using boost::asio::ip::tcp;
|
||||
|
||||
tcp::socket::endpoint_type remote_endpoint() const;
|
||||
*/
|
||||
template<class T, class Stream = tcp::socket>
|
||||
template<class T, class Stream = boost::asio::ip::tcp::socket>
|
||||
class Socket : public std::enable_shared_from_this<T>
|
||||
{
|
||||
public:
|
||||
explicit Socket(tcp::socket&& socket) : _socket(std::move(socket)), _remoteAddress(_socket.remote_endpoint().address()),
|
||||
explicit Socket(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _remoteAddress(_socket.remote_endpoint().address()),
|
||||
_remotePort(_socket.remote_endpoint().port()), _readBuffer(), _closed(false), _closing(false), _isWritingAsync(false)
|
||||
{
|
||||
_readBuffer.Resize(READ_BLOCK_SIZE);
|
||||
@@ -185,7 +183,7 @@ protected:
|
||||
void SetNoDelay(bool enable)
|
||||
{
|
||||
boost::system::error_code err;
|
||||
_socket.set_option(tcp::no_delay(enable), err);
|
||||
_socket.set_option(boost::asio::ip::tcp::no_delay(enable), err);
|
||||
if (err)
|
||||
TC_LOG_DEBUG("network", "Socket::SetNoDelay: failed to set_option(boost::asio::ip::tcp::no_delay) for {} - {} ({})",
|
||||
GetRemoteIpAddress().to_string(), err.value(), err.message());
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <memory>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
template<class SocketType>
|
||||
class SocketMgr
|
||||
{
|
||||
@@ -95,7 +93,7 @@ public:
|
||||
_threads[i].Wait();
|
||||
}
|
||||
|
||||
virtual void OnSocketOpen(tcp::socket&& sock, uint32 threadIndex)
|
||||
virtual void OnSocketOpen(boost::asio::ip::tcp::socket&& sock, uint32 threadIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -123,7 +121,7 @@ public:
|
||||
return min;
|
||||
}
|
||||
|
||||
std::pair<tcp::socket*, uint32> GetSocketForAccept()
|
||||
std::pair<boost::asio::ip::tcp::socket*, uint32> GetSocketForAccept()
|
||||
{
|
||||
uint32 threadIndex = SelectThreadWithMinConnections();
|
||||
return std::make_pair(_threads[threadIndex].GetSocketForAccept(), threadIndex);
|
||||
|
||||
@@ -22,14 +22,13 @@
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
namespace boostssl = boost::asio::ssl;
|
||||
|
||||
template<class SslContext>
|
||||
class SslSocket
|
||||
{
|
||||
public:
|
||||
explicit SslSocket(tcp::socket&& socket) : _socket(std::move(socket)), _sslSocket(_socket, SslContext::instance())
|
||||
explicit SslSocket(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _sslSocket(_socket, SslContext::instance())
|
||||
{
|
||||
_sslSocket.set_verify_mode(boostssl::verify_none);
|
||||
}
|
||||
@@ -70,7 +69,7 @@ public:
|
||||
_socket.set_option(option, error);
|
||||
}
|
||||
|
||||
tcp::socket::endpoint_type remote_endpoint() const
|
||||
boost::asio::ip::tcp::socket::endpoint_type remote_endpoint() const
|
||||
{
|
||||
return _socket.remote_endpoint();
|
||||
}
|
||||
@@ -83,8 +82,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
tcp::socket _socket;
|
||||
boostssl::stream<tcp::socket&> _sslSocket;
|
||||
boost::asio::ip::tcp::socket _socket;
|
||||
boostssl::stream<boost::asio::ip::tcp::socket&> _sslSocket;
|
||||
};
|
||||
|
||||
#endif // SslSocket_h__
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
void RASession::Start()
|
||||
{
|
||||
// wait 1 second for active connections to send negotiation request
|
||||
|
||||
@@ -18,27 +18,25 @@
|
||||
#ifndef __RASESSION_H__
|
||||
#define __RASESSION_H__
|
||||
|
||||
#include <memory>
|
||||
#include "Define.h"
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
|
||||
#include <future>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
#include <memory>
|
||||
|
||||
const size_t bufferSize = 4096;
|
||||
|
||||
class RASession : public std::enable_shared_from_this <RASession>
|
||||
{
|
||||
public:
|
||||
RASession(tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
|
||||
RASession(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void Start();
|
||||
|
||||
const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }
|
||||
unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); }
|
||||
std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }
|
||||
uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); }
|
||||
|
||||
private:
|
||||
int Send(std::string_view data);
|
||||
@@ -50,7 +48,7 @@ private:
|
||||
static void CommandPrint(void* callbackArg, std::string_view text);
|
||||
static void CommandFinished(void* callbackArg, bool);
|
||||
|
||||
tcp::socket _socket;
|
||||
boost::asio::ip::tcp::socket _socket;
|
||||
boost::asio::streambuf _readBuffer;
|
||||
boost::asio::streambuf _writeBuffer;
|
||||
std::promise<void>* _commandExecuting;
|
||||
|
||||
Reference in New Issue
Block a user