fixed AsyncProcess (with help of Mattias and Micha)

git-svn-id: trunk@9441 -
This commit is contained in:
vincents 2006-06-17 19:49:04 +00:00
parent 1c375508ba
commit 5d25e58f94
3 changed files with 23 additions and 6 deletions

View File

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

View File

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

View File

@ -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}
{$ENDIF}