UCommon

shell::pipeio Class Reference

A class to control a process that is piped. More...

#include <shell.h>

Inheritance diagram for shell::pipeio:

Protected Member Functions

int cancel (void)
 Signal termination and wait for child process to exit.
 pipeio ()
 Construct an empty initialized pipe for use.
size_t read (void *address, size_t size)
 Read input from child process.
int spawn (const char *path, char **argv, pmode_t mode, size_t size=512, char **env=NULL)
 Spawn and attach child process I/O through piping.
int wait (void)
 Wait for child process to exit.
size_t write (const void *address, size_t size)
 Write to the child process.

Protected Attributes

fd_t input
fd_t output
int perror
pid_t pid
int presult

Friends

class shell

Detailed Description

A class to control a process that is piped.

This holds the active file descriptors for the pipe as well as the process id. Basic I/O methods are provided to send and receive data with the piped child process. This may be used by itself with various shell methods as a pipe_t, or to construct piped objects such as iobuf.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 141 of file shell.h.


Member Function Documentation

int shell::pipeio::cancel ( void  ) [protected]

Signal termination and wait for child process to exit.

When it does all piping is closed.

Returns:
process exit code or -1 if error.

Reimplemented in shell::iobuf.

size_t shell::pipeio::read ( void *  address,
size_t  size 
) [protected]

Read input from child process.

If there is an error, the result is 0 and perror holds the error code. If an error already happened no further data will be read.

Parameters:
addressto store input.
sizeof input to read.
Returns:
number of bytes actually read.
int shell::pipeio::spawn ( const char *  path,
char **  argv,
pmode_t  mode,
size_t  size = 512,
char **  env = NULL 
) [protected]

Spawn and attach child process I/O through piping.

Stderr is left attached to the console.

Parameters:
pathof program to execute. If simple file, $PATH is used.
argvto pass to child process.
modeof pipe operation; rdonly, wronly, or rdwr.
sizeof atomic pipe buffer if setable.
envthat may optionally be given to the child process.
int shell::pipeio::wait ( void  ) [protected]

Wait for child process to exit.

When it does, close all piping.

Returns:
process exit code or -1 if error.
size_t shell::pipeio::write ( const void *  address,
size_t  size 
) [protected]

Write to the child process.

If there is an error, the result is 0 and perror holds the error code. If an error already happened no further data will be written.

Parameters:
addressto write data from.
sizeof data to write.
Returns:
number of bytes actually written.

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