fix KeepConnectionTimeout loop

This commit is contained in:
Ondrej Pokorny 2025-02-25 20:25:27 +01:00 committed by Michael Van Canneyt
parent e2c9661234
commit 7f9def422f

View File

@ -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