Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

WvPipe Class Reference

#include <wvpipe.h>

Inheritance diagram for WvPipe:

WvStream WvStream List of all members.

Public Methods

 WvPipe (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, int stdin_fd=0, int stdout_fd=1, int stderr_fd=2)
 WvPipe (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, WvStream *stdin_str, WvStream *stdout_str=NULL, WvStream *stderr_str=NULL)
 WvPipe (const char *program, const char **argv, bool writable, bool readable, bool catch_stderr, WvSplitStream *stdio_str)
virtual ~WvPipe ()
void kill (int signum)
int finish ()
bool child_exited ()
bool child_killed () const
int exit_status () const
int getpid () const
 WvPipe (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, int stdin_fd=0, int stdout_fd=1, int stderr_fd=2)
 WvPipe (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, WvStream *stdin_str, WvStream *stdout_str=NULL, WvStream *stderr_str=NULL)
 WvPipe (const char *program, const char **argv, bool writable, bool readable, bool catch_stderr, WvSplitStream *stdio_str)
virtual ~WvPipe ()
void kill (int signum)
int finish ()
bool child_exited ()
bool child_killed () const
int exit_status () const
int getpid () const

Protected Methods

void setup (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, int stdin_fd, int stdout_fd, int stderr_fd)
void setup (const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, int stdin_fd, int stdout_fd, int stderr_fd)

Private Attributes

pid_t pid
int estatus

Detailed Description

Implementation of a WvPipe stream. These allow you to create a new process, attaching its stdin/stdout to a WvStream.

Unlike pipes created with the popen() system call, you can capture both stdin and stdout for the given process. This is because we actually use the socketpair() call instead. If you try this, however, you must be very careful to always use the select() call before reading from the stream. (Think what would happen if both ends of the pipe do a read() simultaneously!)

Note that we do not go as far as actually using a pty. That means programs which deliberately open /dev/tty will not be redirected.

When the WvPipe is destroyed, it makes sure that the child process is killed. Since it tries to do it politely (SIGTERM, wait up to 2 seconds, SIGKILL) it can take up to 2 seconds to destroy a WvPipe.

Definition at line 31 of file include/wvpipe.h.


Constructor & Destructor Documentation

WvPipe::WvPipe const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
int    stdin_fd = 0,
int    stdout_fd = 1,
int    stderr_fd = 2
 

default pipe constructor; if you just want to use a pipe, use this. For each of stdin, stdout, and stderr of the child process, it can do one of three things:

  • leave it alone (ie. the same as for the parent process)
  • redirect it through the WvPipe (eg. if writable==true)
  • redirect it to any open file descriptor (std*_fd are only used if the corresponding bool is false, however)

Definition at line 24 of file wvpipe.cc.

References setup().

WvPipe::WvPipe const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
WvStream   stdin_str,
WvStream   stdout_str = NULL,
WvStream   stderr_str = NULL
 

This constructor does much the same thing as the previous one, except that std*_str are WvStreams instead. The target process accesses the 'fd' member of the stream (NOT using the WvStream read() and write() functions).

Again, we only redirect to the given WvStreams if the corresponding bool is false; otherwise, we redirect to the pipe.

It is okay for the same WvStream to occur more than once. Also, you must naturally make sure that the stream doesn't disappear before WvPipe does!

Definition at line 33 of file wvpipe.cc.

References WvStream::getrfd(), WvStream::getwfd(), and setup().

WvPipe::WvPipe const char *    program,
const char **    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
WvSplitStream   stdio_str
 

This constructor is the same again, except that it uses the features of the WvSplitStream class to get all its fds from one place.

Definition at line 49 of file wvpipe.cc.

References WvSplitStream::getrfd(), WvSplitStream::getwfd(), and setup().

WvPipe::~WvPipe   [virtual]
 

kill the child process and close the stream.

Definition at line 217 of file wvpipe.cc.

References WvStream::close(), kill(), and pid.

WvPipe::WvPipe const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
int    stdin_fd = 0,
int    stdout_fd = 1,
int    stderr_fd = 2
 

default pipe constructor; if you just want to use a pipe, use this. For each of stdin, stdout, and stderr of the child process, it can do one of three things:

  • leave it alone (ie. the same as for the parent process)
  • redirect it through the WvPipe (eg. if writable==true)
  • redirect it to any open file descriptor (std*_fd are only used if the corresponding bool is false, however)

WvPipe::WvPipe const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
WvStream   stdin_str,
WvStream   stdout_str = NULL,
WvStream   stderr_str = NULL
 

This constructor does much the same thing as the previous one, except that std*_str are WvStreams instead. The target process accesses the 'fd' member of the stream (NOT using the WvStream read() and write() functions).

Again, we only redirect to the given WvStreams if the corresponding bool is false; otherwise, we redirect to the pipe.

It is okay for the same WvStream to occur more than once. Also, you must naturally make sure that the stream doesn't disappear before WvPipe does!

WvPipe::WvPipe const char *    program,
const char **    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
WvSplitStream   stdio_str
 

This constructor is the same again, except that it uses the features of the WvSplitStream class to get all its fds from one place.

virtual WvPipe::~WvPipe   [virtual]
 

kill the child process and close the stream.


Member Function Documentation

bool WvPipe::child_exited  
 

returns true if child is dead.

bool WvPipe::child_exited  
 

returns true if child is dead.

Definition at line 177 of file wvpipe.cc.

References estatus, and pid.

Referenced by finish().

bool WvPipe::child_killed   const
 

returns true if child is dead because of a signal.

bool WvPipe::child_killed   const
 

returns true if child is dead because of a signal.

Definition at line 195 of file wvpipe.cc.

References estatus.

Referenced by exit_status().

int WvPipe::exit_status   const
 

returns the exit status: if child_killed()==true, the signal that killed the child. if child_killed()==false, the return code of the program.

int WvPipe::exit_status   const
 

returns the exit status: if child_killed()==true, the signal that killed the child. if child_killed()==false, the return code of the program.

Definition at line 205 of file wvpipe.cc.

References child_killed(), and estatus.

Referenced by finish().

int WvPipe::finish  
 

wait for child to die. Returns exit_status()

int WvPipe::finish  
 

wait for child to die. Returns exit_status()

Definition at line 165 of file wvpipe.cc.

References child_exited(), and exit_status().

int WvPipe::getpid   const [inline]
 

Definition at line 113 of file streams/wvpipe.h.

References pid.

int WvPipe::getpid   const [inline]
 

Definition at line 113 of file include/wvpipe.h.

References pid.

void WvPipe::kill int    signum
 

send the child a signal (signal names are defined in signal.h)

void WvPipe::kill int    signum
 

send the child a signal (signal names are defined in signal.h)

Definition at line 157 of file wvpipe.cc.

References pid.

Referenced by ~WvPipe().

void WvPipe::setup const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
int    stdin_fd,
int    stdout_fd,
int    stderr_fd
[protected]
 

void WvPipe::setup const char *    program,
const char *const *    argv,
bool    writable,
bool    readable,
bool    catch_stderr,
int    stdin_fd,
int    stdout_fd,
int    stderr_fd
[protected]
 

Definition at line 64 of file wvpipe.cc.

References WvStream::errnum, estatus, pid, and WvStream::rwfd.

Referenced by WvPipe().


Member Data Documentation

int WvPipe::estatus [private]
 

Definition at line 34 of file streams/wvpipe.h.

Referenced by child_exited(), child_killed(), exit_status(), and setup().

pid_t WvPipe::pid [private]
 

Definition at line 33 of file streams/wvpipe.h.

Referenced by child_exited(), getpid(), kill(), setup(), and ~WvPipe().


The documentation for this class was generated from the following files:
Generated on Sat Aug 24 21:09:43 2002 for WvStreams by doxygen1.2.15