fixed WaitForHandles

git-svn-id: trunk@4881 -
This commit is contained in:
mattias 2003-12-08 14:27:16 +00:00
parent d40f0332f2
commit a3000e4875
3 changed files with 79 additions and 12 deletions

View File

@ -106,10 +106,9 @@ end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: WaitForHandles Function: WaitForHandles
Params: AHandles: A set of handles to wait for (max 32) Params: AHandles: A set of handles to wait for (max 32)
Returns: BitArray of handles set, 0 when an error ocoured Returns: BitArray of handles set, 0 when an error occoured
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function WaitForHandles(const AHandles: array of Integer): Integer; function WaitForHandles(const AHandles: array of Integer): Integer;
{.$IFDEF Linux}
{$IFDEF UNIX} {$IFDEF UNIX}
var var
n, R, Max, Count: Integer; n, R, Max, Count: Integer;
@ -121,35 +120,54 @@ begin
Count := High(AHandles); Count := High(AHandles);
if Count < 0 then Exit; if Count < 0 then Exit;
if Count > 31 then Count := 31; if Count > 31 then Count := 31;
// zero the whole bit set of handles
{$IFDEF Ver1_0}FD_ZERO{$ELSE}FpFD_ZERO{$ENDIF}(FDS); {$IFDEF Ver1_0}FD_ZERO{$ELSE}FpFD_ZERO{$ENDIF}(FDS);
// set bits for all waiting handles
for n := 0 to Count do for n := 0 to Count do
begin begin
if Max < AHandles[n] then Max := AHandles[n]; if Max < AHandles[n] then Max := AHandles[n];
if AHandles[n] <> 0 if AHandles[n] <> 0 then
then {$IFDEF Ver1_0}FD_Set{$ELSE}FpFD_Set{$ENDIF}(AHandles[n], FDS); {$IFDEF Ver1_0}FD_Set{$ELSE}FpFD_Set{$ENDIF}(AHandles[n], FDS);
end;
if Max=0 then begin
// no valid handle, so no change possible
writeln('WaitForHandles: Error: no handles');
exit;
end; end;
// wait for all handles
repeat repeat
FDSWait := FDS; FDSWait := FDS;
TimeOut := 10; TimeOut := 10;
R := {$IFDEF Ver1_0}Select{$ELSE}FpSelect{$ENDIF}(Max + 1, @FDSWait, nil, nil, TimeOut); // Select:
// R = -1 on error, 0 on timeout, >0 on success and is number of handles
// FDSWait is changed, and indicates what descriptors have changed
R := {$IFDEF Ver1_0}Select{$ELSE}FpSelect{$ENDIF}(Max + 1, @FDSWait,
nil, nil, TimeOut);
Application.ProcessMessages; Application.ProcessMessages;
until R <> 0; until R <> 0;
// set bits for all changed handles
if R > 0 if R > 0
then begin then begin
for n := 0 to Count do for n := 0 to Count do
if (AHandles[n] <> 0) if (AHandles[n] <> 0)
and ({$IFDEF Ver1_0}FD_ISSET{$ELSE}(FpFD_ISSET{$ENDIF}(AHandles[n], FDSWait){$IFNDEF Ver1_0}=0){$ENDIF}) and {$IFDEF Ver1_0}
FD_ISSET(AHandles[n],FDSWait)
{$ELSE}
(FpFD_ISSET(AHandles[n],FDSWait)=1)
{$ENDIF}
then begin then begin
Result := Result or 1 shl n; Result := Result or 1 shl n;
Dec(R); Dec(R);
if R=0 then Break; if R=0 then Break;
end; end;
end; end;
{$ELSE} {$ELSE}
begin begin
writeln('ToDo: implement WaitForHandles for this OS');
Result := 0; Result := 0;
{$ENDIF} {$ENDIF}
end; end;
@ -310,7 +328,7 @@ begin
WaitSet := WaitForHandles([FDbgProcess.Output.Handle]); WaitSet := WaitForHandles([FDbgProcess.Output.Handle]);
if WaitSet = 0 if WaitSet = 0
then begin then begin
WriteLN('[TCmdLineDebugger.Getoutput] Error waiting '); SmartWriteln('[TCmdLineDebugger.Getoutput] Error waiting ');
SetState(dsError); SetState(dsError);
Break; Break;
end; end;
@ -371,6 +389,9 @@ initialization
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.25 2003/12/08 14:27:16 mattias
fixed WaitForHandles
Revision 1.24 2003/10/31 15:14:43 mazen Revision 1.24 2003/10/31 15:14:43 mazen
+ added some paranthesis to avoid operators precedence problems + added some paranthesis to avoid operators precedence problems

View File

@ -62,11 +62,48 @@ function GetPart(const ASkipTo, AnEnd: array of String; var ASource: String; con
function ConvertToCString(const AText: String): String; function ConvertToCString(const AText: String): String;
function DeleteEscapeChars(const AText: String; const AEscapeChar: Char): String; function DeleteEscapeChars(const AText: String; const AEscapeChar: Char): String;
procedure SmartWriteln(const s: string);
implementation implementation
uses uses
SysUtils; SysUtils;
{ SmartWriteln: }
var
LastSmartWritelnStr: string;
LastSmartWritelnCount: integer;
LastSmartWritelnTime: double;
procedure SmartWriteln(const s: string);
var
TimeDiff: TTimeStamp;
i: Integer;
begin
if (LastSmartWritelnCount>0) and (s=LastSmartWritelnStr) then begin
TimeDiff:=DateTimeToTimeStamp(Now-LastSmartWritelnTime);
if TimeDiff.Time<1000 then begin
// repeating too fast
inc(LastSmartWritelnCount);
// write every 2nd, 4th, 8th, 16th, ... time
i:=LastSmartWritelnCount;
while (i>0) and ((i and 1)=0) do begin
i:=i shr 1;
if i=1 then begin
writeln('Last message repeated ',LastSmartWritelnCount,' times:',
' "',LastSmartWritelnStr,'"');
break;
end;
end;
exit;
end;
end;
LastSmartWritelnTime:=Now;
LastSmartWritelnStr:=s;
LastSmartWritelnCount:=1;
writeln(LastSmartWritelnStr);
end;
function GetLine(var ABuffer: String): String; function GetLine(var ABuffer: String): String;
var var
idx: Integer; idx: Integer;
@ -278,9 +315,15 @@ begin
end; end;
end; end;
initialization
LastSmartWritelnCount:=0;
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.10 2003/12/08 14:27:16 mattias
fixed WaitForHandles
Revision 1.9 2003/08/15 14:28:48 mattias Revision 1.9 2003/08/15 14:28:48 mattias
clean up win32 ifdefs clean up win32 ifdefs

View File

@ -40,9 +40,9 @@ interface
{$ASSERTIONS ON} {$ASSERTIONS ON}
uses classes, forms, buttons, StdCtrls, controls, menus, ExtCtrls, CListBox, uses Classes, Forms, Buttons, StdCtrls, Controls, Menus, ExtCtrls, CListBox,
ComCtrls, SysUtils, GraphType, Graphics, Dialogs, Inifiles, Spin, clipbrd, ComCtrls, SysUtils, GraphType, Graphics, Dialogs, Inifiles, Spin, ClipBrd,
LCLIntf, registry, lresources; LCLIntf, LResources;
type type
TForm1 = class(TForm) TForm1 = class(TForm)
@ -2585,6 +2585,9 @@ END.
{ {
$Log$ $Log$
Revision 1.15 2003/12/08 14:27:16 mattias
fixed WaitForHandles
Revision 1.14 2003/11/25 09:15:55 mattias Revision 1.14 2003/11/25 09:15:55 mattias
fixed testall fixed testall