From eec7002fe0efc535bb2c14f11f7e5f447e5bb4b1 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sun, 23 Sep 2012 15:09:22 -0400 Subject: [PATCH] DataWaiting function --- mdl/m_pipe_unix.pas | 15 +++++++++++++++ mdl/m_pipe_windows.pas | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/mdl/m_pipe_unix.pas b/mdl/m_pipe_unix.pas index 5f3f153..c885cc0 100644 --- a/mdl/m_pipe_unix.pas +++ b/mdl/m_pipe_unix.pas @@ -28,6 +28,7 @@ Type Procedure SendToPipe (Var Buf; Len: Longint); Procedure ReadFromPipe (Var Buf; Len: LongInt; Var bRead: LongWord); Procedure Disconnect; + Function DataWaiting : Boolean; End; Implementation @@ -47,6 +48,20 @@ Begin Inherited Destroy; End; +Function TPipeUnix.DataWaiting : Boolean; +Var + FDSin : TFDSet; +Begin + Result := False; + + If PipeHandle = -1 Then Exit; + + fpFD_Zero (FDSIN); + fpFD_Set (PipeHandle, FDSIN); + + Result := fpSelect(PipeHandle + 1, @FDSIN, NIL, NIL, 0) > 0; +End; + Function TPipeUnix.CreatePipe : Boolean; Var PipeName : String; diff --git a/mdl/m_pipe_windows.pas b/mdl/m_pipe_windows.pas index 64e8bc6..1190c12 100644 --- a/mdl/m_pipe_windows.pas +++ b/mdl/m_pipe_windows.pas @@ -31,6 +31,7 @@ Type Procedure SendToPipe (Var Buf; Len: Longint); Procedure ReadFromPipe (Var Buf; Len: LongInt; Var bRead: LongWord); Procedure Disconnect; + Function DataWaiting : Boolean; End; Implementation @@ -50,6 +51,25 @@ Begin Inherited Destroy; End; +Function TPipeWindows.DataWaiting : Boolean; +Var + Temp : LongWord; + Avail : LongWord; +Begin + Result := False; + + If PipeHandle = -1 Then Exit; + + PeekNamedPipe (PipeHandle, + NIL, + Temp, + NIL, + @Avail, + NIL); + + Result := (Avail > 0); +End; + Function TPipeWindows.CreatePipe : Boolean; Var SecAttr : TSecurityAttributes;