From 5d25e58f94ee8a386baa9d411bee441d3b59403a Mon Sep 17 00:00:00 2001 From: vincents Date: Sat, 17 Jun 2006 19:49:04 +0000 Subject: [PATCH] fixed AsyncProcess (with help of Mattias and Micha) git-svn-id: trunk@9441 - --- ide/outputfilter.pas | 7 +++++-- lcl/interfaces/win32/win32lclintf.inc | 2 ++ lcl/interfaces/win32/win32object.inc | 20 ++++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ide/outputfilter.pas b/ide/outputfilter.pas index c3414cd598..10a8d33469 100644 --- a/ide/outputfilter.pas +++ b/ide/outputfilter.pas @@ -27,7 +27,7 @@ unit OutputFilter; interface uses - Classes, SysUtils, Forms, Controls, CompilerOptions, Project, Process, + Classes, Math, SysUtils, Forms, Controls, CompilerOptions, Project, Process, IDEProcs, FileUtil, LclProc, LazConf, AsyncProcess, IDEMsgIntf; type @@ -241,7 +241,10 @@ begin // using non blocking TAsyncProcess Count:=TheAsyncProcess.NumBytesAvailable; if (Count=0) and AsyncProcessTerminated then break; - Count:=TheProcess.Output.Read(Buf[1],length(Buf)); + if Count>0 then + Count:=TheProcess.Output.Read(Buf[1],Min(Count,length(Buf))) + else + Sleep(1); end; if (TheAsyncProcess=nil) and (TheProcess.Output<>nil) then begin // using a blocking TProcess diff --git a/lcl/interfaces/win32/win32lclintf.inc b/lcl/interfaces/win32/win32lclintf.inc index 31f153febd..b01365e5cf 100644 --- a/lcl/interfaces/win32/win32lclintf.inc +++ b/lcl/interfaces/win32/win32lclintf.inc @@ -108,6 +108,8 @@ begin FWaitPipeHandlers := lHandler^.Next; if lHandler^.Next <> nil then lHandler^.Next^.Prev := lHandler^.Prev; + FILLCHAR(LHandler^, sizeof(TPipeEventInfo), 0); + DebugLn(['TWin32WidgetSet.RemovePipeEventHandler', lHandler]); Dispose(lHandler); AHandler := nil; end; diff --git a/lcl/interfaces/win32/win32object.inc b/lcl/interfaces/win32/win32object.inc index 1846b1b82e..354348715c 100644 --- a/lcl/interfaces/win32/win32object.inc +++ b/lcl/interfaces/win32/win32object.inc @@ -347,17 +347,29 @@ procedure TWin32WidgetSet.CheckPipeEvents; var lHandler: PPipeEventInfo; lBytesAvail: dword; + SomethingChanged: Boolean; + ChangedCount:integer; begin lHandler := FWaitPipeHandlers; - while lHandler <> nil do + ChangedCount:=0; + while (lHandler <> nil) and (ChangedCount<10) do begin + SomethingChanged:=true; if Windows.PeekNamedPipe(lHandler^.Handle, nil, 0, nil, @lBytesAvail, nil) then begin if lBytesAvail <> 0 then - lHandler^.OnEvent(lHandler^.UserData, [prDataAvailable]); + lHandler^.OnEvent(lHandler^.UserData, [prDataAvailable]) + else + SomethingChanged := false; end else lHandler^.OnEvent(lHandler^.UserData, [prBroken]); - lHandler := lHandler^.Next; + if SomethingChanged then + lHandler := FWaitPipeHandlers + else begin + lHandler := lHandler^.Next; + ChangedCount := 0; + end; + inc(ChangedCount); end; end; @@ -671,4 +683,4 @@ end; {$IFDEF ASSERT_IS_ON} {$UNDEF ASSERT_IS_ON} {$C-} -{$ENDIF} \ No newline at end of file +{$ENDIF}