Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Logger / simple-server / server_loggerd.cpp
blobbb0cc3ec6f7ccc4f649754b14aed7a97ff480177
1 // This server daemon collects, formats, and displays logging
2 // information forwarded from client daemons running on other hosts in
3 // the network.
4 //
5 // In addition, it also illustrates how the ACE_Reactor framework is
6 // used.
8 #include "ace/Get_Opt.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/Signal.h"
12 #include "Logging_Acceptor.h"
13 #include "Reactor_Singleton.h"
15 static sig_atomic_t finished = 0;
17 extern "C" void
18 handler (int)
20 finished = 1;
23 // It doesn't get anymore const than this....
24 static const u_short PORT = ACE_DEFAULT_SERVER_PORT;
26 int
27 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
29 // Register a signal handler.
30 ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
31 ACE_UNUSED_ARG (sa);
33 Logging_Acceptor *peer_acceptor;
34 ACE_NEW_RETURN (peer_acceptor,
35 Logging_Acceptor,
36 1);
38 ACE_INET_Addr addr (PORT);
40 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"));
42 for (int c; (c = get_opt ()) != -1; )
43 switch (c)
45 case 'p':
46 addr.set (ACE_OS::atoi (get_opt.opt_arg ()));
47 break;
48 default:
49 break;
52 if (peer_acceptor->open (addr) == -1)
53 ACE_ERROR_RETURN ((LM_ERROR,
54 ACE_TEXT ("%p\n"),
55 ACE_TEXT ("open")),
56 -1);
57 else if (REACTOR::instance ()->register_handler (peer_acceptor,
58 ACE_Event_Handler::ACCEPT_MASK) == -1)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 ACE_TEXT ("registering service with ACE_Reactor\n")),
61 -1);
63 // Run forever, performing the logging service.
65 ACE_DEBUG ((LM_DEBUG,
66 ACE_TEXT ("(%P|%t) starting up server logging daemon\n")));
68 while (!finished)
69 REACTOR::instance ()->handle_events ();
71 ACE_DEBUG ((LM_DEBUG,
72 ACE_TEXT ("(%P|%t) shutting down server logging daemon\n")));
73 return 0;
76 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, ACE_Reactor, ACE_Null_Mutex);