|
以下是一个测试ACE REACTOR的程序:
-
- #include "ace/Event_Handler.h"
- #include "ace/Reactor.h"
-
- #include <signal.h>
-
- #include <iostream>
-
- using namespace std ;
-
- class QuitHandler : public ACE_Event_Handler
- {
- public:
- QuitHandler( ACE_Reactor * r ) : ACE_Event_Handler( r )
- {
- }
-
- int open( void )
- {
- return this->reactor()->register_handler(this, ACE_Event_Handler::EXCEPT_MASK);
- }
-
- int handle_exception( ACE_HANDLE )
- {
- cout << "reactor()->end_reactor_event_loop()" << endl ;
- reactor()->end_reactor_event_loop() ;
- return -1 ;
-
- }
-
- int handle_close( ACE_HANDLE, ACE_Reactor_Mask )
- {
- cout << "delete this in QuitHandler::handle_close()" << endl ;
- delete this ;
- return 0 ;
- }
-
- } ;
-
- class MyEvent_Handler : public ACE_Event_Handler
- {
- public:
- MyEvent_Handler( ACE_Reactor *r ) : ACE_Event_Handler( r )
- {
- }
-
- int open( void )
- {
- return this->reactor()->register_handler(this, ACE_Event_Handler::SIGNAL_MASK);
- }
-
- int handle_signal( int signum )
- {
- cout << "catch a signal" << endl ;
-
- if( signum == SIGUSR1 || signum == SIGUSR2 )
- {
- ACE_Reactor *r = ACE_Reactor::instance() ;
- QuitHandler *qhandler = new QuitHandler( r ) ;
- qhandler->open() ;
-
- r->notify( qhandler ) ;
- }
-
- return -1 ;
- }
-
- int handle_close( ACE_HANDLE, ACE_Reactor_Mask )
- {
- delete this ;
- return 0 ;
- }
- } ;
-
-
-
- int main()
- {
- cout << SIGUSR1 << " " << SIGUSR2 << endl ;
-
- MyEvent_Handler myhandler( ACE_Reactor::instance() ) ;
- myhandler.open() ;
-
- ACE_Reactor::instance()->run_reactor_event_loop() ;
-
- return 0 ;
- }
复制代码
问题是,当我在命令行 发SIGUSR1 或 SIGUSR2信号给该程序时,程序并没有检测到信号发生,因而没有调用
handle_signale HOOK METHOD。但是我已经在REACTOR上注册了的,不知道什么原因。请各位帮我看看,谢谢!
[ 本帖最后由 peakzhang 于 2007-12-11 22:19 编辑 ] |
|