Vincent Snijders schreef:
Marc Weustink schreef:
Vincent Snijders wrote:
Hi,

TAsyncProcess from the LCL has a property NumBytesAvailable. Attached patch adds it to TProcess in the FCL.

NumBytesAvailable checks how many bytes are available in TProcess.Output, so you can decide not to read from it if there are no bytes available.

What about StdErr output ?

Cant this be a property of the TInputPipeStream ?



Seems like an good idea. I will create a new patch.

Jonas Maebe schreef:
 >
 > The FIONREAD constant is available in the termio units of both Darwin
 > and FreeBSD as of 2.0.4 (not for Open/NetBSD, but that's probably the
 > least of the things which need to be changed to get those platforms
 > going again).

Thanks for the hint. I guess this was not yet the case when TAsyncProcess was written by Micha.

Attached is a new patch.

I didn't how to implement this for OS/2.

If the CreatePipes function was not implemented, I assume that poUsePipes cannot be used. GetNumBytesAvailable returns 0 is such cases.

Vincent
Index: amiga/pipes.inc
===================================================================
--- amiga/pipes.inc     (revision 6181)
+++ amiga/pipes.inc     (working copy)
@@ -20,3 +20,11 @@
 begin
   Result := False;
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: beos/pipes.inc
===================================================================
--- beos/pipes.inc      (revision 6181)
+++ beos/pipes.inc      (working copy)
@@ -13,10 +13,18 @@
 
  **********************************************************************}
 
-// No pipes under dos, sorry...
+// No pipes under beos, sorry...
 
 Function CreatePipeHandles (Var Inhandle,OutHandle : Longint) : Boolean;
 
 begin
   Result := False;
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: go32v2/pipes.inc
===================================================================
--- go32v2/pipes.inc    (revision 6181)
+++ go32v2/pipes.inc    (working copy)
@@ -20,3 +20,11 @@
 begin
   Result := False;
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: inc/pipes.pp
===================================================================
--- inc/pipes.pp        (revision 6181)
+++ inc/pipes.pp        (working copy)
@@ -28,13 +28,17 @@
   EPipeSeek = Class (EPipeError);
   EPipeCreation = Class (EPipeError);
 
+  { TInputPipeStream }
+
   TInputPipeStream = Class(THandleStream)
     Private
       FPos : Int64;
+      function GetNumBytesAvailable: DWord;
     public
       Function Write (Const Buffer; Count : Longint) :Longint; Override;
       Function Seek (Offset : Longint;Origin : Word) : longint;override;
       Function Read (Var Buffer; Count : Longint) : longint; Override;
+      property NumBytesAvailable: DWord read GetNumBytesAvailable;
     end;
 
   TOutputPipeStream = Class(THandleStream)
Index: morphos/pipes.inc
===================================================================
--- morphos/pipes.inc   (revision 6181)
+++ morphos/pipes.inc   (working copy)
@@ -20,3 +20,11 @@
 begin
   Result := False;
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: netware/pipes.inc
===================================================================
--- netware/pipes.inc   (revision 6181)
+++ netware/pipes.inc   (working copy)
@@ -13,6 +13,7 @@
 
  **********************************************************************}
 
+// Unsupported for the moment...
 
 Function CreatePipeHandles (Var Inhandle,OutHandle : THandle) : Boolean;
 
@@ -20,3 +21,10 @@
   Result := false;  {dont know how to do that with netware clib}
 end;
 
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: netwlibc/pipes.inc
===================================================================
--- netwlibc/pipes.inc  (revision 6181)
+++ netwlibc/pipes.inc  (working copy)
@@ -13,6 +13,7 @@
 
  **********************************************************************}
 
+// Unsupported for the moment...
 
 Function CreatePipeHandles (Var Inhandle,OutHandle : THandle) : Boolean;
 
@@ -20,3 +21,10 @@
   Result := false;  {todo}
 end;
 
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  Result := 0;
+end;
+
Index: os2/pipes.inc
===================================================================
--- os2/pipes.inc       (revision 6181)
+++ os2/pipes.inc       (working copy)
@@ -24,3 +24,11 @@
 begin
   CreatePipeHandles := DosCreatePipe (InHandle, OutHandle, PipeBufSize) = 0;
 end;
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  // TODO: find out if this is possible in OS/2
+  Result := 0;
+end;
+
Index: unix/pipes.inc
===================================================================
--- unix/pipes.inc      (revision 6181)
+++ unix/pipes.inc      (working copy)
@@ -14,8 +14,7 @@
  **********************************************************************}
 
 Uses
-  Unix
-  ;
+  BaseUnix, Unix, TermIO;
 
 Function CreatePipeHandles (Var Inhandle,OutHandle : Longint) : Boolean;
 
@@ -23,3 +22,11 @@
   Result := (AssignPipe (Inhandle,OutHandle)<>-1);
 end;
 
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  if fpioctl(Handle, FIONREAD, @Result)<0 then
+    Result := 0;
+end;
+
Index: win/pipes.inc
===================================================================
--- win/pipes.inc       (revision 6181)
+++ win/pipes.inc       (working copy)
@@ -33,3 +33,11 @@
 begin
   Result := CreatePipe (@Inhandle,@OutHandle,@piInheritablePipe,PipeBufSize);
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+begin
+  if not PeekNamedPipe(Handle, nil, 0, nil, @Result, nil) then
+    Result := 0;
+end;
+
Index: wince/pipes.inc
===================================================================
--- wince/pipes.inc     (revision 6181)
+++ wince/pipes.inc     (working copy)
@@ -13,8 +13,18 @@
 
  **********************************************************************}
 
+// Unsupported for the moment...
+
 Function CreatePipeHandles (Var Inhandle,OutHandle : THandle) : Boolean;
-// No pipes under dos, sorry...
 begin
   Result := False;
 end;
+
+
+Function TInputPipeStream.GetNumBytesAvailable: DWord;
+
+begin
+  // Windows CE doesn´t have the API function PeekNamedPipe
+  Result := 0;
+end;
+
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to