Core/Network: Handle running out of file descriptors on linux-based systems (windows-based systems requires additional fixes)
Signed-off-by: click <[email protected]>
This commit is contained in:
@@ -29,7 +29,11 @@ class RealmAcceptor : public ACE_Acceptor<RealmSocket, ACE_SOCK_Acceptor>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RealmAcceptor(void) { }
|
RealmAcceptor(void) { }
|
||||||
virtual ~RealmAcceptor(void) { }
|
virtual ~RealmAcceptor(void)
|
||||||
|
{
|
||||||
|
if (reactor())
|
||||||
|
reactor()->cancel_timer(this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int make_svc_handler(RealmSocket *&sh)
|
virtual int make_svc_handler(RealmSocket *&sh)
|
||||||
@@ -41,6 +45,26 @@ protected:
|
|||||||
sh->set_session(new AuthSocket(*sh));
|
sh->set_session(new AuthSocket(*sh));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/)
|
||||||
|
{
|
||||||
|
sLog->outBasic("Resuming acceptor");
|
||||||
|
reactor()->cancel_timer(this, 1);
|
||||||
|
return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int handle_accept_error(void)
|
||||||
|
{
|
||||||
|
#if defined(ENFILE) && defined(EMFILE)
|
||||||
|
if (errno == ENFILE || errno == EMFILE)
|
||||||
|
{
|
||||||
|
sLog->outError("Out of file descriptors, suspending incoming connections for 10 seconds");
|
||||||
|
reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL);
|
||||||
|
reactor()->schedule_timer(this, NULL, ACE_Time_Value(10));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <ace/Synch_Traits.h>
|
#include <ace/Synch_Traits.h>
|
||||||
#include <ace/Svc_Handler.h>
|
#include <ace/Svc_Handler.h>
|
||||||
#include <ace/SOCK_Stream.h>
|
#include <ace/SOCK_Stream.h>
|
||||||
#include <ace/SOCK_Acceptor.h>
|
|
||||||
#include <ace/Acceptor.h>
|
|
||||||
#include <ace/Thread_Mutex.h>
|
#include <ace/Thread_Mutex.h>
|
||||||
#include <ace/Guard_T.h>
|
#include <ace/Guard_T.h>
|
||||||
#include <ace/Unbounded_Queue.h>
|
#include <ace/Unbounded_Queue.h>
|
||||||
@@ -74,9 +72,9 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
|
|||||||
* The calls to Update() method are managed by WorldSocketMgr
|
* The calls to Update() method are managed by WorldSocketMgr
|
||||||
* and ReactorRunnable.
|
* and ReactorRunnable.
|
||||||
*
|
*
|
||||||
* For input , the class uses one 1024 bytes buffer on stack
|
* For input, the class uses one 4096 bytes buffer on stack
|
||||||
* to which it does recv() calls. And then received data is
|
* to which it does recv() calls. And then received data is
|
||||||
* distributed where its needed. 1024 matches pretty well the
|
* distributed where its needed. 4096 matches pretty well the
|
||||||
* traffic generated by client for now.
|
* traffic generated by client for now.
|
||||||
*
|
*
|
||||||
* The input/output do speculative reads/writes (AKA it tryes
|
* The input/output do speculative reads/writes (AKA it tryes
|
||||||
@@ -86,16 +84,13 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
|
|||||||
* notification.
|
* notification.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class WorldSocket : protected WorldHandler
|
class WorldSocket : public WorldHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Declare some friends
|
WorldSocket (void);
|
||||||
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
|
virtual ~WorldSocket (void);
|
||||||
friend class WorldSocketMgr;
|
|
||||||
friend class ReactorRunnable;
|
|
||||||
|
|
||||||
/// Declare the acceptor for this class
|
friend class WorldSocketMgr;
|
||||||
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
|
|
||||||
|
|
||||||
/// Mutex type used for various synchronizations.
|
/// Mutex type used for various synchronizations.
|
||||||
typedef ACE_Thread_Mutex LockType;
|
typedef ACE_Thread_Mutex LockType;
|
||||||
@@ -121,10 +116,7 @@ class WorldSocket : protected WorldHandler
|
|||||||
/// Remove reference to this object.
|
/// Remove reference to this object.
|
||||||
long RemoveReference (void);
|
long RemoveReference (void);
|
||||||
|
|
||||||
protected:
|
|
||||||
/// things called by ACE framework.
|
/// things called by ACE framework.
|
||||||
WorldSocket (void);
|
|
||||||
virtual ~WorldSocket (void);
|
|
||||||
|
|
||||||
/// Called on open , the void* is the acceptor.
|
/// Called on open , the void* is the acceptor.
|
||||||
virtual int open (void *);
|
virtual int open (void *);
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \addtogroup u2w User to World Communication
|
||||||
|
* @{
|
||||||
|
* \file WorldSocketMgr.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __WORLDSOCKETACCEPTOR_H_
|
||||||
|
#define __WORLDSOCKETACCEPTOR_H_
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
|
#include <ace/Acceptor.h>
|
||||||
|
#include <ace/SOCK_Acceptor.h>
|
||||||
|
|
||||||
|
#include "WorldSocket.h"
|
||||||
|
|
||||||
|
class WorldSocketAcceptor : public ACE_Acceptor<WorldSocket, ACE_SOCK_Acceptor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorldSocketAcceptor(void) { }
|
||||||
|
virtual ~WorldSocketAcceptor(void)
|
||||||
|
{
|
||||||
|
if (reactor())
|
||||||
|
reactor()->cancel_timer(this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/)
|
||||||
|
{
|
||||||
|
sLog->outBasic("Resuming acceptor");
|
||||||
|
reactor()->cancel_timer(this, 1);
|
||||||
|
return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int handle_accept_error(void)
|
||||||
|
{
|
||||||
|
#if defined(ENFILE) && defined(EMFILE)
|
||||||
|
if (errno == ENFILE || errno == EMFILE)
|
||||||
|
{
|
||||||
|
sLog->outError("Out of file descriptors, suspending incoming connections for 10 seconds");
|
||||||
|
reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL);
|
||||||
|
reactor()->schedule_timer(this, NULL, ACE_Time_Value(10));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __WORLDSOCKETACCEPTOR_H_ */
|
||||||
|
/// @}
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "WorldSocket.h"
|
#include "WorldSocket.h"
|
||||||
|
#include "WorldSocketAcceptor.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,12 +257,11 @@ WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
|
m_Acceptor = new WorldSocketAcceptor;
|
||||||
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 (m_Acceptor->open(listen_addr, m_NetThreads[0].GetReactor(), ACE_NONBLOCK) == -1)
|
||||||
{
|
{
|
||||||
sLog->outError ("Failed to open acceptor , check if the port is free");
|
sLog->outError ("Failed to open acceptor , check if the port is free");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -292,10 +292,7 @@ WorldSocketMgr::StopNetwork()
|
|||||||
{
|
{
|
||||||
if (m_Acceptor)
|
if (m_Acceptor)
|
||||||
{
|
{
|
||||||
WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
|
m_Acceptor->close();
|
||||||
|
|
||||||
if (acc)
|
|
||||||
acc->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_NetThreadsCount != 0)
|
if (m_NetThreadsCount != 0)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ private:
|
|||||||
int m_SockOutUBuff;
|
int m_SockOutUBuff;
|
||||||
bool m_UseNoDelay;
|
bool m_UseNoDelay;
|
||||||
|
|
||||||
ACE_Event_Handler* m_Acceptor;
|
class WorldSocketAcceptor* m_Acceptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sWorldSocketMgr ACE_Singleton<WorldSocketMgr, ACE_Thread_Mutex>::instance()
|
#define sWorldSocketMgr ACE_Singleton<WorldSocketMgr, ACE_Thread_Mutex>::instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user