24#include <boost/asio/ip/tcp.hpp>
27template<
class SocketType>
45 catch (boost::system::system_error
const& err)
47 TC_LOG_ERROR(
"network",
"Exception caught in SocketMgr.StartNetwork ({}:{}): {}", bindIp, port, err.what());
51 if (!acceptor->
Bind())
53 TC_LOG_ERROR(
"network",
"StartNetwork failed to bind socket acceptor");
100 std::shared_ptr<SocketType> newSocket = std::make_shared<SocketType>(std::move(sock));
103 _threads[threadIndex].AddSocket(newSocket);
105 catch (boost::system::system_error
const& err)
107 TC_LOG_WARN(
"network",
"Failed to retrieve client's remote address {}", err.what());
#define TC_LOG_WARN(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
void SetSocketFactory(std::function< std::pair< boost::asio::ip::tcp::socket *, uint32 >()> func)
AsyncAcceptor * _acceptor
NetworkThread< SocketType > * _threads
virtual bool StartNetwork(Trinity::Asio::IoContext &ioContext, std::string const &bindIp, uint16 port, int threadCount)
virtual void OnSocketOpen(boost::asio::ip::tcp::socket &&sock, uint32 threadIndex)
virtual void StopNetwork()
std::pair< boost::asio::ip::tcp::socket *, uint32 > GetSocketForAccept()
uint32 SelectThreadWithMinConnections() const
int32 GetNetworkThreadCount() const
virtual NetworkThread< SocketType > * CreateThreads() const =0