rutz::bidir_pipe Class Reference

An exception-safe wrapper around a pipe-fork-exec sequence. More...

#include <rutz/pipe.h>

Collaboration diagram for rutz::bidir_pipe:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 bidir_pipe ()
 Default construct; you MUST call init() before using any of the streams!
 bidir_pipe (char *const *argv)
 Set up a pipe to a child process with the given argv array.
 bidir_pipe (const char *argv0,...)
 Set up a pipe to a child process with the given list of args.
 ~bidir_pipe () throw ()
 Destructor cleans up child process and the pipe's file descriptors.
void block_child_sigint ()
 Request that SIGINT be ignored in the child process.
void init (char *const *argv)
 Core code for starting the child process.
void init (const char *argv0,...)
 Core code for starting the child process.
std::iostream & in_stream () throw ()
 Get the stream that is receiving input from the child process.
std::iostream & out_stream () throw ()
 Get the stream that is sending output to the child process.
void close_in ()
 Close the underlying input stream file descriptor.
void close_out ()
 Close the underlying output stream file descriptor.
int exit_status () throw ()
 Wait for child process to complete, return 0 if all is OK, -1 if error.


Detailed Description

An exception-safe wrapper around a pipe-fork-exec sequence.

Definition at line 170 of file pipe.h.


Constructor & Destructor Documentation

rutz::bidir_pipe::bidir_pipe ( char *const *  argv  ) 

Set up a pipe to a child process with the given argv array.

BE SURE the argv array is NULL-terminated!

Definition at line 297 of file pipe.cc.

References init().

rutz::bidir_pipe::bidir_pipe ( const char *  argv0,
  ... 
)

Set up a pipe to a child process with the given list of args.

BE SURE the variable-length argument list is NULL-terminated!

A private copy will be made of all the arguments, so it is safe to pass const strings here (such as the result of str.c_str() for a std::string object).

Definition at line 308 of file pipe.cc.

References init().


Member Function Documentation

void rutz::bidir_pipe::block_child_sigint (  ) 

Request that SIGINT be ignored in the child process.

You must request this BEFORE calling init(); so the proper sequence is:

      rutz::bidir_pipe prog;
      prog.block_child_signals();
      prog.init("progname", "arg1", "arg2", NULL);

This functionality is useful if the parent process is already handling SIGINT specially; if you don't block SIGINT in the child process, then when the user presses Ctrl-C, the following happens: (1) the main parent handles the SIGINT, as desired, but (2) the child process also receives a SIGINT, thus it dies, and (3) the parent process then gets a SIGPIPE and dies itself without getting a chance for a clean exit.

Definition at line 336 of file pipe.cc.

void rutz::bidir_pipe::init ( char *const *  argv  ) 

Core code for starting the child process.

NOTE the argv array must be NULL-terminated!

Definition at line 341 of file pipe.cc.

References rutz::pipe_fds::close_reader(), rutz::pipe_fds::close_writer(), rutz::child_process::in_parent(), rutz::pipe_fds::reader(), SRC_POS, and rutz::pipe_fds::writer().

Referenced by bidir_pipe(), and init().

void rutz::bidir_pipe::init ( const char *  argv0,
  ... 
)

Core code for starting the child process.

BE SURE the variable-length argument list is NULL-terminated!

Definition at line 400 of file pipe.cc.

References init().


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

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:56:45 2008 by Doxygen version 1.5.5.