* improved TProcess.WaitOnExit with timeout implementation to use fpGetTimeOfDay to work more precise

git-svn-id: trunk@32993 -
This commit is contained in:
florian 2016-01-24 13:21:31 +00:00
parent 2e506ec4ac
commit 2466b58095

View File

@ -459,16 +459,36 @@ begin
FRunning:=False;
end;
{ maybe some unixes might need a simpler solution }
{$define USE_GETTIMEOFDAY}
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
var
res: cint;
{$ifdef USE_GETTIMEOFDAY}
timeout_tv,t : timeval;
tz : timezone;
{$endif USE_GETTIMEOFDAY}
begin
Result:=false;
{$ifdef USE_GETTIMEOFDAY}
fpGetTimeOfDay(@timeout_tv,@tz);
inc(timeout_tv.tv_sec,Timeout div 1000);
inc(timeout_tv.tv_usec,(Timeout mod 1000)*1000);
{$endif USE_GETTIMEOFDAY}
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);
while (res=-1) and (fpgeterrno=ESysEINTR) do
while res=0 do
begin
{$ifdef USE_GETTIMEOFDAY}
fpGetTimeOfDay(@t,@tz);
if (t.tv_sec>timeout_tv.tv_sec) or
((t.tv_sec=timeout_tv.tv_sec) and (t.tv_usec>timeout_tv.tv_usec)) then
exit;
{$else USE_GETTIMEOFDAY}
if Timeout=0 then
Exit;
{$endif USE_GETTIMEOFDAY}
Sleep(1);
dec(Timeout);
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);