|
楼主 |
发表于 2009-10-20 10:11:41
|
显示全部楼层
我的电脑内存2G的,
在发送的文件大小*连接数<<内存的情况下,发送都是很高效的。
是不是我的程序在发送时申请的内存没有释放?还是别的原因。
传100k的文件,几千的连接都没有问题。
大神们,来看下。
这是发送的函数
void CPserverDlg::OnFileSend()
{
// TODO: Add your control notification handler code here
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);
SYSTEMTIME time1;
GetSystemTime(&time1);
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,sendFileLen+1);
}
SYSTEMTIME time2;
GetSystemTime(&time2);
str.Format("文件已发送,耗时%d毫秒",time2.wMinute*60*1000+time2.wSecond*1000+time2.wMilliseconds
-(time1.wMinute*60*1000+time1.wSecond*1000+time1.wMilliseconds));
MessageBox(str);
delete []membuf;
membuf=null;
}
int WriteDate(char *szSendBuf, int nSendCnt)
{
ACE_Message_Block *smb = new ACE_Message_Block(nSendCnt+1);
smb->copy(szSendBuf,nSendCnt+1);
int nResult = this->writer_.write(*smb,nSendCnt+1);
if ( nResult != 0)
{
ACE_TRACE("Write data failed!");
}
return nResult;
}
[ 本帖最后由 psycheqiqi 于 2009-10-20 14:09 编辑 ] |
|