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
27 Event_Handler (ACE_Reactor
&reactor
,
31 ~Event_Handler () override
;
33 int handle_input (ACE_HANDLE fd
= ACE_INVALID_HANDLE
) override
;
35 int handle_close (ACE_HANDLE handle
,
36 ACE_Reactor_Mask close_mask
) override
;
42 Event_Handler::Event_Handler (ACE_Reactor
&reactor
,
45 : ACE_Event_Handler (&reactor
),
49 if (read
== ACE_INVALID_HANDLE
)
51 if (0 != this->pipe_
.open ())
55 ACE_TEXT ("Event_Handler pipe")));
60 if (0 != this->reactor ()->register_handler (this->pipe_
.read_handle (),
62 ACE_Event_Handler::READ_MASK
))
66 ACE_TEXT ("Event_Handler register_handler")));
70 ssize_t result
= ACE::send_n (this->pipe_
.write_handle (),
73 if (result
!= ssize_t (message_size
))
76 ACE_TEXT ("Event_Handler sent %b bytes; should be %B\n"),
77 result
, message_size
));
83 ACE_TEXT ("Event_Handler::Event_Handler for %@\n"),
88 Event_Handler::~Event_Handler ()
91 ACE_TEXT ("Event_Handler::~Event_Handler for %@\n"),
96 Event_Handler::handle_input (ACE_HANDLE handle
)
98 char buf
[message_size
+ 1];
104 if (result
!= static_cast<ssize_t
> (message_size
))
105 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Handler recv'd %b bytes; expected %B\n"),
106 result
, message_size
));
107 buf
[result
> 0 ? result
: 0] = '\0';
109 ACE_DEBUG ((LM_DEBUG
,
110 ACE_TEXT ("Message %C received for %@\n"),
118 Event_Handler::handle_close (ACE_HANDLE
,
124 new Event_Handler (*this->reactor (),
129 new Event_Handler (*this->reactor (),
130 this->pipe_
.read_handle (),
131 this->pipe_
.write_handle ());
134 this->reactor ()->end_reactor_event_loop ();
145 test (ACE_Reactor_Impl
&reactor_impl
,
146 const char *reactor_type
)
148 ACE_DEBUG ((LM_DEBUG
,
149 ACE_TEXT ("\nTesting with %C\n\n"),
152 ACE_Reactor
reactor (&reactor_impl
,
155 Event_Handler
*e
= new Event_Handler (reactor
,
160 ACE_ERROR ((LM_ERROR
,
161 ACE_TEXT ("Error initializing test; aborting.\n")));
166 reactor
.run_reactor_event_loop ();
170 run_main (int, ACE_TCHAR
*[])
172 ACE_START_TEST (ACE_TEXT ("Reactor_Registration_Test"));
175 ACE_Select_Reactor select_reactor
;
176 test (select_reactor
, "ACE_Select_Reactor");
179 ACE_TP_Reactor tp_reactor
;
180 test (tp_reactor
, "ACE_TP_Reactor");
182 // The ACE_WFMO_Reactor stuff needs Winsock2
183 #if defined (ACE_WIN32) && \
184 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
186 ACE_WFMO_Reactor wfmo_reactor
;
187 test (wfmo_reactor
, "ACE_WFMO_Reactor");
188 #endif /* ACE_WIN32 && ACE_HAS_WINSOCK2 */