aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerex <derex101@gmail.com>2011-06-23 11:14:01 +0200
committerclick <click@gonnamakeyou.com>2011-06-23 11:14:01 +0200
commitd65e1d9a3fc7d597425d6b1fed76d07b22d6008c (patch)
tree8dde4e5dfc82b559969c3916e55e9b22e15e4e70 /src
parent90a34fdc0644a6165bdd2dc9dcf2adf87e74807a (diff)
Core/Network: Handle running out of file descriptors on linux-based systems (windows-based systems requires additional fixes)
Signed-off-by: click <click@gonnamakeyou.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/authserver/Server/RealmAcceptor.h26
-rwxr-xr-xsrc/server/game/Server/WorldSocket.h20
-rw-r--r--src/server/game/Server/WorldSocketAcceptor.h67
-rwxr-xr-xsrc/server/game/Server/WorldSocketMgr.cpp11
-rwxr-xr-xsrc/server/game/Server/WorldSocketMgr.h2
5 files changed, 103 insertions, 23 deletions
diff --git a/src/server/authserver/Server/RealmAcceptor.h b/src/server/authserver/Server/RealmAcceptor.h
index a245c7914f5..99817dfddac 100755
--- a/src/server/authserver/Server/RealmAcceptor.h
+++ b/src/server/authserver/Server/RealmAcceptor.h
@@ -29,7 +29,11 @@ class RealmAcceptor : public ACE_Acceptor<RealmSocket, ACE_SOCK_Acceptor>
{
public:
RealmAcceptor(void) { }
- virtual ~RealmAcceptor(void) { }
+ virtual ~RealmAcceptor(void)
+ {
+ if (reactor())
+ reactor()->cancel_timer(this, 1);
+ }
protected:
virtual int make_svc_handler(RealmSocket *&sh)
@@ -41,6 +45,26 @@ protected:
sh->set_session(new AuthSocket(*sh));
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
diff --git a/src/server/game/Server/WorldSocket.h b/src/server/game/Server/WorldSocket.h
index 7e87b38f737..7a121cbe3df 100755
--- a/src/server/game/Server/WorldSocket.h
+++ b/src/server/game/Server/WorldSocket.h
@@ -29,8 +29,6 @@
#include <ace/Synch_Traits.h>
#include <ace/Svc_Handler.h>
#include <ace/SOCK_Stream.h>
-#include <ace/SOCK_Acceptor.h>
-#include <ace/Acceptor.h>
#include <ace/Thread_Mutex.h>
#include <ace/Guard_T.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
* 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
- * distributed where its needed. 1024 matches pretty well the
+ * distributed where its needed. 4096 matches pretty well the
* traffic generated by client for now.
*
* 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.
*
*/
-class WorldSocket : protected WorldHandler
+class WorldSocket : public WorldHandler
{
public:
- /// Declare some friends
- friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
- friend class WorldSocketMgr;
- friend class ReactorRunnable;
+ WorldSocket (void);
+ virtual ~WorldSocket (void);
- /// Declare the acceptor for this class
- typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
+ friend class WorldSocketMgr;
/// Mutex type used for various synchronizations.
typedef ACE_Thread_Mutex LockType;
@@ -121,10 +116,7 @@ class WorldSocket : protected WorldHandler
/// Remove reference to this object.
long RemoveReference (void);
- protected:
/// things called by ACE framework.
- WorldSocket (void);
- virtual ~WorldSocket (void);
/// Called on open , the void* is the acceptor.
virtual int open (void *);
diff --git a/src/server/game/Server/WorldSocketAcceptor.h b/src/server/game/Server/WorldSocketAcceptor.h
new file mode 100644
index 00000000000..1d3155b9e06
--- /dev/null
+++ b/src/server/game/Server/WorldSocketAcceptor.h
@@ -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_ */
+/// @}
diff --git a/src/server/game/Server/WorldSocketMgr.cpp b/src/server/game/Server/WorldSocketMgr.cpp
index 2454f6df5d0..4151c646fb2 100755
--- a/src/server/game/Server/WorldSocketMgr.cpp
+++ b/src/server/game/Server/WorldSocketMgr.cpp
@@ -43,6 +43,7 @@
#include "Config.h"
#include "DatabaseEnv.h"
#include "WorldSocket.h"
+#include "WorldSocketAcceptor.h"
#include "ScriptMgr.h"
/**
@@ -256,12 +257,11 @@ WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
return -1;
}
- WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
- m_Acceptor = acc;
+ m_Acceptor = new WorldSocketAcceptor;
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");
return -1;
@@ -292,10 +292,7 @@ WorldSocketMgr::StopNetwork()
{
if (m_Acceptor)
{
- WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
-
- if (acc)
- acc->close();
+ m_Acceptor->close();
}
if (m_NetThreadsCount != 0)
diff --git a/src/server/game/Server/WorldSocketMgr.h b/src/server/game/Server/WorldSocketMgr.h
index eb6ee9efbe6..25f92042f4e 100755
--- a/src/server/game/Server/WorldSocketMgr.h
+++ b/src/server/game/Server/WorldSocketMgr.h
@@ -65,7 +65,7 @@ private:
int m_SockOutUBuff;
bool m_UseNoDelay;
- ACE_Event_Handler* m_Acceptor;
+ class WorldSocketAcceptor* m_Acceptor;
};
#define sWorldSocketMgr ACE_Singleton<WorldSocketMgr, ACE_Thread_Mutex>::instance()