aboutsummaryrefslogtreecommitdiff
path: root/src/trinityrealm/Main.cpp
diff options
context:
space:
mode:
authorAnubisss <none@none>2010-05-19 21:16:59 +0200
committerAnubisss <none@none>2010-05-19 21:16:59 +0200
commita5840e9286de8e610b3e4f01438e1e7117b6de3a (patch)
treeaabc7aa2d458ef79800610b5138a0e754d547c98 /src/trinityrealm/Main.cpp
parenta04809437bdc0f5ae0865fdc6b1b43f542cdfae7 (diff)
Implement a signalhandler via ACE.
Thanks to Diver for test compiling under WIN. --HG-- branch : trunk
Diffstat (limited to 'src/trinityrealm/Main.cpp')
-rw-r--r--src/trinityrealm/Main.cpp87
1 files changed, 37 insertions, 50 deletions
diff --git a/src/trinityrealm/Main.cpp b/src/trinityrealm/Main.cpp
index ebd232c465c..f926aebf616 100644
--- a/src/trinityrealm/Main.cpp
+++ b/src/trinityrealm/Main.cpp
@@ -29,11 +29,13 @@
#include "Log.h"
#include "SystemConfig.h"
#include "Util.h"
+#include "SignalHandler.h"
#include "RealmList.h"
#include "RealmAcceptor.h"
#include <ace/Dev_Poll_Reactor.h>
#include <ace/ACE.h>
+#include <ace/Sig_Handler.h>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
@@ -57,13 +59,33 @@ int m_ServiceStatus = -1;
#endif
bool StartDB();
-void UnhookSignals();
-void HookSignals();
bool stopEvent = false; ///< Setting it to true stops the server
DatabaseType LoginDatabase; ///< Accessor to the realm server database
+/// Handle realmd's termination signals
+class RealmdSignalHandler : public Trinity::SignalHandler
+{
+ public:
+ virtual void HandleSignal(int SigNum)
+ {
+ switch (SigNum)
+ {
+ case SIGINT:
+ case SIGTERM:
+ stopEvent = true;
+ break;
+ #ifdef _WIN32
+ case SIGBREAK:
+ if (m_ServiceStatus != 1)
+ stopEvent = true;
+ break;
+ #endif /* _WIN32 */
+ }
+ }
+};
+
/// Print out the usage string for this program on the console.
void usage(const char *prog)
{
@@ -214,8 +236,19 @@ extern int main(int argc, char **argv)
return 1;
}
- ///- Catch termination signals
- HookSignals();
+ // Initialise the signal handlers
+ RealmdSignalHandler SignalINT, SignalTERM;
+ #ifdef _WIN32
+ RealmdSignalHandler SignalBREAK;
+ #endif /* _WIN32 */
+
+ // Register realmd's signal handlers
+ ACE_Sig_Handler Handler;
+ Handler.register_handler(SIGINT, &SignalINT);
+ Handler.register_handler(SIGTERM, &SignalTERM);
+ #ifdef _WIN32
+ Handler.register_handler(SIGBREAK, &SignalBREAK);
+ #endif /* _WIN32 */();
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
@@ -303,34 +336,10 @@ extern int main(int argc, char **argv)
LoginDatabase.ThreadEnd();
LoginDatabase.HaltDelayThread();
- ///- Remove signal handling before leaving
- UnhookSignals();
-
sLog.outString("Halting process...");
return 0;
}
-/// Handle termination signals
-/** Put the global variable stopEvent to 'true' if a termination signal is caught **/
-void OnSignal(int s)
-{
- switch (s)
- {
- case SIGINT:
- case SIGTERM:
- stopEvent = true;
- break;
- #ifdef _WIN32
- case SIGBREAK:
- if (m_ServiceStatus != 1)
- stopEvent = true;
- break;
- #endif
- }
-
- signal(s, OnSignal);
-}
-
/// Initialize connection to the database
bool StartDB()
{
@@ -351,26 +360,4 @@ bool StartDB()
return true;
}
-/// Define hook 'OnSignal' for all termination signals
-void HookSignals()
-{
- signal(SIGINT, OnSignal);
- signal(SIGTERM, OnSignal);
- #ifdef _WIN32
- if (m_ServiceStatus != 1)
- signal(SIGBREAK, OnSignal);
- #endif
-}
-
-/// Unhook the signals before leaving
-void UnhookSignals()
-{
- signal(SIGINT, 0);
- signal(SIGTERM, 0);
- #ifdef _WIN32
- if (m_ServiceStatus != 1)
- signal(SIGBREAK, 0);
- #endif
-}
-
/// @}