[7270] Apply mangos code style.

This commit is contained in:
VladimirMangos 2009-02-12 15:03:44 +03:00
parent 7c67848b48
commit 671a942d14
2 changed files with 67 additions and 65 deletions

View file

@ -116,72 +116,74 @@ public:
class RARunnable : public ZThread::Runnable class RARunnable : public ZThread::Runnable
{ {
public: public:
uint32 numLoops, loopCounter; uint32 numLoops, loopCounter;
RARunnable () RARunnable ()
{ {
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME); uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
numLoops = (sConfig.GetIntDefault ("MaxPingTime", 30) * (MINUTE * 1000000 / socketSelecttime)); numLoops = (sConfig.GetIntDefault ("MaxPingTime", 30) * (MINUTE * 1000000 / socketSelecttime));
loopCounter = 0;
}
void
checkping ()
{
// ping if need
if ((++loopCounter) == numLoops)
{
loopCounter = 0; loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive"); }
delete WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
delete loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
void void checkping ()
run (void) {
{ // ping if need
SocketHandler h; if ((++loopCounter) == numLoops)
{
loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive");
delete WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
delete loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
// Launch the RA listener socket void run ()
ListenSocket<RASocket> RAListenSocket (h); {
bool usera = sConfig.GetBoolDefault ("Ra.Enable", false); SocketHandler h;
if (usera) // Launch the RA listener socket
{ ListenSocket<RASocket> RAListenSocket (h);
port_t raport = sConfig.GetIntDefault ("Ra.Port", 3443); bool usera = sConfig.GetBoolDefault ("Ra.Enable", false);
std::string stringip = sConfig.GetStringDefault ("Ra.IP", "0.0.0.0");
ipaddr_t raip; if (usera)
if (!Utility::u2ip (stringip, raip)) {
sLog.outError ("MaNGOS RA can not bind to ip %s", stringip.c_str ()); port_t raport = sConfig.GetIntDefault ("Ra.Port", 3443);
else if (RAListenSocket.Bind (raip, raport)) std::string stringip = sConfig.GetStringDefault ("Ra.IP", "0.0.0.0");
sLog.outError ("MaNGOS RA can not bind to port %d on %s", raport, stringip.c_str ()); ipaddr_t raip;
if (!Utility::u2ip (stringip, raip))
sLog.outError ("MaNGOS RA can not bind to ip %s", stringip.c_str ());
else if (RAListenSocket.Bind (raip, raport))
sLog.outError ("MaNGOS RA can not bind to port %d on %s", raport, stringip.c_str ());
else
{
h.Add (&RAListenSocket);
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
}
// Socket Selet time is in microseconds , not miliseconds!!
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
// if use ra spend time waiting for io, if not use ra ,just sleep
if (usera)
{
while (!World::IsStopped())
{
h.Select (0, socketSelecttime);
checkping ();
}
}
else else
{
h.Add (&RAListenSocket);
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
}
// Socket Selet time is in microseconds , not miliseconds!!
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
// if use ra spend time waiting for io, if not use ra ,just sleep
if (usera)
while (!World::IsStopped())
{ {
h.Select (0, socketSelecttime); while (!World::IsStopped())
checkping (); {
ZThread::Thread::sleep (static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
}
} }
else }
while (!World::IsStopped())
{
ZThread::Thread::sleep (static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
}
}
}; };
Master::Master() Master::Master()
@ -302,14 +304,14 @@ int Master::Run()
} }
///- Launch the world listener socket ///- Launch the world listener socket
port_t wsport = sWorld.getConfig (CONFIG_PORT_WORLD); port_t wsport = sWorld.getConfig (CONFIG_PORT_WORLD);
std::string bind_ip = sConfig.GetStringDefault ("BindIP", "0.0.0.0"); std::string bind_ip = sConfig.GetStringDefault ("BindIP", "0.0.0.0");
if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1) if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1)
{ {
sLog.outError ("Failed to start network"); sLog.outError ("Failed to start network");
World::StopNow(ERROR_EXIT_CODE); World::StopNow(ERROR_EXIT_CODE);
// go down and shutdown the server // go down and shutdown the server
} }
sWorldSocketMgr->Wait (); sWorldSocketMgr->Wait ();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7269" #define REVISION_NR "7270"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__