procedure THttpStream.HttpCli1DocData(Sender: TObject; Buffer: Pointer;
Len: Integer);
begin
if FReady = True then Exit;
FOldTime := timeGetTime;
trace(format('Data Size: %u',[len]));
if Assigned(FOndata) then FOnData(Self,Buffer,Len);
Inc(FPosition,Len);
if FLimitedSpeed<> 0 then
DoLimitedSpeed(Len);
end;
procedure THttpStream.DoLimitedSpeed(len:Integer);
var
UseTime
WORD;
expTime
WORD;
begin
if FPaused then
begin
FHttpCli.WSocket.Pause;
Exit;
end;
UseTime := timeGetTime - FOldTime;
expTime := len *1000 div (LimitedSpeed*1024);
if expTime > UseTime + 2 then
begin
FHttpCli.WSocket.Pause;
Delay(min(2000,expTime - UseTime));
FHttpCli.WSocket.Resume;
end;
// DB_WriteIntln(0,expTime - UseTime);
end;
procedure Delay(m:Cardinal);
var
tick : Cardinal;
begin
tick := TimeGetTime;
while TimeGetTime - tick < m do
begin
Application.ProcessMessages;
Sleep(2);
end;
end;
应该可以理解了吧?