18#ifndef TRINITYCORE_SOCKET_MGR_H
19#define TRINITYCORE_SOCKET_MGR_H
25#include <boost/asio/ip/tcp.hpp>
30template<
class SocketType>
48 std::unique_ptr<AsyncAcceptor> acceptor =
nullptr;
51 acceptor = std::make_unique<AsyncAcceptor>(ioContext, bindIp, port);
53 catch (boost::system::system_error
const& err)
55 TC_LOG_ERROR(
"network",
"Exception caught in SocketMgr.StartNetwork ({}:{}): {}", bindIp, port, err.what());
59 if (!acceptor->Bind())
61 TC_LOG_ERROR(
"network",
"StartNetwork failed to bind socket acceptor");
103 std::shared_ptr<SocketType> newSocket = std::make_shared<SocketType>(std::move(sock));
106 _threads[threadIndex].AddSocket(newSocket);
108 catch (boost::system::system_error
const& err)
110 TC_LOG_WARN(
"network",
"Failed to retrieve client's remote address {}", err.what());
141 std::unique_ptr<NetworkThread<SocketType>[]>
_threads;
#define TC_LOG_WARN(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
SocketMgr(SocketMgr const &)=delete
std::unique_ptr< NetworkThread< SocketType >[]> _threads
uint32 SelectThreadWithMinConnections() const
virtual void OnSocketOpen(IoContextTcpSocket &&sock, uint32 threadIndex)
int32 GetNetworkThreadCount() const
SocketMgr(SocketMgr &&)=delete
std::pair< IoContextTcpSocket *, uint32 > GetSocketForAccept()
std::unique_ptr< AsyncAcceptor > _acceptor
SocketMgr & operator=(SocketMgr &&)=delete
virtual bool StartNetwork(Asio::IoContext &ioContext, std::string const &bindIp, uint16 port, int threadCount)
virtual void StopNetwork()
virtual NetworkThread< SocketType > * CreateThreads() const =0
SocketMgr & operator=(SocketMgr const &)=delete
boost::asio::basic_stream_socket< boost::asio::ip::tcp, boost::asio::io_context::executor_type > IoContextTcpSocket