summaryrefslogtreecommitdiff
path: root/ACE/tests/Bug_2368_Regression_Test.cpp
blob: f3afd21436243f3135aa1790e7f3cecca41fe1fb (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * @file Bug_2368_Regression_Test.cpp
 *
 * Reproduces the problems reported in bug 2368:
 *   http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=2368
 *
 * @author Johnny Willemsen  <jwillemsen@remedy.nl>
 */

#include "test_config.h"
#include "ace/Service_Config.h"
#include "ace/Reactor.h"
#include "ace/Log_Msg.h"
#include "ace/Signal.h"

static bool handleA_close_called = false;
static bool handleB_close_called = false;

class My_HandlerA : public ACE_Event_Handler
{
public:
  int handle_close (ACE_HANDLE, ACE_Reactor_Mask) override
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle close called\n"));
    handleA_close_called = true;

    return 0;
  }

  int handle_signal (int, siginfo_t *, ucontext_t *) override
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle signal called\n"));

    return 0;
  }
};

class My_HandlerB : public ACE_Event_Handler
{
public:
  int handle_close (ACE_HANDLE, ACE_Reactor_Mask) override
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle close called\n"));
    handleB_close_called = true;

    return 0;
  }

  int handle_signal (int, siginfo_t *, ucontext_t *) override
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle signal called\n"));

    return 0;
  }
};

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_2368_Regression_Test"));

  My_HandlerA my_handlerA;
  My_HandlerB my_handlerB;

  // Set up an ACE signal handler.
  if (ACE_Reactor::instance ()->register_handler
      (SIGINT,
       &my_handlerA) == -1)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("register_handlerA")));

  if (ACE_Reactor::instance ()->register_handler
      (SIGTERM,
       &my_handlerB) == -1)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("register_handlerB")));

  ACE_Sig_Action *new_disp = 0;
  if (ACE_Reactor::instance ()->remove_handler
      (SIGINT,
       new_disp) == -1)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("remove_handlerB")));

  if (ACE_Reactor::instance ()->close () == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("close")));

  if (!handleA_close_called)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Handle close hasn't been called for A.\n")));

  if (!handleB_close_called)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Handle close hasn't been called for B.\n")));

  ACE_END_TEST;

  return 0;
}