mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 04:29:26 +02:00
fix KeepConnectionTimeout loop
This commit is contained in:
parent
e2c9661234
commit
7f9def422f
@ -1332,26 +1332,29 @@ end;
|
||||
procedure TFPHTTPConnectionThread.Execute;
|
||||
|
||||
var
|
||||
AttemptsLeft: Integer;
|
||||
WaitUntil: QWord;
|
||||
|
||||
procedure SetWaitUntil;
|
||||
begin
|
||||
if Connection.KeepConnectionTimeout>0 then
|
||||
WaitUntil := GetTickCount64+Connection.KeepConnectionTimeout
|
||||
else
|
||||
WaitUntil := 0;
|
||||
end;
|
||||
begin
|
||||
try
|
||||
// Always handle first request
|
||||
Connection.HandleRequest;
|
||||
if (Connection.KeepConnectionIdleTimeout>0) and (Connection.KeepConnectionTimeout>0) then
|
||||
AttemptsLeft := Connection.KeepConnectionTimeout div Connection.KeepConnectionIdleTimeout
|
||||
else
|
||||
AttemptsLeft := -1; // infinitely
|
||||
While not Terminated and Connection.AllowNewRequest and (AttemptsLeft<>0) do
|
||||
SetWaitUntil;
|
||||
While not Terminated and Connection.AllowNewRequest and (WaitUntil>0) and (GetTickCount64<WaitUntil) do
|
||||
begin
|
||||
if Connection.RequestPending then
|
||||
Connection.HandleRequest
|
||||
else // KeepConnectionIdleTimeout was reached without a new request -> idle
|
||||
begin
|
||||
if AttemptsLeft>0 then
|
||||
Dec(AttemptsLeft);
|
||||
if AttemptsLeft<>0 then
|
||||
Connection.DoKeepConnectionIdle;
|
||||
end;
|
||||
Connection.HandleRequest;
|
||||
SetWaitUntil;
|
||||
end
|
||||
else // KeepConnectionIdleTimeout was reached without a new request -> idle
|
||||
Connection.DoKeepConnectionIdle;
|
||||
end;
|
||||
except
|
||||
on E : Exception do
|
||||
|
Loading…
Reference in New Issue
Block a user