24 #include <boost/asio/ip/tcp.hpp>
27 using boost::asio::ip::tcp;
29 template<
class SocketType>
38 virtual bool StartNetwork(boost::asio::io_service& service, std::string
const& bindIp,
uint16 port,
int threadCount)
46 catch (boost::system::system_error
const& err)
48 TC_LOG_ERROR(
"network",
"Exception caught in SocketMgr.StartNetwork (%s:%u): %s", bindIp.c_str(), port, err.what());
91 std::shared_ptr<SocketType> newSocket = std::make_shared<SocketType>(std::move(sock));
94 _threads[threadIndex].AddSocket(newSocket);
96 catch (boost::system::system_error
const& err)
98 TC_LOG_WARN(
"network",
"Failed to retrieve client's remote address %s", err.what());
133 #endif // SocketMgr_h__
void Wait()
Definition: SocketMgr.h:80
int32 _threadCount
Definition: SocketMgr.h:130
virtual ~SocketMgr()
Definition: SocketMgr.h:33
Definition: AsyncAcceptor.h:28
void Close()
Definition: AsyncAcceptor.h:69
virtual bool StartNetwork(boost::asio::io_service &service, std::string const &bindIp, uint16 port, int threadCount)
Definition: SocketMgr.h:38
SocketMgr()
Definition: SocketMgr.h:122
AsyncAcceptor * _acceptor
Definition: SocketMgr.h:128
virtual NetworkThread< SocketType > * CreateThreads() const =0
virtual void OnSocketOpen(tcp::socket &&sock, uint32 threadIndex)
Definition: SocketMgr.h:87
T min(const T &x, const T &y)
Definition: g3dmath.h:305
Definition: NetworkThread.h:37
Definition: SocketMgr.h:30
uint32 SelectThreadWithMinConnections() const
Definition: SocketMgr.h:104
NetworkThread< SocketType > * _threads
Definition: SocketMgr.h:129
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
int32 GetNetworkThreadCount() const
Definition: SocketMgr.h:102
virtual void StopNetwork()
Definition: SocketMgr.h:63
std::pair< tcp::socket *, uint32 > GetSocketForAccept()
Definition: SocketMgr.h:115
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207