|
@@ -1332,26 +1332,29 @@ end;
|
|
procedure TFPHTTPConnectionThread.Execute;
|
|
procedure TFPHTTPConnectionThread.Execute;
|
|
|
|
|
|
var
|
|
var
|
|
- AttemptsLeft: Integer;
|
|
|
|
|
|
+ WaitUntil: QWord;
|
|
|
|
+
|
|
|
|
+ procedure SetWaitUntil;
|
|
|
|
+ begin
|
|
|
|
+ if Connection.KeepConnectionTimeout>0 then
|
|
|
|
+ WaitUntil := GetTickCount64+Connection.KeepConnectionTimeout
|
|
|
|
+ else
|
|
|
|
+ WaitUntil := 0;
|
|
|
|
+ end;
|
|
begin
|
|
begin
|
|
try
|
|
try
|
|
// Always handle first request
|
|
// Always handle first request
|
|
Connection.HandleRequest;
|
|
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
|
|
begin
|
|
if Connection.RequestPending then
|
|
if Connection.RequestPending then
|
|
- Connection.HandleRequest
|
|
|
|
- else // KeepConnectionIdleTimeout was reached without a new request -> idle
|
|
|
|
begin
|
|
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;
|
|
end;
|
|
except
|
|
except
|
|
on E : Exception do
|
|
on E : Exception do
|