From a3000e4875468a9c678d7ed3cb2b06dc5ab0e828 Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 8 Dec 2003 14:27:16 +0000 Subject: [PATCH] fixed WaitForHandles git-svn-id: trunk@4881 - --- debugger/cmdlinedebugger.pp | 39 +++++++++++++++++++++++++-------- debugger/dbgutils.pp | 43 +++++++++++++++++++++++++++++++++++++ examples/testallform.pp | 9 +++++--- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/debugger/cmdlinedebugger.pp b/debugger/cmdlinedebugger.pp index 58624d07c7..fdaef6a205 100644 --- a/debugger/cmdlinedebugger.pp +++ b/debugger/cmdlinedebugger.pp @@ -106,10 +106,9 @@ end; {------------------------------------------------------------------------------ Function: WaitForHandles 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; -{.$IFDEF Linux} {$IFDEF UNIX} var n, R, Max, Count: Integer; @@ -121,35 +120,54 @@ begin Count := High(AHandles); if Count < 0 then Exit; if Count > 31 then Count := 31; + + // zero the whole bit set of handles {$IFDEF Ver1_0}FD_ZERO{$ELSE}FpFD_ZERO{$ENDIF}(FDS); + // set bits for all waiting handles for n := 0 to Count do begin if Max < AHandles[n] then Max := AHandles[n]; - if AHandles[n] <> 0 - then {$IFDEF Ver1_0}FD_Set{$ELSE}FpFD_Set{$ENDIF}(AHandles[n], FDS); + if AHandles[n] <> 0 then + {$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; + // wait for all handles repeat FDSWait := FDS; 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; until R <> 0; - + + // set bits for all changed handles if R > 0 then begin for n := 0 to Count do 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 Result := Result or 1 shl n; Dec(R); if R=0 then Break; end; - end; +end; {$ELSE} begin + writeln('ToDo: implement WaitForHandles for this OS'); Result := 0; {$ENDIF} end; @@ -310,7 +328,7 @@ begin WaitSet := WaitForHandles([FDbgProcess.Output.Handle]); if WaitSet = 0 then begin - WriteLN('[TCmdLineDebugger.Getoutput] Error waiting '); + SmartWriteln('[TCmdLineDebugger.Getoutput] Error waiting '); SetState(dsError); Break; end; @@ -371,6 +389,9 @@ initialization end. { ============================================================================= $Log$ + Revision 1.25 2003/12/08 14:27:16 mattias + fixed WaitForHandles + Revision 1.24 2003/10/31 15:14:43 mazen + added some paranthesis to avoid operators precedence problems diff --git a/debugger/dbgutils.pp b/debugger/dbgutils.pp index 837f84f066..b879a016d6 100644 --- a/debugger/dbgutils.pp +++ b/debugger/dbgutils.pp @@ -62,11 +62,48 @@ function GetPart(const ASkipTo, AnEnd: array of String; var ASource: String; con function ConvertToCString(const AText: String): String; function DeleteEscapeChars(const AText: String; const AEscapeChar: Char): String; +procedure SmartWriteln(const s: string); + implementation uses 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; var idx: Integer; @@ -278,9 +315,15 @@ begin end; end; +initialization + LastSmartWritelnCount:=0; + end. { ============================================================================= $Log$ + Revision 1.10 2003/12/08 14:27:16 mattias + fixed WaitForHandles + Revision 1.9 2003/08/15 14:28:48 mattias clean up win32 ifdefs diff --git a/examples/testallform.pp b/examples/testallform.pp index 4393ed7f52..a8e67eddc1 100644 --- a/examples/testallform.pp +++ b/examples/testallform.pp @@ -40,9 +40,9 @@ interface {$ASSERTIONS ON} -uses classes, forms, buttons, StdCtrls, controls, menus, ExtCtrls, CListBox, - ComCtrls, SysUtils, GraphType, Graphics, Dialogs, Inifiles, Spin, clipbrd, - LCLIntf, registry, lresources; +uses Classes, Forms, Buttons, StdCtrls, Controls, Menus, ExtCtrls, CListBox, + ComCtrls, SysUtils, GraphType, Graphics, Dialogs, Inifiles, Spin, ClipBrd, + LCLIntf, LResources; type TForm1 = class(TForm) @@ -2585,6 +2585,9 @@ END. { $Log$ + Revision 1.15 2003/12/08 14:27:16 mattias + fixed WaitForHandles + Revision 1.14 2003/11/25 09:15:55 mattias fixed testall