proactor 退出我出错的问题
客户端的连接和关闭程序UINT ThreadReactor(LPVOID param)
{
ACE_INET_Addr addr(3000,"192.168.6.10");
HA_Proactive_Service *client = new HA_Proactive_Service();
ACE_Asynch_Connector<HA_Proactive_Service> connector;
connector.open();
if (connector.connect(addr) == -1)
return -1;
CProactorClientDlg *dlg = (CProactorClientDlg*)AfxGetApp()->GetMainWnd();
dlg->MessageBox("已连接");
int result = ACE_Proactor::instance ()->proactor_run_event_loop ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Thread ended\n")));
return result;
}
void CProactorClientDlg::OnConnect()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ThreadReactor,NULL);
}
void CProactorClientDlg::OnStop()
{
// TODO: Add your control notification handler code here
ACE_Proactor::instance()->proactor_end_event_loop();
}
服务器端的析构函数
class HA_Proactive_Service : public ACE_Service_Handler
{
public:
~HA_Proactive_Service ()
{
if (this->handle () != ACE_INVALID_HANDLE)
{
this->reader_.cancel();
this->writer_.cancel();
ACE_OS::shutdown(this->handle_, ACE_SHUTDOWN_WRITE);
ACE_OS::closesocket (this->handle ());
this->handle (ACE_INVALID_HANDLE);
}
}
问题:客户端连接,断开。但是在关闭对话框的时候服务器端出现错误的提示。前几天还好好的,不知道为啥?
[ 本帖最后由 psycheqiqi 于 2009-10-12 10:39 编辑 ] 一般是线程同步问题导致,提供点更详细的资料,帖代码,帖错误信息。
回复 #2 winston 的帖子
class HA_Proactive_Service : public ACE_Service_Handler{
public:
~HA_Proactive_Service ()
{
if (this->handle () != ACE_INVALID_HANDLE)
{
this->reader_.cancel();
this->writer_.cancel();
ACE_OS::shutdown(this->handle_, ACE_SHUTDOWN_WRITE);
ACE_OS::closesocket (this->handle ());
this->handle (ACE_INVALID_HANDLE);
}
}
virtual void open (ACE_HANDLE h, ACE_Message_Block&)
{
_cur = this;
num++;
this->handle (h);
if (this->writer_.open (*this) != 0 ||this->reader_.open(*this) != 0)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("HA_Proactive_Service open")));
delete this;
return;
}
ACE_Message_Block *mb;
ACE_NEW_NORETURN(mb,ACE_Message_Block(1024));
if (this->reader_.read(*mb, mb->space ()) != 0)
{
ACE_OS::printf("Begin read fail\n");
mb->release();
delete this;
return;
}
}
下面就是读写的处理。。
private:
static HA_Proactive_Service *_cur;
ACE_Asynch_Read_Streamreader_;
ACE_Asynch_Write_Stream writer_;
};
HA_Proactive_Service *HA_Proactive_Service::_cur;
}
客户端和服务器的设置参考的http://www.acejoy.com/bbs/viewthread.php?tid=641&extra=page%3D6
错误的信息就是在关闭客户端的对话框时,服务器端弹出 “0x10053bea”指令引用的内存不能读的问题 我之前写的是没有出错,我又重新建了个工程,把代码拷了一遍。现在没错误
页:
[1]