|
本帖最后由 maddreamw88 于 2010-12-28 10:21 编辑
请问我在handle_exception 加了 打印信息,为什么运行时,标准输入quit , 打印信息出不来?我用ACE_OS::printf, printf, std::cerr等都试过,都没打印,不知什么原因,难道是我对notify理解有误, 发送消息后,不会回调handle_exception ,请高手解答,谢谢!
源码如下: 其实就是ace源代码包 ACE_wrappers/examples/C++NPv2、Select_Reactor_Logging_Server.cpp 代码
typedef Reactor_Logging_Server<Logging_Acceptor_Ex>
Server_Logging_Daemon;
class Quit_Handler : public ACE_Event_Handler {
public:
Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {}
virtual int handle_exception (ACE_HANDLE) {
ACE_OS::printf("hhhhhhhhhhhhhhhhhhhh\n");
reactor ()->end_reactor_event_loop ();
return -1; // Trigger call to handle_close() method.
}
virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)
{
delete this;
return 0;
}
protected:
// Protected destructor ensures dynamic allocation.
virtual ~Quit_Handler () {}
};
static ACE_THR_FUNC_RETURN event_loop (void *arg) {
ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);
reactor->owner (ACE_OS::thr_self ());
reactor->run_reactor_event_loop ();
return 0;
}
static ACE_THR_FUNC_RETURN controller (void *arg) {
ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);
Quit_Handler *quit_handler = 0;
ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0);
#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \
(ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \
defined (ACE_USES_OLD_IOSTREAMS))
for (;;) {
char user_input[80];
ACE_OS::fgets (user_input, sizeof (user_input), stdin);
if (ACE_OS::strcmp (user_input, "quit") == 0) {
reactor->notify (quit_handler);
break;
}
}
#else
for (;;) {
std::string user_input;
std::getline (cin, user_input, '\n');
if (user_input == "quit") {
reactor->notify (quit_handler);
break;
}
}
#endif
return 0;
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_Select_Reactor select_reactor;
ACE_Reactor reactor (&select_reactor);
Server_Logging_Daemon *server;
// Ignore argv[0]...
--argc; ++argv;
ACE_NEW_RETURN (server,
Server_Logging_Daemon (argc, argv, &reactor),
1);
ACE_Thread_Manager::instance ()->spawn (event_loop, &reactor);
ACE_Thread_Manager::instance ()->spawn (controller, &reactor);
return ACE_Thread_Manager::instance ()->wait ();
} |
|