|
楼主 |
发表于 2007-12-17 23:09:49
|
显示全部楼层
只开了一个线程- UINT ThreadReactor(LPVOID param)
- {
- ACE_INET_Addr port_listen(1515);
- ClientAcceptor ClientAcceptor;
- ClientAcceptor.reactor(ACE_Reactor::instance());
- if(ClientAcceptor.open(port_listen) == -1)
- return -1;
- int result = ACE_Reactor::instance()->run_reactor_event_loop();
- return result;
- }
- //启动线程
- void CAceTestDlg::OnButServer()
- {
- AfxBeginThread(ThreadReactor,NULL);
- }
- //这里停止
- void CAceTestDlg::OnButtonClose()
- {
- // TODO: Add your control notification handler code here
- ACE_Reactor::instance()->end_reactor_event_loop();
- }
- //这里析构,略:在initDialog 里 ACE::init()
- BOOL CAceTestDlg::DestroyWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- ACE_Reactor::instance()->owner(ACE_OS::thr_self());
- ACE::fini();
- return CDialog::DestroyWindow();
- }
- //Acceptor 的 handle_close
- int ClientAcceptor::handle_close(ACE_HANDLE handle,ACE_Reactor_Mask close_mask)
- {
- if( acceptor_.get_handle() != ACE_INVALID_HANDLE)
- {
- ACE_Reactor_Mask m = ACE_Event_Handler::ACCEPT_MASK|
- ACE_Event_Handler::DONT_CALL;
- reactor()->remove_handler(this,m);
- acceptor_.close();
- }
- return 0;
- }
- //ClientService的 handle_close
- int ClientService::handle_close(ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
- {
- if( ACE_Event_Handler::WRITE_MASK == close_mask)
- return 0;
- close_mask = ACE_Event_Handler::ALL_EVENTS_MASK|ACE_Event_Handler::DONT_CALL;
- reactor()->remove_handler(this,close_mask);
- sock_.close();
- output_queue_.flush();
- delete this;
- return 0;
- }
复制代码 注:
除了开个线程,其他均为抄书. |
|