|
楼主 |
发表于 2009-10-28 10:57:27
|
显示全部楼层
virtual void handle_write_stream
(const ACE_Asynch_Write_Stream::Result &result)
{
result.message_block ().reset();
if(fileflag)
asynch_read_file();
return;
}
void WriteDate(char *szSendBuf, int nSendCnt)
{
// ACE_Message_Block *smb = new ACE_Message_Block(nSendCnt+1);
// smb->copy(szSendBuf,nSendCnt+1);
msgblock_->copy(szSendBuf,nSendCnt+1);
msgblock_->copy("");
int nResult= this->writer_.write(*msgblock_,nSendCnt+1);
if ( nResult != 0)
{
CPserverDlg *dlg=(CPserverDlg*)AfxGetApp()->GetMainWnd();
ACE_OS::sleep(0);
ACE_TRACE("Write data failed!");
}
return ;
}
void asynch_read_file()
{
CPserverDlg *dlg = (CPserverDlg*)AfxGetApp()->GetMainWnd();
int size=8100;
if(sendFileLen>size)
{
char *membuf=new char[size+2];
sendFile.Read(membuf,size);
membuf[size] = '%';
membuf[size+1] = '\0';
sendFileLen = sendFileLen-size;
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);
}
delete []membuf;
membuf = NULL;
}
else
{
CHAR *membuf = new CHAR[sendFileLen+2];
sendFile.Read(membuf,sendFileLen);
sendFile.Close();
membuf[sendFileLen] = '^';
membuf[sendFileLen+1] = '\0';
fileflag=false;
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,sendFileLen+1);
}
delete []membuf;
membuf = NULL;
dlg->MessageBox((LPCTSTR)"文件已发送");
}
}
void CPserverDlg::OnFileSend()
{
// TODO: Add your control notification handler code here
fileflag=true;
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);
asynch_read_file();
} |
|