HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_WritePipe Class Reference

#include <UT_WritePipe.h>

Public Member Functions

 UT_WritePipe (const char *cmd=0, bool change_process_group=false)
 
 ~UT_WritePipe ()
 
FILE * open (const char *cmd)
 
FILE * open (const char *cmd, FILE *kid_stdout, FILE *kid_stderr)
 
int close (bool wait_for_child_to_terminate=false)
 
bool isComplete (bool block=false)
 
void suspend ()
 Suspend pipe process. More...
 
void restart ()
 Restart pipe process after suspended. More...
 
false is liable *to return
false if you call it right
after this Use * 
isComplete (true)`to ensure the pipe process is fully *complete before continuing
 
false is liable *to return
false if you call it right
after this Use or call 
close ()`with block set to true.*/void terminate()
 
bool isSuspended () const
 Is pipe process suspended? More...
 
FILE * getFilePtr ()
 Return file handle for last open() call. More...
 
int getErrno () const
 
int getStatus () const
 
pid_t getPid () const
 This method will return the child process id. More...
 

Detailed Description

Examples:
FS/FS_Background.C.

Definition at line 29 of file UT_WritePipe.h.

Constructor & Destructor Documentation

UT_WritePipe::UT_WritePipe ( const char *  cmd = 0,
bool  change_process_group = false 
)
explicit

Construct pipe

Parameters
cmdIf given, opens the cmd before returning. Call getFilePtr() for the actual created file handle.
change_process_groupPuts the child process in a new process group to isolate the parent from any crashes coming from the child.
UT_WritePipe::~UT_WritePipe ( )

Destruct pipe

If the pipe is open and destructed, the process will be blocked until the child is terminated.

Member Function Documentation

int UT_WritePipe::close ( bool  wait_for_child_to_terminate = false)

Close the pipe

Returns
Return values are:
  • -1 : Error closing the pipe
  • 0 : Child is still running (only returned if the arg is 0)
  • >0 : Child is terminated
Note
After close is called, it is not safe to write to the pipe anymore (since the file descriptor is closed). Please use isComplete() to see if the child process has terminated.
Examples:
FS/FS_Background.C.
false is liable* to return false if you call it right after this Use or call UT_WritePipe::close ( )
int UT_WritePipe::getErrno ( ) const
inline

If close() fails, you can get the errno of the fail call by calling this method. If the child is still running, the error will be set to EWOULDBLOCK

Definition at line 100 of file UT_WritePipe.h.

FILE* UT_WritePipe::getFilePtr ( )
inline

Return file handle for last open() call.

Definition at line 95 of file UT_WritePipe.h.

pid_t UT_WritePipe::getPid ( ) const
inline

This method will return the child process id.

Definition at line 107 of file UT_WritePipe.h.

int UT_WritePipe::getStatus ( ) const
inline

If close() succeeds, you can get the exit status of the child process by calling the following method.

Definition at line 104 of file UT_WritePipe.h.

bool UT_WritePipe::isComplete ( bool  block = false)

Call this to find out whether it's safe to close (i.e. the child process has terminated). This can be called before, or after the pipe has been closed.

Examples:
FS/FS_Background.C.
false is liable* to return false if you call it right after this Use* UT_WritePipe::isComplete ( true  )

Terminate pipe process

Warning
This method is asynchronous! `close(/*block
bool UT_WritePipe::isSuspended ( ) const

Is pipe process suspended?

FILE* UT_WritePipe::open ( const char *  cmd)
inline

Open a command as a write pipe. The file descriptor returned will be the command's stdin.

Examples:
FS/FS_Background.C.

Definition at line 49 of file UT_WritePipe.h.

FILE* UT_WritePipe::open ( const char *  cmd,
FILE *  kid_stdout,
FILE *  kid_stderr 
)

Open a command as a write pipe. The file descriptor returned will be the command's stdin. If the kid_stdout file descriptor is given, this will become stdout for the child. If kid_stderr is specified, it will be come stderr for the child.

void UT_WritePipe::restart ( )

Restart pipe process after suspended.

void UT_WritePipe::suspend ( )

Suspend pipe process.


The documentation for this class was generated from the following file: