|
int_type | overflow (int_type c) |
| Transfer characters to the pipe when character buffer overflows.
|
|
int_type | underflow () |
| Transfer characters from the pipe when the character buffer is empty.
|
|
int_type | pbackfail (int_type c=traits_type::eof()) |
| Make a character available to be returned by the next extraction.
|
|
int | sync () |
| Write any buffered characters to the stream.
|
|
std::streamsize | xsputn (const char_type *s, std::streamsize n) |
| Insert multiple characters into the pipe.
|
|
std::streamsize | write (const char_type *s, std::streamsize n) |
| Insert a sequence of characters into the pipe.
|
|
std::streamsize | read (char_type *s, std::streamsize n) |
| Extract a sequence of characters from the pipe.
|
|
std::streamsize | showmanyc () |
| Report how many characters can be read from active input without blocking.
|
|
pid_t | fork (pmode mode) |
| Initialise pipes and fork process.
|
|
int | wait (bool nohang=false) |
| Wait for the child process to exit.
|
|
fd_type & | wpipe () |
| Return the file descriptor for the output pipe.
|
|
fd_type & | rpipe () |
| Return the file descriptor for the active input pipe.
|
|
fd_type & | rpipe (buf_read_src which) |
| Return the file descriptor for the specified input pipe.
|
|
void | create_buffers (pmode mode) |
|
void | destroy_buffers (pmode mode) |
|
bool | empty_buffer () |
| Writes buffered characters to the process' stdin pipe.
|
|
bool | fill_buffer (bool non_blocking=false) |
|
char_type * | rbuffer () |
| Return the active input buffer.
|
|
buf_read_src | switch_read_buffer (buf_read_src) |
|
template<typename CharT, typename Traits = std::char_traits<CharT>>
class redi::basic_pstreambuf< CharT, Traits >
Class template for stream buffer.
Provides underlying streambuf functionality for the PStreams classes.
template<typename C , typename T >
Initialise pipes and fork process.
Creates pipes as specified by mode and calls fork()
to create a new process. If the fork is successful the parent process stores the child's PID and the opened pipes and the child process replaces its standard streams with the opened pipes.
If an error occurs the error code will be set to one of the possible errors for pipe()
or fork()
. See your system's documentation for these error codes.
- Parameters
-
mode | an OR of pmodes specifying which of the child's standard streams to connect to. |
- Returns
- On success the PID of the child is returned in the parent's context and zero is returned in the child's context. On error -1 is returned and the error code is set appropriately.
template<typename C , typename T >
Send a signal to the process.
Sends the specified signal to the process. A signal can be used to terminate a child process that would not exit otherwise.
If an error occurs the error code will be set to one of the possible errors for kill()
. See your system's documentation for these errors.
- Parameters
-
signal | A signal to send to the child process. |
- Returns
this
or NULL
if kill()
fails.
template<typename C , typename T >
Send a signal to the process' process group.
Sends the specified signal to the process group of the child process. A signal can be used to terminate a child process that would not exit otherwise, or to kill the process and its own children.
If an error occurs the error code will be set to one of the possible errors for getpgid()
or kill()
. See your system's documentation for these errors. If the child is in the current process group then NULL will be returned and the error code set to EPERM.
- Parameters
-
signal | A signal to send to the child process. |
- Returns
this
on success or NULL
on failure.
template<typename C , typename T >
Initialise the stream buffer with cmd.
Starts a new process by passing command to the shell (/bin/sh) and opens pipes to the process with the specified mode.
If mode contains pstdout
the initial read source will be the child process' stdout, otherwise if mode contains pstderr
the initial read source will be the child's stderr.
Will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character.
- Warning
- There is no way to tell whether the shell command succeeded, this function will always succeed unless resource limits (such as memory usage, or number of processes or open files) are exceeded. This means is_open() will return true even if command cannot be executed. Use pstreambuf::open(const std::string&, const argv_type&, pmode) if you need to know whether the command failed to execute.
- Parameters
-
command | a string containing a shell command. |
mode | a bitwise OR of one or more of out , in , err . |
- Returns
- NULL if the shell could not be started or the pipes could not be opened,
this
otherwise.
- See also
- execl(3)
Referenced by redi::basic_pstreambuf< CharT, Traits >::basic_pstreambuf(), and redi::basic_pstreambuf< CharT, Traits >::basic_pstreambuf().
template<typename C , typename T >
Initialise the stream buffer with file and argv.
Starts a new process by executing file with the arguments in argv and opens pipes to the process with the specified mode.
By convention argv
[0] should be the file name of the file being executed.
If mode contains pstdout
the initial read source will be the child process' stdout, otherwise if mode contains pstderr
the initial read source will be the child's stderr.
Will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character.
Iff file is successfully executed then is_open() will return true. Otherwise, pstreambuf::error() can be used to obtain the value of errno
that was set by execvp(3) in the child process.
The exit status of the new process will be returned by pstreambuf::status() after pstreambuf::exited() returns true.
- Parameters
-
file | a string containing the pathname of a program to execute. |
argv | a vector of argument strings passed to the new program. |
mode | a bitwise OR of one or more of out , in and err . |
- Returns
- NULL if a pipe could not be opened or if the program could not be executed,
this
otherwise.
- See also
- execvp(3)
template<typename C , typename T >
Change active input source.
Toggle the stream used for reading. If readerr is true
then the process' stderr
output will be used for subsequent extractions, if readerr is false the the process' stdout will be used.
- Parameters
-
readerr | true to read stderr , false to read stdout . |
- Returns
true
if the requested stream is open and will be used for subsequent extractions, false
otherwise.
Referenced by redi::basic_ipstream< CharT, Traits >::err(), redi::basic_pstream< CharT, Traits >::err(), redi::basic_rpstream< CharT, Traits >::err(), redi::basic_ipstream< CharT, Traits >::out(), redi::basic_pstream< CharT, Traits >::out(), and redi::basic_rpstream< CharT, Traits >::out().
template<typename C , typename T >
Wait for the child process to exit.
Suspends execution and waits for the associated process to exit, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. If the process has already exited (i.e. it is a "zombie" process) then wait() returns immediately. Waiting for the child process causes all its system resources to be freed.
error() will return EINTR if wait() is interrupted by a signal.
- Parameters
-
nohang | true to return immediately if the process has not exited. |
- Returns
- 1 if the process has exited and wait() has not yet been called. 0 if nohang is true and the process has not exited yet. -1 if no process has been started or if an error occurs, in which case the error can be found using error().