Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Signals / SigHandlers.cpp
blob4142cc62216a3ebd918e0d0271fb0f6c83626ba7
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/Signal.h"
4 #include "ace/Sig_Handler.h"
6 class MySignalHandler : public ACE_Event_Handler
8 public:
9 MySignalHandler (int signum) : signum_(signum)
10 { }
12 virtual ~MySignalHandler ()
13 { }
15 virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0)
17 ACE_TRACE ("MySignalHandler::handle_signal");
19 // Make sure the right handler was called back..
20 ACE_ASSERT(signum == this->signum_);
22 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d occurred\n"), signum));
24 return 0;
27 private:
28 int signum_;
31 // Listing 1 code/ch11
32 int ACE_TMAIN (int, ACE_TCHAR *[])
34 MySignalHandler h1 (SIGUSR1), h2 (SIGUSR1);
35 ACE_Sig_Handlers handler;
36 handler.register_handler (SIGUSR1, &h1);
37 handler.register_handler (SIGUSR1, &h2);
39 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1);
41 int time = 10;
42 while ((time = ACE_OS::sleep (time)) == -1)
44 if (errno == EINTR)
45 continue;
46 else
47 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
48 ACE_TEXT ("sleep")), -1);
50 return 0;
52 // Listing 1