mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-14 01:56:36 +08:00
Issue #1771: add additional sleep time between SSH process checks, so it does not matter when WaitForSingleObject does not really wait (on Wine)
This commit is contained in:
@ -1090,9 +1090,10 @@ var
|
|||||||
rx: TRegExpr;
|
rx: TRegExpr;
|
||||||
StartupInfo: TStartupInfo;
|
StartupInfo: TStartupInfo;
|
||||||
ExitCode: LongWord;
|
ExitCode: LongWord;
|
||||||
Waited, PortChecks, SshTimeOutMilliseconds: Integer;
|
PortChecks: Integer;
|
||||||
SshCheckIntervalMilliseconds: Integer;
|
CheckIntervalMs: Integer;
|
||||||
IsPlink: Boolean;
|
IsPlink: Boolean;
|
||||||
|
TimeStartedMs, WaitedMs, WaitedLeftMs, TimeOutMs: Int64;
|
||||||
begin
|
begin
|
||||||
// Check if local port is open
|
// Check if local port is open
|
||||||
PortChecks := 0;
|
PortChecks := 0;
|
||||||
@ -1162,22 +1163,30 @@ begin
|
|||||||
// Wait until timeout has finished.
|
// Wait until timeout has finished.
|
||||||
// Todo: Find a way to wait only until connection is established
|
// Todo: Find a way to wait only until connection is established
|
||||||
// Parse pipe output and probably show some message in a dialog.
|
// Parse pipe output and probably show some message in a dialog.
|
||||||
Waited := 0;
|
WaitedMs := 0;
|
||||||
DialogTitle := ExtractFileName(FConnection.Parameters.SSHExe);
|
DialogTitle := ExtractFileName(FConnection.Parameters.SSHExe);
|
||||||
SshTimeOutMilliseconds := FConnection.Parameters.SSHTimeout * 1000;
|
TimeOutMs := FConnection.Parameters.SSHTimeout * 1000;
|
||||||
SshCheckIntervalMilliseconds := FConnection.Parameters.SSHTimeout * 100;
|
CheckIntervalMs := FConnection.Parameters.SSHTimeout * 100;
|
||||||
while Waited < SshTimeOutMilliseconds do begin
|
TimeStartedMs := GetTickCount64;
|
||||||
Inc(Waited, SshCheckIntervalMilliseconds);
|
while WaitedMs < TimeOutMs do begin
|
||||||
WaitForSingleObject(FProcessInfo.hProcess, SshCheckIntervalMilliseconds);
|
WaitForSingleObject(FProcessInfo.hProcess, CheckIntervalMs);
|
||||||
|
WaitedMs := GetTickCount64 - TimeStartedMs;
|
||||||
|
// On Wine, WaitForSingleObject does not really seem to wait. See #1771
|
||||||
|
WaitedLeftMs := TimeStartedMs + WaitedMs - GetTickCount64;
|
||||||
|
if WaitedLeftMs > 0 then begin
|
||||||
|
FConnection.Log(lcDebug, 'Wait additional '+WaitedLeftMs.ToString+'ms (see issue #1771)...');
|
||||||
|
Sleep(WaitedLeftMs);
|
||||||
|
end;
|
||||||
GetExitCodeProcess(FProcessInfo.hProcess, ExitCode);
|
GetExitCodeProcess(FProcessInfo.hProcess, ExitCode);
|
||||||
FConnection.Log(lcDebug, 'SSH process exit code after '+Waited.ToString+'ms: '+ExitCode.ToString);
|
if ExitCode <> STILL_ACTIVE then begin
|
||||||
if ExitCode <> STILL_ACTIVE then
|
FConnection.Log(lcError, 'SSH process exited after '+WaitedMs.ToString+'ms with code '+ExitCode.ToString+'. Should be '+STILL_ACTIVE.ToString+' (STILL_ACTIVE)');
|
||||||
raise EDbError.CreateFmt(_('SSH exited unexpected. Command line was: %s'), [CRLF+SshCmdDisplay]);
|
raise EDbError.CreateFmt(_('SSH exited unexpected. Command line was: %s'), [CRLF+SshCmdDisplay]);
|
||||||
|
end;
|
||||||
|
|
||||||
OutText := Trim(ReadPipe(FOutPipe));
|
OutText := Trim(ReadPipe(FOutPipe));
|
||||||
ErrorText := ReadPipe(FErrorPipe);
|
ErrorText := ReadPipe(FErrorPipe);
|
||||||
if (OutText <> '') or (ErrorText <> '') then begin
|
if (OutText <> '') or (ErrorText <> '') then begin
|
||||||
FConnection.Log(lcDebug, Format('SSH output after %d ms. OutPipe: "%s" ErrorPipe: "%s"', [Waited, OutText, ErrorText]));
|
FConnection.Log(lcDebug, Format('SSH output after %d ms. OutPipe: "%s" ErrorPipe: "%s"', [WaitedMs, OutText, ErrorText]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if OutText <> '' then begin
|
if OutText <> '' then begin
|
||||||
|
Reference in New Issue
Block a user