* Remove unused now TcpNoDelay config option. Patch provided by TonyMontana5000.

* Fixed: move includes to prevent fail rebuild WorldSocket.cpp.
 * Apply code style to WorldSocket.* and WorldSocketMgr.cpp
This commit is contained in:
vladimir-mangos 2008-10-17 06:30:08 +04:00
parent 245f868521
commit 398b5535b7
6 changed files with 343 additions and 350 deletions

View file

@ -558,7 +558,6 @@ void World::LoadConfigSettings(bool reload)
else
m_configs[CONFIG_SOCKET_SELECTTIME] = sConfig.GetIntDefault("SocketSelectTime", DEFAULT_SOCKET_SELECT_TIME);
m_configs[CONFIG_TCP_NO_DELAY] = sConfig.GetBoolDefault("TcpNoDelay", false);
m_configs[CONFIG_GROUP_XP_DISTANCE] = sConfig.GetIntDefault("MaxGroupXPDistance", 74);
/// \todo Add MonsterSight and GuarderSight (with meaning) in mangosd.conf or put them as define
m_configs[CONFIG_SIGHT_MONSTER] = sConfig.GetIntDefault("MonsterSight", 50);

View file

@ -146,7 +146,6 @@ enum WorldConfigs
CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL,
CONFIG_TALENTS_INSPECTING,
CONFIG_CHAT_FAKE_MESSAGE_PREVENTING,
CONFIG_TCP_NO_DELAY,
CONFIG_CORPSE_DECAY_NORMAL,
CONFIG_CORPSE_DECAY_RARE,
CONFIG_CORPSE_DECAY_ELITE,

View file

@ -16,8 +16,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Common.h"
#include "WorldSocket.h"
#include <ace/Message_Block.h>
#include <ace/OS_NS_string.h>
#include <ace/OS_NS_unistd.h>
@ -29,6 +27,9 @@
#include <ace/Reactor.h>
#include <ace/Auto_Ptr.h>
#include "WorldSocket.h"
#include "Common.h"
#include "Util.h"
#include "World.h"
#include "WorldPacket.h"

View file

@ -88,144 +88,144 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
*/
class WorldSocket : protected WorldHandler
{
public:
/// Declare some friends
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
friend class WorldSocketMgr;
friend class ReactorRunnable;
public:
/// Declare some friends
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
friend class WorldSocketMgr;
friend class ReactorRunnable;
/// Declare the acceptor for this class
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
/// Declare the acceptor for this class
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
/// Mutex type used for various syncronizations.
typedef ACE_Thread_Mutex LockType;
typedef ACE_Guard<LockType> GuardType;
/// Mutex type used for various syncronizations.
typedef ACE_Thread_Mutex LockType;
typedef ACE_Guard<LockType> GuardType;
/// Queue for storing packets for which there is no space.
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;
/// Queue for storing packets for which there is no space.
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;
/// Check if socket is closed.
bool IsClosed (void) const;
/// Check if socket is closed.
bool IsClosed (void) const;
/// Close the socket.
void CloseSocket (void);
/// Close the socket.
void CloseSocket (void);
/// Get address of connected peer.
const std::string& GetRemoteAddress (void) const;
/// Get address of connected peer.
const std::string& GetRemoteAddress (void) const;
/// Send A packet on the socket, this function is reentrant.
/// @param pct packet to send
/// @return -1 of failure
int SendPacket (const WorldPacket& pct);
/// Send A packet on the socket, this function is reentrant.
/// @param pct packet to send
/// @return -1 of failure
int SendPacket (const WorldPacket& pct);
/// Add refference to this object.
long AddReference (void);
/// Add refference to this object.
long AddReference (void);
/// Remove refference to this object.
long RemoveReference (void);
/// Remove refference to this object.
long RemoveReference (void);
protected:
/// things called by ACE framework.
WorldSocket (void);
virtual ~WorldSocket (void);
protected:
/// things called by ACE framework.
WorldSocket (void);
virtual ~WorldSocket (void);
/// Called on open ,the void* is the acceptor.
virtual int open (void *);
/// Called on open ,the void* is the acceptor.
virtual int open (void *);
/// Called on failures inside of the acceptor, don't call from your code.
virtual int close (int);
/// Called on failures inside of the acceptor, don't call from your code.
virtual int close (int);
/// Called when we can read from the socket.
virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE);
/// Called when we can read from the socket.
virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE);
/// Called when the socket can write.
virtual int handle_output (ACE_HANDLE = ACE_INVALID_HANDLE);
/// Called when the socket can write.
virtual int handle_output (ACE_HANDLE = ACE_INVALID_HANDLE);
/// Called when connection is closed or error happens.
virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
/// Called when connection is closed or error happens.
virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
/// Called by WorldSocketMgr/ReactorRunnable.
int Update (void);
/// Called by WorldSocketMgr/ReactorRunnable.
int Update (void);
private:
/// Helper functions for processing incoming data.
int handle_input_header (void);
int handle_input_payload (void);
int handle_input_missing_data (void);
private:
/// Helper functions for processing incoming data.
int handle_input_header (void);
int handle_input_payload (void);
int handle_input_missing_data (void);
/// Help functions to mark/unmark the socket for output.
/// @param g the guard is for m_OutBufferLock, the function will release it
int cancel_wakeup_output (GuardType& g);
int schedule_wakeup_output (GuardType& g);
/// Help functions to mark/unmark the socket for output.
/// @param g the guard is for m_OutBufferLock, the function will release it
int cancel_wakeup_output (GuardType& g);
int schedule_wakeup_output (GuardType& g);
/// process one incoming packet.
/// @param new_pct received packet ,note that you need to delete it.
int ProcessIncoming (WorldPacket* new_pct);
/// process one incoming packet.
/// @param new_pct received packet ,note that you need to delete it.
int ProcessIncoming (WorldPacket* new_pct);
/// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
int HandleAuthSession (WorldPacket& recvPacket);
/// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
int HandleAuthSession (WorldPacket& recvPacket);
/// Called by ProcessIncoming() on CMSG_PING.
int HandlePing (WorldPacket& recvPacket);
/// Called by ProcessIncoming() on CMSG_PING.
int HandlePing (WorldPacket& recvPacket);
/// Try to write WorldPacket to m_OutBuffer ,return -1 if no space
/// Need to be called with m_OutBufferLock lock held
int iSendPacket (const WorldPacket& pct);
/// Try to write WorldPacket to m_OutBuffer ,return -1 if no space
/// Need to be called with m_OutBufferLock lock held
int iSendPacket (const WorldPacket& pct);
/// Flush m_PacketQueue if there are packets in it
/// Need to be called with m_OutBufferLock lock held
/// @return true if it wrote to the buffer ( AKA you need
/// to mark the socket for output ).
bool iFlushPacketQueue ();
/// Flush m_PacketQueue if there are packets in it
/// Need to be called with m_OutBufferLock lock held
/// @return true if it wrote to the buffer ( AKA you need
/// to mark the socket for output ).
bool iFlushPacketQueue ();
private:
/// Time in which the last ping was received
ACE_Time_Value m_LastPingTime;
private:
/// Time in which the last ping was received
ACE_Time_Value m_LastPingTime;
/// Keep track of overspeed pings ,to prevent ping flood.
uint32 m_OverSpeedPings;
/// Keep track of overspeed pings ,to prevent ping flood.
uint32 m_OverSpeedPings;
/// Address of the remote peer
std::string m_Address;
/// Address of the remote peer
std::string m_Address;
/// Class used for managing encryption of the headers
AuthCrypt m_Crypt;
/// Class used for managing encryption of the headers
AuthCrypt m_Crypt;
/// Mutex lock to protect m_Session
LockType m_SessionLock;
/// Mutex lock to protect m_Session
LockType m_SessionLock;
/// Session to which recieved packets are routed
WorldSession* m_Session;
/// Session to which recieved packets are routed
WorldSession* m_Session;
/// here are stored the fragmens of the recieved data
WorldPacket* m_RecvWPct;
/// here are stored the fragmens of the recieved data
WorldPacket* m_RecvWPct;
/// This block actually refers to m_RecvWPct contents,
/// which alows easy and safe writing to it.
/// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
ACE_Message_Block m_RecvPct;
/// This block actually refers to m_RecvWPct contents,
/// which alows easy and safe writing to it.
/// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
ACE_Message_Block m_RecvPct;
/// Fragment of the recieved header.
ACE_Message_Block m_Header;
/// Fragment of the recieved header.
ACE_Message_Block m_Header;
/// Mutex for protecting otuput related data.
LockType m_OutBufferLock;
/// Mutex for protecting otuput related data.
LockType m_OutBufferLock;
/// Buffer used for writing output.
ACE_Message_Block *m_OutBuffer;
/// Buffer used for writing output.
ACE_Message_Block *m_OutBuffer;
/// Size of the m_OutBuffer.
size_t m_OutBufferSize;
/// Size of the m_OutBuffer.
size_t m_OutBufferSize;
/// Here are stored packets for which there was no space on m_OutBuffer,
/// this alows not-to kick player if its buffer is overflowed.
PacketQueueT m_PacketQueue;
/// Here are stored packets for which there was no space on m_OutBuffer,
/// this alows not-to kick player if its buffer is overflowed.
PacketQueueT m_PacketQueue;
/// True if the socket is registered with the reactor for output
bool m_OutActive;
/// True if the socket is registered with the reactor for output
bool m_OutActive;
uint32 m_Seed;
uint32 m_Seed;
};
#endif /* _WORLDSOCKET_H */

View file

@ -1,25 +1,25 @@
/*
* Copyright (C) 2005-2008,2007 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
* Copyright (C) 2005-2008,2007 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file WorldSocketMgr.cpp
* \ingroup u2w
* \author Derex <derex101@gmail.com>
*/
* \ingroup u2w
* \author Derex <derex101@gmail.com>
*/
#include "WorldSocketMgr.h"
@ -45,326 +45,324 @@
#include "WorldSocket.h"
/**
* This is a helper class to WorldSocketMgr ,that manages
* network threads, and assigning connections from acceptor thread
* to other network threads
*/
* This is a helper class to WorldSocketMgr ,that manages
* network threads, and assigning connections from acceptor thread
* to other network threads
*/
class ReactorRunnable : protected ACE_Task_Base
{
public:
public:
ReactorRunnable () :
m_ThreadId (-1),
m_Connections (0),
m_Reactor (0)
{
ACE_Reactor_Impl* imp = 0;
ReactorRunnable () :
m_ThreadId (-1),
m_Connections (0),
m_Reactor (0)
{
ACE_Reactor_Impl* imp = 0;
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
imp = new ACE_Dev_Poll_Reactor ();
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
imp->max_notify_iterations (128);
imp->restart (1);
#else
imp = new ACE_TP_Reactor ();
imp->max_notify_iterations (128);
#endif
imp = new ACE_Dev_Poll_Reactor ();
m_Reactor = new ACE_Reactor (imp, 1);
}
imp->max_notify_iterations (128);
imp->restart (1);
virtual
~ReactorRunnable ()
{
this->Stop ();
this->Wait ();
#else
if (m_Reactor)
delete m_Reactor;
}
imp = new ACE_TP_Reactor ();
imp->max_notify_iterations (128);
void
Stop ()
{
m_Reactor->end_reactor_event_loop ();
}
#endif
int
Start ()
{
if (m_ThreadId != -1)
return -1;
m_Reactor = new ACE_Reactor (imp, 1);
}
return (m_ThreadId = this->activate ());
}
virtual ~ReactorRunnable ()
{
this->Stop ();
this->Wait ();
void
Wait ()
{
ACE_Task_Base::wait ();
}
if (m_Reactor)
delete m_Reactor;
}
long
Connections ()
{
return static_cast<long> (m_Connections.value ());
}
void Stop ()
{
m_Reactor->end_reactor_event_loop ();
}
int
AddSocket (WorldSocket* sock)
{
ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1);
int Start ()
{
if (m_ThreadId != -1)
return -1;
++m_Connections;
sock->AddReference();
sock->reactor (m_Reactor);
m_NewSockets.insert (sock);
return (m_ThreadId = this->activate ());
}
return 0;
}
void Wait () { ACE_Task_Base::wait (); }
ACE_Reactor* GetReactor ()
{
return m_Reactor;
}
long Connections ()
{
return static_cast<long> (m_Connections.value ());
}
protected:
int AddSocket (WorldSocket* sock)
{
ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1);
void
AddNewSockets ()
{
ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock);
++m_Connections;
sock->AddReference();
sock->reactor (m_Reactor);
m_NewSockets.insert (sock);
if (m_NewSockets.empty ())
return;
return 0;
}
for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i)
{
WorldSocket* sock = (*i);
ACE_Reactor* GetReactor ()
{
return m_Reactor;
}
if (sock->IsClosed ())
{
sock->RemoveReference ();
--m_Connections;
}
else
m_Sockets.insert (sock);
}
protected:
m_NewSockets.clear ();
}
void AddNewSockets ()
{
ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock);
virtual int
svc (void)
{
DEBUG_LOG ("Network Thread Starting");
if (m_NewSockets.empty ())
return;
WorldDatabase.ThreadStart ();
for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i)
{
WorldSocket* sock = (*i);
ACE_ASSERT (m_Reactor);
if (sock->IsClosed ())
{
sock->RemoveReference ();
--m_Connections;
}
else
m_Sockets.insert (sock);
}
SocketSet::iterator i, t;
m_NewSockets.clear ();
}
while (!m_Reactor->reactor_event_loop_done ())
{
// dont be too smart to move this outside the loop
// the run_reactor_event_loop will modify interval
ACE_Time_Value interval (0, 10000);
virtual int svc ()
{
DEBUG_LOG ("Network Thread Starting");
if (m_Reactor->run_reactor_event_loop (interval) == -1)
break;
WorldDatabase.ThreadStart ();
AddNewSockets ();
ACE_ASSERT (m_Reactor);
for (i = m_Sockets.begin (); i != m_Sockets.end ();)
{
if ((*i)->Update () == -1)
{
t = i;
i++;
(*t)->CloseSocket ();
(*t)->RemoveReference ();
--m_Connections;
m_Sockets.erase (t);
}
else
i++;
}
}
SocketSet::iterator i, t;
WorldDatabase.ThreadEnd ();
while (!m_Reactor->reactor_event_loop_done ())
{
// dont be too smart to move this outside the loop
// the run_reactor_event_loop will modify interval
ACE_Time_Value interval (0, 10000);
DEBUG_LOG ("Network Thread Exitting");
if (m_Reactor->run_reactor_event_loop (interval) == -1)
break;
return 0;
}
AddNewSockets ();
private:
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
typedef std::set<WorldSocket*> SocketSet;
for (i = m_Sockets.begin (); i != m_Sockets.end ();)
{
if ((*i)->Update () == -1)
{
t = i;
i++;
(*t)->CloseSocket ();
(*t)->RemoveReference ();
--m_Connections;
m_Sockets.erase (t);
}
else
i++;
}
}
ACE_Reactor* m_Reactor;
AtomicInt m_Connections;
int m_ThreadId;
WorldDatabase.ThreadEnd ();
SocketSet m_Sockets;
DEBUG_LOG ("Network Thread Exitting");
SocketSet m_NewSockets;
ACE_Thread_Mutex m_NewSockets_Lock;
return 0;
}
private:
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
typedef std::set<WorldSocket*> SocketSet;
ACE_Reactor* m_Reactor;
AtomicInt m_Connections;
int m_ThreadId;
SocketSet m_Sockets;
SocketSet m_NewSockets;
ACE_Thread_Mutex m_NewSockets_Lock;
};
WorldSocketMgr::WorldSocketMgr () :
m_NetThreadsCount (0),
m_NetThreads (0),
m_SockOutKBuff (-1),
m_SockOutUBuff (65536),
m_UseNoDelay (true),
m_Acceptor (0) {}
m_NetThreadsCount (0),
m_NetThreads (0),
m_SockOutKBuff (-1),
m_SockOutUBuff (65536),
m_UseNoDelay (true),
m_Acceptor (0)
{
}
WorldSocketMgr::~WorldSocketMgr ()
{
if (m_NetThreads)
delete [] m_NetThreads;
if (m_NetThreads)
delete [] m_NetThreads;
if(m_Acceptor)
delete m_Acceptor;
if(m_Acceptor)
delete m_Acceptor;
}
int
WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
{
m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true);
m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true);
int num_threads = sConfig.GetIntDefault ("Network.Threads", 1);
int num_threads = sConfig.GetIntDefault ("Network.Threads", 1);
if (num_threads <= 0)
if (num_threads <= 0)
{
sLog.outError ("Network.Threads is wrong in your config file");
return -1;
sLog.outError ("Network.Threads is wrong in your config file");
return -1;
}
m_NetThreadsCount = static_cast<size_t> (num_threads + 1);
m_NetThreadsCount = static_cast<size_t> (num_threads + 1);
m_NetThreads = new ReactorRunnable[m_NetThreadsCount];
m_NetThreads = new ReactorRunnable[m_NetThreadsCount];
sLog.outBasic ("Max alowed socket connections %d",ACE::max_handles ());
sLog.outBasic ("Max alowed socket connections %d",ACE::max_handles ());
m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1); // -1 means use default
// -1 means use default
m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1);
m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536);
m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536);
if ( m_SockOutUBuff <= 0 )
if ( m_SockOutUBuff <= 0 )
{
sLog.outError ("Network.OutUBuff is wrong in your config file");
return -1;
sLog.outError ("Network.OutUBuff is wrong in your config file");
return -1;
}
WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
m_Acceptor = acc;
WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
m_Acceptor = acc;
ACE_INET_Addr listen_addr (port, address);
ACE_INET_Addr listen_addr (port, address);
if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1)
if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1)
{
sLog.outError ("Failed to open acceptor ,check if the port is free");
return -1;
sLog.outError ("Failed to open acceptor ,check if the port is free");
return -1;
}
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Start ();
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Start ();
return 0;
return 0;
}
int
WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address)
{
if (!sLog.IsOutDebug ())
ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
if (!sLog.IsOutDebug ())
ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
if (this->StartReactiveIO (port, address) == -1)
return -1;
if (this->StartReactiveIO (port, address) == -1)
return -1;
return 0;
return 0;
}
void
WorldSocketMgr::StopNetwork ()
{
if (m_Acceptor)
if (m_Acceptor)
{
WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
if (acc)
acc->close ();
if (acc)
acc->close ();
}
if (m_NetThreadsCount != 0)
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Stop ();
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Stop ();
}
this->Wait ();
this->Wait ();
}
void
WorldSocketMgr::Wait ()
{
if (m_NetThreadsCount != 0)
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Wait ();
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Wait ();
}
}
int
WorldSocketMgr::OnSocketOpen (WorldSocket* sock)
{
// set some options here
if (m_SockOutKBuff >= 0)
if (sock->peer ().set_option (SOL_SOCKET,
SO_SNDBUF,
(void*) & m_SockOutKBuff,
sizeof (int)) == -1 && errno != ENOTSUP)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF");
return -1;
}
// set some options here
if (m_SockOutKBuff >= 0)
{
if (sock->peer ().set_option (SOL_SOCKET,
SO_SNDBUF,
(void*) & m_SockOutKBuff,
sizeof (int)) == -1 && errno != ENOTSUP)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF");
return -1;
}
}
static const int ndoption = 1;
static const int ndoption = 1;
// Set TCP_NODELAY.
if (m_UseNoDelay)
if (sock->peer ().set_option (ACE_IPPROTO_TCP,
TCP_NODELAY,
(void*) & ndoption,
sizeof (int)) == -1)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno));
return -1;
}
// Set TCP_NODELAY.
if (m_UseNoDelay)
{
if (sock->peer ().set_option (ACE_IPPROTO_TCP,
TCP_NODELAY,
(void*)&ndoption,
sizeof (int)) == -1)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno));
return -1;
}
}
sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
// we skip the Acceptor Thread
size_t min = 1;
// we skip the Acceptor Thread
size_t min = 1;
ACE_ASSERT (m_NetThreadsCount >= 1);
ACE_ASSERT (m_NetThreadsCount >= 1);
for (size_t i = 1; i < m_NetThreadsCount; ++i)
if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ())
min = i;
for (size_t i = 1; i < m_NetThreadsCount; ++i)
if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ())
min = i;
return m_NetThreads[min].AddSocket (sock);
return m_NetThreads[min].AddSocket (sock);
return 0;
return 0;
}
WorldSocketMgr*
WorldSocketMgr::Instance ()
{
return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance();
return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance();
}

View file

@ -70,11 +70,6 @@ BindIP = "0.0.0.0"
# Default: 1 (speed)
# 9 (best compression)
#
# TcpNoDelay
# TCP Nagle algorithm setting
# Default: 0 (enable Nagle algorithm, less traffic, more latency)
# 1 (TCP_NO_DELAY, disable Nagle algorithm, more traffic but less latency)
#
# PlayerLimit
# Maximum number of players in the world. Excluding Mods, GM's and Admins
# Default: 100
@ -1026,23 +1021,24 @@ Death.CorpseReclaimDelay.PvE = 1
###################################################################################################################
#
# Network config
# NETWORK CONFIG
#
# Threads: Number of threads for network, recommend 1 thread per 1000 connections.
# Default: 1
# Network.Threads
# Number of threads for network, recommend 1 thread per 1000 connections.
# Default: 1
#
# OutKBuff: The size of the output kernel buffer used ( SO_SNDBUF socket option, tcp manual ).
# Default: -1 (Use system default setting)
#
# OutUBuff: Userspace buffer for output. This is amount of memory reserved per each connection.
# Default: 65536
#
# TcpNoDelay:
# TCP Nagle algorithm setting
# Default: 0 (enable Nagle algorithm, less traffic, more latency)
# 1 (TCP_NO_DELAY, disable Nagle algorithm, more traffic but less latency)
# Network.OutKBuff
# The size of the output kernel buffer used ( SO_SNDBUF socket option, tcp manual ).
# Default: -1 (Use system default setting)
#
# Network.OutUBuff
# Userspace buffer for output. This is amount of memory reserved per each connection.
# Default: 65536
#
# Network.TcpNoDelay:
# TCP Nagle algorithm setting
# Default: 0 (enable Nagle algorithm, less traffic, more latency)
# 1 (TCP_NO_DELAY, disable Nagle algorithm, more traffic but less latency)
#
###################################################################################################################