|
楼主 |
发表于 2007-12-22 21:42:00
|
显示全部楼层
补上完整的测试代码,VC2005/xp下通过- /**
- test.cpp
- Stone jiang
- */
- #include "ace/OS_NS_time.h"
- #include "ace/Log_Msg.h"
- #include "ace/Reactor.h"
- #include "ace/Event_Handler.h"
- #include "ace/Task.h"
- #include "ace/Thread_Manager.h"
- #include "ace/TP_Reactor.h"
- #include "ace/WFMO_Reactor.h"
- class MyTimerHandler : public ACE_Event_Handler
- {
- public:
- int handle_timeout (const ACE_Time_Value ¤t_time,
- const void * = 0)
- {
- time_t epoch = ((timespec_t)current_time).tv_sec;
- ACE_DEBUG ((LM_INFO,
- ACE_TEXT ("(%t) handle_timeout: %s\n"),
- ACE_OS::ctime (&epoch)));
- return 0;
- }
- };
- class SigintHandler : public ACE_Event_Handler
- {
- public:
- int handle_signal (int signum, siginfo_t * = 0,
- ucontext_t * = 0)
- {
- if (signum == SIGINT)
- {
- ACE_Reactor::instance ()->end_reactor_event_loop ();
- }
- return 0;
- }
- };
- class ReactorThread :public ACE_Task
- {
- public:
- ReactorThread(void* r)
- {
- reactor_ = (ACE_Reactor*) r;
- ACE_DEBUG ((LM_INFO,
- ACE_TEXT ("ReactorThread::ReactorThread()\n")));
- this->activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED,3);
- }
- virtual int svc()
- {
- ACE_DEBUG ((LM_INFO,
- ACE_TEXT (" (%t) ReactorThread::svc()\n")));
- reactor_->owner (ACE_OS::thr_self ());
- reactor_->run_reactor_event_loop();
- return 0;
- }
- private:
- ACE_Reactor* reactor_;
- };
- int ACE_TMAIN (int, ACE_TCHAR *[])
- {
-
- ACE_DEBUG ((LM_INFO,
- ACE_TEXT ("(%t) main::start \n")));
- ACE_WFMO_Reactor this_reactor;
- ACE_Reactor reactor (&this_reactor);
- auto_ptr delete_instance
- (ACE_Reactor::instance (&reactor));
- ReactorThread thread(ACE_Reactor::instance());
- MyTimerHandler * timer = new MyTimerHandler ();
- ACE_Time_Value initialDelay (1);
- ACE_Time_Value interval (2);
- ACE_Reactor::instance()->schedule_timer (timer,
- 0,
- initialDelay,
- interval);
-
- SigintHandler * handleExit = new SigintHandler ();
- ACE_Reactor::instance()->register_handler (SIGINT,
- handleExit);
- thread.wait();
- ACE_DEBUG ((LM_INFO,
- ACE_TEXT ("main::exit \n")));
- return 0;
- }
复制代码 |
|