OregonCore  revision fb2a440-git
Your Favourite TBC server
RARunnable.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "Config/Config.h"
20 #include "Log.h"
21 #include "RARunnable.h"
22 #include "World.h"
23 
24 #include <ace/Reactor_Impl.h>
25 #include <ace/TP_Reactor.h>
26 #include <ace/Dev_Poll_Reactor.h>
27 #include <ace/Acceptor.h>
28 #include <ace/SOCK_Acceptor.h>
29 
30 #include "RASocket.h"
31 
32 RARunnable::RARunnable() : m_Reactor(NULL)
33 {
34  ACE_Reactor_Impl* imp = 0;
35 
36  #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
37 
38  imp = new ACE_Dev_Poll_Reactor();
39 
40  imp->max_notify_iterations (128);
41  imp->restart (1);
42 
43  #else
44 
45  imp = new ACE_TP_Reactor();
46  imp->max_notify_iterations (128);
47 
48  #endif
49 
50  m_Reactor = new ACE_Reactor (imp, 1);
51 }
52 
54 {
55  delete m_Reactor;
56 }
57 
59 {
60  if (!sConfig.GetBoolDefault("Ra.Enable", false))
61  return;
62 
63  ACE_Acceptor<RASocket, ACE_SOCK_ACCEPTOR> acceptor;
64 
65  uint16 raport = sConfig.GetIntDefault("Ra.Port", 3443);
66  std::string stringip = sConfig.GetStringDefault("Ra.IP", "0.0.0.0");
67 
68  ACE_INET_Addr listen_addr(raport, stringip.c_str());
69 
70  if (acceptor.open(listen_addr, m_Reactor) == -1)
71  {
72  sLog.outError("Oregon RA can not bind to port %d on %s", raport, stringip.c_str());
73  return;
74  }
75 
76  sLog.outString("Starting Oregon RA on port %d on %s", raport, stringip.c_str());
77 
78  while (!World::IsStopped())
79  {
80  // don't be too smart to move this outside the loop
81  // the run_reactor_event_loop will modify interval
82  ACE_Time_Value interval(0, 100000);
83 
84  if (m_Reactor->run_reactor_event_loop(interval) == -1)
85  break;
86  }
87 
88  sLog.outString("Oregon RA thread exiting");
89 }
void run()
Definition: RARunnable.cpp:58
#define sConfig
Definition: Config.h:52
virtual ~RARunnable()
Definition: RARunnable.cpp:53
#define sLog
Log class singleton.
Definition: Log.h:187
static bool IsStopped()
Definition: World.h:638
ACE_Reactor * m_Reactor
Definition: RARunnable.h:33
ACE_UINT16 uint16
Definition: Define.h:72