3 //=============================================================================
5 * @file QtReactor_Test.cpp
7 * Simple test of QtReactor. Test is intended to verify if QtReactor
8 * correctly cooperates with Qt event loop in typical application. Test
9 * creates a number of timers which send datagrams. These datagrams are
10 * expected by datagram_handlers registered in reactor. Test asynchronously
11 * establishes also a number of loopback tcp connections using ACE_Acceptors
12 * and ACE_Connectors. Socket activities are handled asynchronously to ensure
13 * that reactor does not lose events in traffic transmission. Moreover, test
14 * registers and removes handlers frequently to cover register/remove_handler
15 * method of QtReactor which are known (10/07/2004) to be buggy.
18 * QTestApplication - main qt application running event loop for a
20 * Dgram_Handler - responsible for sending and receiving datagrams as
21 * well as handling timeouts. Datagrams are sent in
22 * handle_timeout method.
23 * TCPConnectionHandler - connection handler responsible for sending and
24 * receiving data using tcp streams.
25 * TCPAcceptorHandler - acceptor responsible for acceptance and
26 * registration of connections in HandlersRegister
28 * HandlersRegister - register of event_handlers, responsible also for
29 * the analysis of test results.
31 * @author Marek Brudka <mbrudka@elka.pw.edu.pl>
33 //=============================================================================
36 #include "test_config.h"
39 #include <QtCore/qtimer.h>
41 #include "ace/OS_NS_time.h"
42 #include "ace/Time_Value.h"
43 #include "ace/QtReactor/QtReactor.h"
44 #include "ace/Event_Handler.h"
45 #include "ace/Argv_Type_Converter.h"
46 #include "ace/Acceptor.h"
47 #include "ace/Connector.h"
48 #include "ace/SOCK_Acceptor.h"
49 #include "ace/SOCK_Connector.h"
50 #include "ace/SOCK_Dgram.h"
53 #include "QtReactor_Test.h"
56 QTestApplication class implementation
59 QTestApplication::QTestApplication (int argc
, char *argv
[]):
60 QApplication (argc
, argv
, FALSE
) /* do not enable GUI */
62 //FUZZ: disable check_for_lack_ACE_OS
63 connect (&finishTimer_
, SIGNAL (timeout ()), this, SLOT (finishTest ()));
64 //FUZZ: enable check_for_lack_ACE_OS
67 void QTestApplication::finishTest ()
72 void QTestApplication::exec (int msec
)
77 finishTimer_
.setSingleShot (TRUE
);
78 finishTimer_
.start (msec
);
84 // maximum time for testing QtReactor (msec)
85 const int TotalTestTime
= 8000;
87 // how many handlers for each event handler class should be started ?
89 const int HandlersNo
= 8 ;
90 #else /* __QNXNTO__ */
91 // it seems that Qt 3.1 for NTO 6.2 is compiled with rather small FD_SETSIZE
92 // Nevertheless, test works fine with native select reactor
93 const int HandlersNo
= 4;
95 // base port for sending datagrams
96 const u_short BaseDgramPort
= 5931;
98 // port for TCP connections
99 const u_short BaseTCPPort
= 5931;
101 // how many datagrams should be sent for a single handler
102 const int DgramsToSend
= 64;
104 // how many bytes to send vie TCP
105 const int TCPBytesToSend
= 1024;
107 // how many times to reply tcp recv
108 const int TCPClientPings
= 16;
110 // total number of bytes in TCP transmission
111 const int TCPTotalBytesToSend
= TCPClientPings
* TCPBytesToSend
;
115 \brief Simple event handler that receives and counts datagrams
116 as well as sends dgrams using timeouts.
118 class DgramHandler
: public ACE_Event_Handler
121 DgramHandler (ACE_Reactor
*p_reactor
= 0);
122 virtual ~DgramHandler ();
124 //FUZZ: disable check_for_lack_ACE_OS
125 int open (const ACE_INET_Addr
&local
,
126 int protocol_family
=ACE_PROTOCOL_FAMILY_INET
,
129 //FUZZ: enable check_for_lack_ACE_OS
131 virtual ACE_HANDLE
get_handle () const;
132 virtual int handle_input (ACE_HANDLE handle
);
133 virtual int handle_close (ACE_HANDLE handle
,ACE_Reactor_Mask close_mask
);
134 virtual int handle_timeout (const ACE_Time_Value
¤t_time
, const void *act
=0);
135 int dgramsSent () const;
136 int dgramsReceived () const;
137 int timeoutsTriggered () const;
138 int expectedTriggers () const;
139 void expectedTriggers (int);
141 int dgramsSent_
; //!< the number of sent datagrams
142 int dgramsReceived_
; //!< the number of received datagrams
143 int timeoutsTriggered_
;
144 int expectedTriggers_
;
145 ACE_SOCK_Dgram peer_
; //!< datagram socket we listen to
149 \class TCPConnectionHandler
150 \brief TCP stream handler for both sides of connection.
152 class TCPConnectionHandler
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_NULL_SYNCH
>
155 typedef ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_NULL_SYNCH
> inherited
;
157 TCPConnectionHandler (bool p_serverSide
= false);
158 virtual ~TCPConnectionHandler ();
160 virtual int handle_output (ACE_HANDLE handle
);
161 virtual int handle_input (ACE_HANDLE handle
);
162 virtual int handle_close (ACE_HANDLE handle
,ACE_Reactor_Mask close_mask
);
164 //FUZZ: disable check_for_lack_ACE_OS
165 ///FUZZ: enable check_for_lack_ACE_OS
166 virtual int open (void * = 0);
168 int scheduleSend (ACE_Message_Block
*);
170 int totalReceived () const;
171 int totalSent () const;
173 ACE_Message_Block
*buffers_
;
174 int totalReceived_
; //!< total number of received bytes
175 int totalSent_
; //!< total number of send bytes
176 bool serverSide_
; //!< if true, echo received data
177 int pingsNo_
; //!< number of pings client should make
180 typedef ACE_Connector
< TCPConnectionHandler
, ACE_SOCK_CONNECTOR
> TCPConnectorHandler
;
181 class TCPAcceptorHandler
; // forward declaration
183 /* \class HandlersRegister
184 \brief The collection of test tools. Here ACE classes bind to Qt application
186 class HandlersRegister
189 HandlersRegister (ACE_Reactor
*p_reactor
);
190 virtual ~HandlersRegister ();
191 int scheduleTimers (const ACE_Time_Value
&p_TestTime
); //!< schedule ace timers
192 int registerDgramHandlers (); //!< open dgrams socket and register in reactor
193 int registerTCPHandlers (); //!< creates TCP acceptors and connector
194 int analyze () const; //!< analyze results
195 int analyzeTimeouts () const; //!< analyze triggered timeouts
196 int analyzeDgrams () const; //!< analyze collected dgrams
197 int analyzeTCP () const; //!< analyze TCP transmission
198 int registerTCPServer (TCPConnectionHandler
*);
199 int TCPServersNo () const; //!< return the number of accepted connections
202 ACE_Reactor
*reactor_
; //!< reactor for this application
203 DgramHandler
*DgramHandlers_
[ HandlersNo
] ;//!< dgram input handlers
204 int TCPServersNo_
; //!< number of accepted connections
205 TCPConnectionHandler
*TCPServers_
[ HandlersNo
];
206 TCPConnectionHandler
*TCPClients_
[ HandlersNo
];
207 TCPAcceptorHandler
*acceptor_
;
208 TCPConnectorHandler
*connectors_
[ HandlersNo
];
211 class TCPAcceptorHandler
: public ACE_Acceptor
< TCPConnectionHandler
, ACE_SOCK_ACCEPTOR
>
214 typedef ACE_Acceptor
< TCPConnectionHandler
, ACE_SOCK_ACCEPTOR
> inherited
;
216 TCPAcceptorHandler (HandlersRegister
*p_handlersRegister
);
217 virtual ~TCPAcceptorHandler ();
218 virtual int make_svc_handler (TCPConnectionHandler
*& sh
);
219 virtual int activate_svc_handler (TCPConnectionHandler
* sh
);
221 HandlersRegister
*handlersRegister_
;
225 DgramHandler class implementation
228 DgramHandler::DgramHandler (ACE_Reactor
*p_reactor
):
229 ACE_Event_Handler (p_reactor
),
232 timeoutsTriggered_ (0),
233 expectedTriggers_ (0)
235 reference_counting_policy ().value (Reference_Counting_Policy::ENABLED
);
238 DgramHandler::~DgramHandler ()
240 ACE_TRACE ("DgramHandler::~DgramHandler");
243 int DgramHandler::open (const ACE_INET_Addr
&local
,
248 if (0 > peer_
.open (local
,
252 ACE_ERROR_RETURN ((LM_ERROR
,
253 ACE_TEXT (" (%P) %p\n"),
254 ACE_TEXT ("Cannot oper dgram socket")),
260 ACE_HANDLE
DgramHandler::get_handle () const
262 return peer_
.get_handle ();
265 int DgramHandler::handle_input (ACE_HANDLE
)
268 ACE_INET_Addr peerAddress
;
270 int result
= peer_
.recv (&recvBuffer
, sizeof (recvBuffer
) , peerAddress
);
273 ACE_ERROR_RETURN ((LM_ERROR
,
274 ACE_TEXT (" (%P) %p\n"),
275 ACE_TEXT ("While reading datagram from socket"))
283 int DgramHandler::handle_timeout (const ACE_Time_Value
¤t_time
, const void *act
)
285 ACE_UNUSED_ARG (current_time
);
286 ACE_UNUSED_ARG (act
);
289 if (++timeoutsTriggered_
>= expectedTriggers_
)
290 reactor ()->cancel_timer (this, 1);
292 ACE_SOCK_Dgram socket
;
293 if (-1 == socket
.open (ACE_INET_Addr (static_cast< u_short
> (0),
294 static_cast< ACE_UINT32
> (INADDR_ANY
)),
295 ACE_PROTOCOL_FAMILY_INET
, 0, 1))
296 ACE_ERROR ((LM_ERROR
,
297 ACE_TEXT (" (%P) %p\n"),
298 ACE_TEXT ("Cannot open socket for sending Qt dgrams")));
300 ACE_INET_Addr peerAddr
;
301 peer_
.get_local_addr (peerAddr
);
303 if (sizeof (sendBuffer
) != socket
.send (&sendBuffer
,
304 sizeof (sendBuffer
), peerAddr
))
305 ACE_ERROR ((LM_ERROR
,
306 ACE_TEXT (" (%P) %p\n"),
307 ACE_TEXT ("Cannot send dgram")));
316 int DgramHandler::handle_close (ACE_HANDLE handle
, ACE_Reactor_Mask close_mask
)
318 if (peer_
.get_handle () != handle
)
319 ACE_ERROR ((LM_ERROR
,
320 ACE_TEXT ("Unknown handle %d DgramHandler::handle_close "
321 "with mask %x. My handle is %d\n"),
324 peer_
.get_handle ()));
331 int DgramHandler::dgramsSent () const
336 int DgramHandler::dgramsReceived () const
338 return dgramsReceived_
;
341 int DgramHandler::timeoutsTriggered () const
343 return timeoutsTriggered_
;
346 void DgramHandler::expectedTriggers (int triggers
)
348 expectedTriggers_
= triggers
;
351 int DgramHandler::expectedTriggers () const
353 return expectedTriggers_
;
357 TCPConnectionHandler class implementation
360 TCPConnectionHandler::TCPConnectionHandler (bool p_serverSide
):
364 serverSide_ (p_serverSide
),
365 pingsNo_ (TCPClientPings
)
367 reference_counting_policy ().value (Reference_Counting_Policy::ENABLED
);
370 TCPConnectionHandler::~TCPConnectionHandler ()
372 ACE_TRACE ("TCPConnectionHandler::~TCPConnectionHandler");
375 int TCPConnectionHandler::handle_input (ACE_HANDLE handle
)
377 ACE_UNUSED_ARG (handle
);
378 ACE_Message_Block
*buffer
= new ACE_Message_Block (TCPBytesToSend
);
379 int bytesReceived
= peer_
.recv (buffer
->wr_ptr (), buffer
->space ());
381 if (bytesReceived
> 0)
383 totalReceived_
+= bytesReceived
;
384 if (serverSide_
|| --pingsNo_
> 0) // echo received buffer
386 buffer
->wr_ptr (bytesReceived
);
387 int result
= scheduleSend (buffer
);
389 ACE_ERROR_RETURN ((LM_ERROR
,
390 ACE_TEXT (" (%P) %p\n"),
391 ACE_TEXT ("Cannot schedule TCP reply")),
400 if (errno
!= EWOULDBLOCK
)
401 ACE_ERROR_RETURN ((LM_ERROR
,
402 ACE_TEXT (" (%P:%p (%d)\n"),
403 ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle
),
406 ACE_ERROR ((LM_WARNING
,
407 ACE_TEXT (" (%P:%p (%d)\n"),
408 ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle
));
413 int TCPConnectionHandler::handle_output (ACE_HANDLE handle
)
415 ACE_UNUSED_ARG (handle
);
417 ACE_ERROR ((LM_ERROR
,
418 ACE_TEXT ("TCPConnectionHandler::handle_output call for empty buffers (%d)\n"), handle
));
419 if (0 > sendBuffers ()) // socket broken, kill yourself
422 if (!buffers_
) // everything already send, unregister
424 reactor ()->cancel_wakeup (this,
425 ACE_Event_Handler::WRITE_MASK
| ACE_Event_Handler::DONT_CALL
);
426 reactor ()->remove_handler (this,
427 ACE_Event_Handler::WRITE_MASK
| ACE_Event_Handler::DONT_CALL
);
433 int TCPConnectionHandler::open (void * )
435 int result
= inherited::open ();
439 ACE_Message_Block
*buffer
= new ACE_Message_Block (TCPBytesToSend
);
440 char *bufferData
= buffer
->wr_ptr ();
443 for (i
= buffer
->size () - 1; i
>= 0; --i
)
444 bufferData
[ i
] = static_cast< char > (i
);
445 buffer
->wr_ptr (buffer
->size ());
446 if (0 != (scheduleSend (buffer
)))
447 ACE_ERROR_RETURN ((LM_ERROR
,
448 ACE_TEXT ("Cannot schedule initial send\n")),
455 int TCPConnectionHandler::scheduleSend (ACE_Message_Block
* buffer
)
457 // link buffer to the end of buffers list
460 ACE_Message_Block
*lastBuffer
= buffers_
;
461 while (lastBuffer
->cont ())
462 lastBuffer
= lastBuffer
->cont () ;
463 lastBuffer
->cont (buffer
);
468 if (0 > sendBuffers ())
469 ACE_ERROR_RETURN ((LM_ERROR
,
470 ACE_TEXT (" (%P) %p\n"),
471 ACE_TEXT ("Cannot schedule TCP send.")),
476 int TCPConnectionHandler::sendBuffers ()
481 if (0 < (result
= peer_
.send_n (buffers_
))) // remove sent blocks
483 totalSent_
+= result
;
485 static_cast< size_t > (result
) >= buffers_
->length ())
487 ACE_Message_Block
*buffer
= buffers_
;
488 result
-= buffers_
->length ();
489 buffers_
= buffers_
->cont ();
494 if (buffers_
) // some buffers were not sent, truncate data
495 buffers_
->rd_ptr (result
);
501 int TCPConnectionHandler::handle_close (ACE_HANDLE handle
,ACE_Reactor_Mask close_mask
)
503 if (peer_
.get_handle () != handle
)
504 ACE_ERROR ((LM_ERROR
,
505 ACE_TEXT ("Unknown handle %d TCPConnectionHandler::handle_close "
506 "with mask %x. My handle is %d\n"),
509 peer_
.get_handle ()));
516 int TCPConnectionHandler::totalReceived () const
518 return totalReceived_
;
521 int TCPConnectionHandler::totalSent () const
528 HandlersRegister class implementation
531 HandlersRegister::HandlersRegister (ACE_Reactor
*p_reactor
):
532 reactor_ (p_reactor
),
537 for (i
= 0; i
< HandlersNo
; ++i
)
539 // create dgram input handler
540 DgramHandlers_
[ i
] = new DgramHandler (p_reactor
);
542 TCPServers_
[ i
] = 0;
544 TCPClients_
[ i
] = new TCPConnectionHandler (false);
546 connectors_
[ i
] =new TCPConnectorHandler (p_reactor
, ACE_NONBLOCK
);
547 connectors_
[ i
]->reference_counting_policy ().value (
548 ACE_Event_Handler::Reference_Counting_Policy::ENABLED
) ;
551 acceptor_
= new TCPAcceptorHandler (this);
552 acceptor_
->reactor (p_reactor
);
555 HandlersRegister::~HandlersRegister ()
560 reactor_
->remove_handler (acceptor_
, ACE_Event_Handler::ALL_EVENTS_MASK
);
562 acceptor_
->remove_reference ();
565 for (i
= 0; i
< HandlersNo
; ++i
)
567 reactor_
->cancel_timer (DgramHandlers_
[ i
], 1);
568 reactor_
->remove_handler (DgramHandlers_
[ i
],
569 ACE_Event_Handler::ALL_EVENTS_MASK
);
570 DgramHandlers_
[ i
]->remove_reference ();
572 if (TCPServers_
[ i
])
574 reactor_
->remove_handler (TCPServers_
[ i
],
575 ACE_Event_Handler::ALL_EVENTS_MASK
);
576 TCPServers_
[ i
]->remove_reference ();
579 reactor_
->remove_handler (connectors_
[ i
],
580 ACE_Event_Handler::ALL_EVENTS_MASK
);
581 connectors_
[ i
]->close ();
582 connectors_
[ i
]->remove_reference ();
584 if (TCPClients_
[ i
])
586 reactor_
->remove_handler (TCPClients_
[ i
],
587 ACE_Event_Handler::ALL_EVENTS_MASK
);
588 TCPClients_
[ i
]->remove_reference ();
593 int HandlersRegister::TCPServersNo () const
595 return TCPServersNo_
;
598 int HandlersRegister::scheduleTimers (const ACE_Time_Value
&p_TestTime
)
602 for (i
= 0; i
< HandlersNo
; ++i
)
604 if (-1 == reactor_
->schedule_timer (DgramHandlers_
[ i
],
606 ACE_Time_Value::zero
,
607 p_TestTime
* (0.5 / DgramsToSend
)))
608 ACE_ERROR_RETURN ((LM_ERROR
,
609 ACE_TEXT (" (%P) %p\n"),
610 ACE_TEXT ("Cannot schedule ACE timer")),
613 DgramHandlers_
[ i
] ->expectedTriggers (DgramsToSend
);
619 int HandlersRegister::registerDgramHandlers ()
623 // open dgram handlers for all ports
624 for (i
= 0; i
< HandlersNo
; ++i
)
625 if (-1 == DgramHandlers_
[ i
]->open (
626 ACE_INET_Addr (i
+ BaseDgramPort
,
627 ACE_TEXT ("127.0.0.1"),
628 ACE_PROTOCOL_FAMILY_INET
)))
629 ACE_ERROR_RETURN ((LM_ERROR
,
630 ACE_TEXT (" (%P) %p\n"),
631 ACE_TEXT ("Cannot open dgram handler")),
634 // register dgram handlers
635 for (i
= 0; i
< HandlersNo
; ++i
)
636 if (-1 == reactor_
->register_handler (DgramHandlers_
[ i
],
637 ACE_Event_Handler::READ_MASK
))
638 ACE_ERROR_RETURN ((LM_ERROR
,
639 ACE_TEXT (" (%P) %p\n"),
640 ACE_TEXT ("Cannot register dgram handler")),
645 int HandlersRegister::registerTCPHandlers ()
647 ACE_INET_Addr
addr (BaseTCPPort
);
649 if (-1 == acceptor_
->open (addr
, reactor_
, 1))
650 ACE_ERROR_RETURN ((LM_ERROR
,
651 ACE_TEXT (" (%P) %p\n"),
652 ACE_TEXT ("Cannot open acceptor port")),
656 addr
.set (BaseTCPPort
, ACE_TEXT ("127.0.0.1"));
658 for (i
= 0; i
< HandlersNo
; ++i
)
660 if (-1 == connectors_
[ i
]->connect (
663 ACE_Synch_Options::asynch
))
664 if (errno
!= EWOULDBLOCK
)
665 ACE_ERROR_RETURN ((LM_ERROR
,
666 ACE_TEXT (" (%P) %p (%d)\n"),
667 ACE_TEXT ("Cannot connect connector"),
675 int HandlersRegister::registerTCPServer (TCPConnectionHandler
*handler
)
677 if (TCPServersNo_
< HandlersNo
)
679 TCPServers_
[ TCPServersNo_
++ ] = handler
;
682 ACE_ERROR ((LM_ERROR
,
683 ACE_TEXT ("Too many servers registered (%d). ACE_Reactor or ACE_Acceptor broken?\n"),
684 handler
->get_handle ()));
688 int HandlersRegister::analyze () const
692 if (0 > analyzeTimeouts ())
695 if (0 > analyzeDgrams ())
698 if (0 > analyzeTCP ())
704 int HandlersRegister::analyzeTimeouts () const
709 for (i
= 0; i
< HandlersNo
; ++i
)
710 if (DgramHandlers_
[ i
]->expectedTriggers () !=
711 DgramHandlers_
[ i
]->timeoutsTriggered ())
713 ACE_ERROR ((LM_ERROR
,
714 ACE_TEXT ("Dgram_Handlers (%d) expected %d timeouts"
715 " but triggered only %d.\n"),
717 DgramHandlers_
[ i
]->expectedTriggers (),
718 DgramHandlers_
[ i
]->timeoutsTriggered ()));
725 int HandlersRegister::analyzeDgrams () const
730 for (i
= 0; i
< HandlersNo
; ++i
)
731 if (DgramHandlers_
[ i
]->dgramsSent () !=
732 DgramHandlers_
[ i
]->dgramsReceived ())
734 ACE_ERROR ((LM_ERROR
,
735 ACE_TEXT ("DgramsHandler (%d) sent %d dgrams but received only %d."
736 "Either reactor failed or system lost local dgrams..\n"),
737 DgramHandlers_
[ i
]->dgramsSent (),
738 DgramHandlers_
[ i
]->dgramsReceived ()));
745 int HandlersRegister::analyzeTCP () const
750 for (i
= 0; i
< HandlersNo
; ++i
)
752 if (TCPClients_
[ i
]->totalSent () != TCPTotalBytesToSend
)
754 ACE_ERROR ((LM_ERROR
,
755 ACE_TEXT ("TCPClient (%d): wanted to send %d but sent only (%d).\n"),
758 TCPClients_
[ i
]->totalSent ()));
762 if (TCPClients_
[ i
]->totalReceived () != TCPTotalBytesToSend
)
764 ACE_ERROR ((LM_ERROR
,
765 ACE_TEXT ("TCPClient (%d): expected %d bytes but received only (%d).\n"),
768 TCPClients_
[ i
]->totalReceived ()));
772 if (TCPServers_
[ i
])
774 if (TCPServers_
[ i
]->totalSent () != TCPTotalBytesToSend
)
776 ACE_ERROR ((LM_ERROR
,
777 ACE_TEXT ("TCPServer (%d): wanted to send %d bytes "
778 "but sent only (%d).\n"),
781 TCPServers_
[ i
]->totalSent ()));
785 if (TCPServers_
[ i
]->totalReceived () != TCPTotalBytesToSend
)
787 ACE_ERROR ((LM_ERROR
,
788 ACE_TEXT ("TCPServer (%d): expected %d bytes but received only (%d).\n"),
791 TCPServers_
[ i
]->totalReceived ()));
798 ACE_ERROR ((LM_ERROR
,
799 ACE_TEXT ("TCPServer (%d): not connected.\n"),
810 TCPAcceptorHandler class implementation
813 TCPAcceptorHandler::TCPAcceptorHandler (HandlersRegister
*p_handlersRegister
):
814 handlersRegister_ (p_handlersRegister
)
816 reference_counting_policy ().value (Reference_Counting_Policy::ENABLED
);
819 int TCPAcceptorHandler::make_svc_handler (TCPConnectionHandler
*& sh
)
821 sh
= new TCPConnectionHandler (true);
822 sh
->reactor (reactor ());
823 if (handlersRegister_
->TCPServersNo () >= HandlersNo
)
824 ACE_ERROR ((LM_ERROR
,
825 ACE_TEXT ("TCPAcceptorHandler::make_svc_handler called to many times!\n")));
827 ACE_DEBUG ((LM_DEBUG
,
828 ACE_TEXT ("TCPAcceptorHandler::make_svc_handler new TCP server created\n")));
833 int TCPAcceptorHandler::activate_svc_handler (TCPConnectionHandler
* sh
)
835 if (0 == inherited::activate_svc_handler (sh
) )
837 if (0 != handlersRegister_
->registerTCPServer (sh
)) // for analysis
839 // release event handler
840 reactor ()->remove_handler (sh
, ACE_Event_Handler::ALL_EVENTS_MASK
);
841 sh
->remove_reference ();
843 ACE_ERROR_RETURN ((LM_ERROR
,
844 ACE_TEXT ("Cannot register server TCPConnectionHandler\n")),
850 ACE_ERROR_RETURN ((LM_ERROR
,
851 ACE_TEXT ("Failed to create server TCPConnectionHandler\n")),
857 TCPAcceptorHandler::~TCPAcceptorHandler ()
859 ACE_TRACE ("TCPAcceptorHandler::~TCPAcceptorHandler");
862 void testNativeReactor (int, ACE_TCHAR
*[])
864 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Testing autotest using native reactor\n")));
867 HandlersRegister
handlersRegister (&reactor
);
868 ACE_Time_Value
testTime (TotalTestTime
/ 1000, (TotalTestTime
% 1000) * 1000);
870 if (0 <= handlersRegister
.scheduleTimers (testTime
) &&
871 0 <= handlersRegister
.registerDgramHandlers () &&
872 0 <= handlersRegister
.registerTCPHandlers ())
874 reactor
.run_reactor_event_loop (testTime
);
876 if (0 != handlersRegister
.analyze ())
877 ACE_ERROR ((LM_ERROR
,
878 ACE_TEXT ("Test failed for native reactor. "
879 "Fix QtReactor_Test or ACE_Reactor.\n")));
881 ACE_ERROR ((LM_INFO
, ACE_TEXT ("Test seems to work with native reactor.\n")));
885 void testQtReactor (int argc
, ACE_TCHAR
*argv
[])
888 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Testing QtReactor\n")));
890 ACE_Argv_Type_Converter
ct (argc
, argv
);
891 QTestApplication
app (argc
, ct
.get_ASCII_argv ());
893 ACE_QtReactor
qtReactor (&app
);
894 ACE_Reactor
reactor (&qtReactor
);
895 HandlersRegister
handlersRegister (&reactor
);
896 ACE_Time_Value
testTime (TotalTestTime
/ 1000, (TotalTestTime
% 1000) * 1000);
898 if (0 <= handlersRegister
.scheduleTimers (testTime
) &&
899 0 <= handlersRegister
.registerDgramHandlers () &&
900 0 <= handlersRegister
.registerTCPHandlers ())
902 app
.exec (TotalTestTime
);
904 if (0 != handlersRegister
.analyze ())
905 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("QtReactor_Test failed.\n")));
907 ACE_ERROR ((LM_INFO
, ACE_TEXT ("QtReactor_Test passed.\n")));
912 run_main (int argc
, ACE_TCHAR
*argv
[])
914 ACE_START_TEST (ACE_TEXT ("QtReactor_Test"));
916 testNativeReactor (argc
, argv
);
917 testQtReactor (argc
, argv
);