|
楼主 |
发表于 2009-10-23 17:43:23
|
显示全部楼层
回复 #27 wishel 的帖子
我的WriteDate()不是在handle_write_stream()中调用的,而是单独定义的函数。异步的读是在对话框的OnFileSend()函数中调用的writeDate()
virtual void handle_write_stream
(const ACE_Asynch_Write_Stream::Result &result)
{
ACE_Message_Block &mb = result.message_block ();
mb.release();
count--;
return;
}
void WriteDate(char *szSendBuf, int nSendCnt)
{
ACE_Message_Block *smb = new ACE_Message_Block(nSendCnt+1);
count++;
smb->copy(szSendBuf,nSendCnt+1);
int nResult= this->writer_.write(*smb,nSendCnt+1);
if ( nResult != 0)
{
CPserverDlg *dlg=(CPserverDlg*)AfxGetApp()->GetMainWnd();
ACE_OS::sleep(0);
ACE_TRACE("Write data failed!");
}
return ;
}
void CPserverDlg::OnFileSend()
{
// TODO: Add your control notification handler code here
ACE_Time_Value delay;
delay.msec(1);
CString str;
sendFile.Abort();
sendFile.Open(sendFileName,CFile::modeRead | CFile::typeBinary);
sendFileLen = sendFile.GetLength();
CPserverDlg *dlg = (CPserverDlg*)AfxGetApp()->GetMainWnd();
str.Format("%d",sendFileLen);
dlg->MessageBox(str);
int size=8100;
while(sendFileLen>size)
{
char *membuf=new char[size+2] ;
sendFile.Read(membuf,size);
membuf[size] = '%';
membuf[size+1] = '\0';
list <HA_Proactive_Service *> ::iterator its;
for(its=HA_Proactive_Service::List.begin();its!=HA_Proactive_Service::List.end();its++)
{
HA_Proactive_Service *curSvr = *its;
curSvr->WriteDate( membuf,size+1);
}
sendFileLen = sendFileLen-size;
delete []membuf;
membuf = NULL;
}
CHAR *membuf = new CHAR[sendFileLen+2];
sendFile.Read(membuf,sendFileLen);
sendFile.Close();
membuf[sendFileLen] = '^';
membuf[sendFileLen+1] = '\0';
list <HA_Proactive_Service *> ::iterator its;
for(its=HA_Proactive_Service::List.begin();its!=HA_Proactive_Service::List.end();its++)
{
HA_Proactive_Service *curSvr = *its;
curSvr->WriteDate(membuf,size+1);
}
dlg->MessageBox((LPCTSTR)"文件已发送");
delete []membuf;
membuf = NULL;
return 0;
}
[ 本帖最后由 psycheqiqi 于 2009-10-23 17:47 编辑 ] |
|