2 //=============================================================================
4 * @file Reactor_Registration_Test.cpp
6 * This is a test of registering handlers with the Reactor.
8 * @author Irfan Pyarali <irfan@oomworks.com>
10 //=============================================================================
12 #include "test_config.h"
14 #include "ace/Reactor.h"
15 #include "ace/Select_Reactor.h"
16 #include "ace/TP_Reactor.h"
17 #include "ace/WFMO_Reactor.h"
20 static const char message
[] = "abcdefghijklmnopqrstuvwxyz";
21 static const size_t message_size
= 26;
22 static int iteration
= 1;
24 class Event_Handler
: public ACE_Event_Handler
28 Event_Handler (ACE_Reactor
&reactor
,
32 ~Event_Handler (void);
34 int handle_input (ACE_HANDLE fd
= ACE_INVALID_HANDLE
);
36 int handle_close (ACE_HANDLE handle
,
37 ACE_Reactor_Mask close_mask
);
43 Event_Handler::Event_Handler (ACE_Reactor
&reactor
,
46 : ACE_Event_Handler (&reactor
),
50 if (read
== ACE_INVALID_HANDLE
)
52 if (0 != this->pipe_
.open ())
56 ACE_TEXT ("Event_Handler pipe")));
61 if (0 != this->reactor ()->register_handler (this->pipe_
.read_handle (),
63 ACE_Event_Handler::READ_MASK
))
67 ACE_TEXT ("Event_Handler register_handler")));
71 ssize_t result
= ACE::send_n (this->pipe_
.write_handle (),
74 if (result
!= ssize_t (message_size
))
77 ACE_TEXT ("Event_Handler sent %b bytes; should be %B\n"),
78 result
, message_size
));
84 ACE_TEXT ("Event_Handler::Event_Handler for %@\n"),
89 Event_Handler::~Event_Handler (void)
92 ACE_TEXT ("Event_Handler::~Event_Handler for %@\n"),
97 Event_Handler::handle_input (ACE_HANDLE handle
)
99 char buf
[message_size
+ 1];
105 if (result
!= static_cast<ssize_t
> (message_size
))
106 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Handler recv'd %b bytes; expected %B\n"),
107 result
, message_size
));
108 buf
[result
> 0 ? result
: 0] = '\0';
110 ACE_DEBUG ((LM_DEBUG
,
111 ACE_TEXT ("Message %C received for %@\n"),
119 Event_Handler::handle_close (ACE_HANDLE
,
125 new Event_Handler (*this->reactor (),
130 new Event_Handler (*this->reactor (),
131 this->pipe_
.read_handle (),
132 this->pipe_
.write_handle ());
135 this->reactor ()->end_reactor_event_loop ();
146 test (ACE_Reactor_Impl
&reactor_impl
,
147 const char *reactor_type
)
149 ACE_DEBUG ((LM_DEBUG
,
150 ACE_TEXT ("\nTesting with %C\n\n"),
153 ACE_Reactor
reactor (&reactor_impl
,
156 Event_Handler
*e
= new Event_Handler (reactor
,
161 ACE_ERROR ((LM_ERROR
,
162 ACE_TEXT ("Error initializing test; aborting.\n")));
167 reactor
.run_reactor_event_loop ();
171 run_main (int, ACE_TCHAR
*[])
173 ACE_START_TEST (ACE_TEXT ("Reactor_Registration_Test"));
176 ACE_Select_Reactor select_reactor
;
177 test (select_reactor
, "ACE_Select_Reactor");
180 ACE_TP_Reactor tp_reactor
;
181 test (tp_reactor
, "ACE_TP_Reactor");
183 // The ACE_WFMO_Reactor stuff needs Winsock2
184 #if defined (ACE_WIN32) && \
185 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
187 ACE_WFMO_Reactor wfmo_reactor
;
188 test (wfmo_reactor
, "ACE_WFMO_Reactor");
189 #endif /* ACE_WIN32 && ACE_HAS_WINSOCK2 */