Y
yyok
Unregistered / Unconfirmed
GUEST, unregistred user!
我用InternetReadFileEx从网上读取文件,
读得不会停下了,也就是文件读完了,但是dwBufferLength不会返回0,
我设的缓冲大小为65535,但是我把它设得很小时,比如4,就不会发生这个问题。
请问这是为什么。
bAllDone := false;
iTotalReceive := 0 ;
iFileHandle := FileCreate('C:/temp.exe');
if iFileHandle = -1 then ShowMessage(IntToStr(GetLastError()));
repeat
begin
FillMemory(@InetReadBuf,sizeof(InetReadBuf),0);
InetReadBuf.dwStructSize := sizeof(InetReadBuf);
InetReadBuf.lpvBuffer := @readBuf;
InetReadBuf.dwBufferLength := 65535;
bRetReadFile := InternetReadFileEx
(hRequest,@InetReadBuf,IRF_ASYNC,2);
if bRetReadFile = false then
begin
if GetLastError() <> ERROR_IO_PENDING then
begin
Form1.OutPut(GetLastError(),'interReadFile fail');
break;
end;
end;
filewrite(iFileHandle,readBuf,InetReadBuf.dwBufferLength);
if InetReadBuf.dwBufferLength = 0 then
bAllDone := true;
end
until bAllDone = true;
fileClose(iFileHandle);
读得不会停下了,也就是文件读完了,但是dwBufferLength不会返回0,
我设的缓冲大小为65535,但是我把它设得很小时,比如4,就不会发生这个问题。
请问这是为什么。
bAllDone := false;
iTotalReceive := 0 ;
iFileHandle := FileCreate('C:/temp.exe');
if iFileHandle = -1 then ShowMessage(IntToStr(GetLastError()));
repeat
begin
FillMemory(@InetReadBuf,sizeof(InetReadBuf),0);
InetReadBuf.dwStructSize := sizeof(InetReadBuf);
InetReadBuf.lpvBuffer := @readBuf;
InetReadBuf.dwBufferLength := 65535;
bRetReadFile := InternetReadFileEx
(hRequest,@InetReadBuf,IRF_ASYNC,2);
if bRetReadFile = false then
begin
if GetLastError() <> ERROR_IO_PENDING then
begin
Form1.OutPut(GetLastError(),'interReadFile fail');
break;
end;
end;
filewrite(iFileHandle,readBuf,InetReadBuf.dwBufferLength);
if InetReadBuf.dwBufferLength = 0 then
bAllDone := true;
end
until bAllDone = true;
fileClose(iFileHandle);