2 ** Copyright 2002 Addison Wesley. All Rights Reserved.
5 #include "ace/Event_Handler.h"
6 #include "ace/Reactor.h"
7 #include "ace/Service_Object.h"
8 #include "ace/Thread_Manager.h"
9 #include "ace/OS_NS_string.h"
11 // FUZZ: disable check_for_streams_include
12 #include "ace/streams.h"
14 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
20 #include "SLDEX_export.h"
23 class Quit_Handler
: public ACE_Event_Handler
{
25 Quit_Handler (ACE_Reactor
*r
) : ACE_Event_Handler (r
) {}
27 virtual int handle_exception (ACE_HANDLE
) {
28 reactor ()->end_reactor_event_loop ();
29 return -1; // Trigger call to handle_close() method.
32 virtual int handle_close (ACE_HANDLE
, ACE_Reactor_Mask
)
33 { delete this; return 0; }
36 // Protected destructor ensures dynamic allocation.
37 virtual ~Quit_Handler () {}
41 static ACE_THR_FUNC_RETURN
controller (void *arg
) {
42 ACE_Reactor
*reactor
= static_cast<ACE_Reactor
*> (arg
);
44 Quit_Handler
*quit_handler
= 0;
45 ACE_NEW_RETURN (quit_handler
, Quit_Handler (reactor
), 0);
47 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
50 ACE_OS::fgets (user_input
, sizeof (user_input
), stdin
);
51 if (ACE_OS::strcmp (user_input
, "quit") == 0) {
52 reactor
->notify (quit_handler
);
58 std::string user_input
;
59 std::getline (cin
, user_input
, '\n');
60 if (user_input
== "quit") {
61 reactor
->notify (quit_handler
);
71 class Server_Shutdown
: public ACE_Service_Object
{
73 virtual int init (int, ACE_TCHAR
*[]) {
74 reactor_
= ACE_Reactor::instance ();
75 return ACE_Thread_Manager::instance ()->spawn
76 (controller
, reactor_
, THR_DETACHED
);
80 Quit_Handler
*quit_handler
= 0;
81 ACE_NEW_RETURN (quit_handler
,
82 Quit_Handler (reactor_
), -1);
83 return reactor_
->notify (quit_handler
);
87 ACE_Reactor
*reactor_
;
90 ACE_FACTORY_DEFINE (SLDEX
, Server_Shutdown
)