以前在ASP中一直解决不了下载速度的限制的问题,用ISAPI原来可以这么轻松搞定
void CBinaryWrite::Default(CHttpServerContext* pCtxt) { char buf[1024];
pCtxt->GetServerVariable("HTTP_ALL",buf,1024);
this->AddHeader(pCtxt,"Content-type = image/jpeg\r\n"); this->AddHeader(pCtxt,"Content-type = text/plain\r\n");
StartContent(pCtxt);
CFile f; f.Open("d:\\PHOTO-055.JPG",CFile::modeRead);
ULONG flen=f.GetLength(); ULONG bRead=0; ULONG bRealRead=0;
while (bRead<flen) { bRealRead=f.Read(buf,(flen-bRead>1024)?1024:(flen-bRead)); pCtxt->WriteClient(buf,&bRealRead);
bRead+=bRealRead; Sleep(500);
}
f.Close(); EndContent(pCtxt); }
关键就是这个Sleep,可以放弃CPU资源,让下载过程暂停一定时间,这样通过控制这个暂停的时间,就可以控制速度 
|