summaryrefslogtreecommitdiff
path: root/docs/tutorials/022/server.cpp
blob: b9915be4122814db9b82a42eed8bf860d66be8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// $Id$

/* We try to keep the server much simpler than before and
   remove any thing related to the acceptor or the handler 
   from the main (). This lets keep the server running irrespective of
   the state of the acceptor service, in our case and any service in
   the general case. */

/* We would need the ACE_Service_Config class as it provides an
   application developers interface to the entire Service
   Configuration Framework */
#include "ace/Service_Config.h"

/* Since we are seperating the acceptor service class from the
   server, we need to declare our Acceptor_Service */
#include "Acceptor_Service.h"

#include "ace/Signal.h"

extern "C" void handler (int)
{
  ACE_Service_Config::reconfig_occurred (1);
}

int
main (int argc, char *argv[])
{
  /* Perform daemon services update ... this opens the svc.conf
     file and reads the entries present in the svc.conf
     file. We will later learn the syntax of making an entry
     into a svc.conf file. But for now, remember that this is a
     file which has the entries to load or unload a service
     dynamically or statically. */
  if (ACE_Service_Config::open (argc,
                                argv,
                                ACE_DEFAULT_LOGGER_KEY,
                                0) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "ACE_Service_Config::open"),
                      -1);
  
  /* Install our signal handler.  As we already know, you can actually
     register signal handlers with the reactor.  You might do that
     when the signal handler is responsible for performing "real"
     work.  Our simple flag-setter doesn't justify deriving from
     ACE_Event_Handler and providing a callback function though.  */
   ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGHUP);

   /* Start running the event loop so that it
      listens for events and acts accordingly. This event loop will run
      until either the event loop is ended explicitly or an error
      occurs. */
   ACE_Reactor::run_event_loop ();

  /* NOT REACHED */

}