TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WorldSocketMgr Class Reference

Manages all sockets connected to peers and network threads. More...

#include <WorldSocketMgr.h>

Public Member Functions

 ~WorldSocketMgr ()
 
bool StartNetwork (boost::asio::io_service &service, std::string const &bindIp, uint16 port, int networkThreads) override
 Start network, listen at address:port . More...
 
void StopNetwork () override
 Stops all network threads, It will wait for all running threads . More...
 
void OnSocketOpen (tcp::socket &&sock, uint32 threadIndex) override
 
- Public Member Functions inherited from SocketMgr< WorldSocket >
virtual ~SocketMgr ()
 
void Wait ()
 
int32 GetNetworkThreadCount () const
 
uint32 SelectThreadWithMinConnections () const
 
std::pair< tcp::socket *, uint32GetSocketForAccept ()
 

Static Public Member Functions

static WorldSocketMgrInstance ()
 

Protected Member Functions

 WorldSocketMgr ()
 
NetworkThread< WorldSocket > * CreateThreads () const override
 
- Protected Member Functions inherited from SocketMgr< WorldSocket >
 SocketMgr ()
 

Private Types

typedef SocketMgr< WorldSocketBaseSocketMgr
 

Private Attributes

AsyncAcceptor_instanceAcceptor
 
int32 _socketSendBufferSize
 
int32 m_SockOutUBuff
 
bool _tcpNoDelay
 

Additional Inherited Members

- Protected Attributes inherited from SocketMgr< WorldSocket >
AsyncAcceptor_acceptor
 
NetworkThread< WorldSocket > * _threads
 
int32 _threadCount
 

Detailed Description

Manages all sockets connected to peers and network threads.

Member Typedef Documentation

Constructor & Destructor Documentation

WorldSocketMgr::~WorldSocketMgr ( )
51 {
52  ASSERT(!_instanceAcceptor, "StopNetwork must be called prior to WorldSocketMgr destruction");
53 }
AsyncAcceptor * _instanceAcceptor
Definition: WorldSocketMgr.h:56
#define ASSERT
Definition: Errors.h:55
WorldSocketMgr::WorldSocketMgr ( )
protected
47 {
48 }
SocketMgr< WorldSocket > BaseSocketMgr
Definition: WorldSocketMgr.h:35
int32 _socketSendBufferSize
Definition: WorldSocketMgr.h:57
AsyncAcceptor * _instanceAcceptor
Definition: WorldSocketMgr.h:56
bool _tcpNoDelay
Definition: WorldSocketMgr.h:59
int32 m_SockOutUBuff
Definition: WorldSocketMgr.h:58

Member Function Documentation

NetworkThread< WorldSocket > * WorldSocketMgr::CreateThreads ( ) const
overrideprotectedvirtual

Implements SocketMgr< WorldSocket >.

135 {
137 }
Definition: WorldSocketMgr.cpp:32
int32 GetNetworkThreadCount() const
Definition: SocketMgr.h:102

+ Here is the call graph for this function:

WorldSocketMgr & WorldSocketMgr::Instance ( )
static
56 {
57  static WorldSocketMgr instance;
58  return instance;
59 }
Manages all sockets connected to peers and network threads.
Definition: WorldSocketMgr.h:33
void WorldSocketMgr::OnSocketOpen ( tcp::socket &&  sock,
uint32  threadIndex 
)
overridevirtual

Reimplemented from SocketMgr< WorldSocket >.

104 {
105  // set some options here
106  if (_socketSendBufferSize >= 0)
107  {
108  boost::system::error_code err;
109  sock.set_option(boost::asio::socket_base::send_buffer_size(_socketSendBufferSize), err);
110  if (err && err != boost::system::errc::not_supported)
111  {
112  TC_LOG_ERROR("misc", "WorldSocketMgr::OnSocketOpen sock.set_option(boost::asio::socket_base::send_buffer_size) err = %s", err.message().c_str());
113  return;
114  }
115  }
116 
117  // Set TCP_NODELAY.
118  if (_tcpNoDelay)
119  {
120  boost::system::error_code err;
121  sock.set_option(boost::asio::ip::tcp::no_delay(true), err);
122  if (err)
123  {
124  TC_LOG_ERROR("misc", "WorldSocketMgr::OnSocketOpen sock.set_option(boost::asio::ip::tcp::no_delay) err = %s", err.message().c_str());
125  return;
126  }
127  }
128 
129  //sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
130 
131  BaseSocketMgr::OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
132 }
int32 _socketSendBufferSize
Definition: WorldSocketMgr.h:57
virtual void OnSocketOpen(tcp::socket &&sock, uint32 threadIndex)
Definition: SocketMgr.h:87
bool _tcpNoDelay
Definition: WorldSocketMgr.h:59
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

bool WorldSocketMgr::StartNetwork ( boost::asio::io_service &  service,
std::string const bindIp,
uint16  port,
int  networkThreads 
)
overridevirtual

Start network, listen at address:port .

Reimplemented from SocketMgr< WorldSocket >.

62 {
63  _tcpNoDelay = sConfigMgr->GetBoolDefault("Network.TcpNodelay", true);
64 
65  int const max_connections = boost::asio::socket_base::max_connections;
66  TC_LOG_DEBUG("misc", "Max allowed socket connections %d", max_connections);
67 
68  // -1 means use default
69  _socketSendBufferSize = sConfigMgr->GetIntDefault("Network.OutKBuff", -1);
70 
71  m_SockOutUBuff = sConfigMgr->GetIntDefault("Network.OutUBuff", 65536);
72 
73  if (m_SockOutUBuff <= 0)
74  {
75  TC_LOG_ERROR("misc", "Network.OutUBuff is wrong in your config file");
76  return false;
77  }
78 
79  BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount);
80  _instanceAcceptor = new AsyncAcceptor(service, bindIp, uint16(sWorld->getIntConfig(CONFIG_PORT_INSTANCE)));
81 
84 
87 
88  sScriptMgr->OnNetworkStart();
89  return true;
90 }
Definition: AsyncAcceptor.h:28
virtual bool StartNetwork(boost::asio::io_service &service, std::string const &bindIp, uint16 port, int threadCount)
Definition: SocketMgr.h:38
int32 _socketSendBufferSize
Definition: WorldSocketMgr.h:57
Definition: World.h:216
#define sConfigMgr
Definition: Config.h:61
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
AsyncAcceptor * _acceptor
Definition: SocketMgr.h:128
#define sWorld
Definition: World.h:887
AsyncAcceptor * _instanceAcceptor
Definition: WorldSocketMgr.h:56
uint16_t uint16
Definition: g3dmath.h:166
void SetSocketFactory(std::function< std::pair< tcp::socket *, uint32 >()> func)
Definition: AsyncAcceptor.h:78
bool _tcpNoDelay
Definition: WorldSocketMgr.h:59
static void OnSocketAccept(tcp::socket &&sock, uint32 threadIndex)
Definition: WorldSocketMgr.cpp:27
std::pair< tcp::socket *, uint32 > GetSocketForAccept()
Definition: SocketMgr.h:115
int32 m_SockOutUBuff
Definition: WorldSocketMgr.h:58
void AsyncAcceptWithCallback()
Definition: AsyncAcceptor.h:43
#define sScriptMgr
Definition: ScriptMgr.h:837
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

void WorldSocketMgr::StopNetwork ( )
overridevirtual

Stops all network threads, It will wait for all running threads .

Reimplemented from SocketMgr< WorldSocket >.

93 {
96 
97  delete _instanceAcceptor;
98  _instanceAcceptor = nullptr;
99 
100  sScriptMgr->OnNetworkStop();
101 }
void Close()
Definition: AsyncAcceptor.h:69
AsyncAcceptor * _instanceAcceptor
Definition: WorldSocketMgr.h:56
virtual void StopNetwork()
Definition: SocketMgr.h:63
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the call graph for this function:

Member Data Documentation

AsyncAcceptor* WorldSocketMgr::_instanceAcceptor
private
int32 WorldSocketMgr::_socketSendBufferSize
private
bool WorldSocketMgr::_tcpNoDelay
private
int32 WorldSocketMgr::m_SockOutUBuff
private

The documentation for this class was generated from the following files: