Browse Source

Implementing non-blocking read.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@53 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 10 years ago
parent
commit
f1001bc789
2 changed files with 12 additions and 9 deletions
  1. 1
    1
      child.cpp
  2. 11
    8
      child.hpp

+ 1
- 1
child.cpp View File

throw std::runtime_error("Error creating pipe for stdin: " + throw std::runtime_error("Error creating pipe for stdin: " +
getErrorText()); getErrorText());
} }
if (pipe(childStdOutPipe) != 0) {
if (pipe(childStdOutPipe, O_NONBLOCK) != 0) {
close(childStdInPipe[0]); close(childStdInPipe[0]);
close(childStdInPipe[1]); close(childStdInPipe[1]);
throw std::runtime_error("Error creating pipe for stdout: " + throw std::runtime_error("Error creating pipe for stdout: " +

+ 11
- 8
child.hpp View File

/// Override streambuf::underflow(). /// Override streambuf::underflow().
int_type underflow(); int_type underflow();


/// Fill the buffer.
//void fillBuffer();

/// Copy constructor not implemented. /// Copy constructor not implemented.
ReadStreambuf(const ReadStreambuf &); ReadStreambuf(const ReadStreambuf &);


/// Input stream to read data from the child's standard output. /// Input stream to read data from the child's standard output.
std::istream reader; std::istream reader;


/** Get the number of bytes available for input.

@returns number of bytes that can be read from reader without
blocking.

*/
ssize_t inputBytesAvailable();

/// Output stream to write data to the child's standard input. /// Output stream to write data to the child's standard input.
std::ostream writer; std::ostream writer;


*/ */
void run(); void run();


/** Check if input is available.

\returns true if at least one character is available for
reading.

*/
//bool hasData();

/** Terminite the child process. /** Terminite the child process.


\throws runtime_error if an error occurs. \throws runtime_error if an error occurs.

Loading…
Cancel
Save