|
|
|
|
|
|
|
|
#include <cerrno>
|
|
|
#include <cerrno>
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#include <iostream> // Temporary.
|
|
|
|
|
|
#include <stdexcept>
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
#include "child.hpp"
|
|
|
#include "child.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::streambuf::int_type
|
|
|
std::streambuf::int_type
|
|
|
Child::ReadStreambuf::underflow() {
|
|
|
Child::ReadStreambuf::underflow() {
|
|
|
std::cout << "underflow()." << std::endl; // debug
|
|
|
|
|
|
|
|
|
|
|
|
// Check for empty buffer.
|
|
|
// Check for empty buffer.
|
|
|
if (gptr() < egptr()) {
|
|
|
if (gptr() < egptr()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return traits_type::to_int_type(*gptr());
|
|
|
return traits_type::to_int_type(*gptr());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
std::cout << "need to fill buffer." << std::endl; // debug
|
|
|
|
|
|
|
|
|
|
|
|
// Need to fill the buffer.
|
|
|
// Need to fill the buffer.
|
|
|
char *base = &(buffer.front());
|
|
|
char *base = &(buffer.front());
|
|
|
char *start = base;
|
|
|
char *start = base;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
#else
|
|
|
ssize_t nBytesRead;
|
|
|
ssize_t nBytesRead;
|
|
|
std::cout << "Requesting read of " << buffer.size() - (start - base)
|
|
|
|
|
|
<< " bytes" << std::endl; // debug
|
|
|
|
|
|
|
|
|
|
|
|
nBytesRead = read(inputFileDescriptor,
|
|
|
nBytesRead = read(inputFileDescriptor,
|
|
|
start,
|
|
|
start,
|
|
|
buffer.size() - (start - base));
|
|
|
buffer.size() - (start - base));
|
|
|
// debug
|
|
|
|
|
|
std::cout << "nBytesRead: " << nBytesRead << std::endl; // debug
|
|
|
|
|
|
for (int i = 0; i < nBytesRead; i++) {
|
|
|
|
|
|
std::cout << (char) start[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
// end of debug
|
|
|
|
|
|
if (-1 == nBytesRead) {
|
|
|
if (-1 == nBytesRead) {
|
|
|
return traits_type::eof();
|
|
|
return traits_type::eof();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Update buffer pointers.
|
|
|
// Update buffer pointers.
|
|
|
setg(base, start, start + nBytesRead);
|
|
|
setg(base, start, start + nBytesRead);
|
|
|
|
|
|
|
|
|
std::cout << "underflow() return." << std::endl; // debug
|
|
|
|
|
|
|
|
|
|
|
|
return traits_type::to_int_type(*gptr());
|
|
|
return traits_type::to_int_type(*gptr());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ssize_t nBytesWritten;
|
|
|
ssize_t nBytesWritten;
|
|
|
|
|
|
|
|
|
nBytesWritten = write(outputFileDescriptor, pbase(), nBytes);
|
|
|
nBytesWritten = write(outputFileDescriptor, pbase(), nBytes);
|
|
|
// debug
|
|
|
|
|
|
std::cout << "flushBuffer(). Requested to write " << nBytes << " bytes, "
|
|
|
|
|
|
<<"wrote " << nBytesWritten << " bytes." << std::endl;
|
|
|
|
|
|
char *ch = pbase();
|
|
|
|
|
|
for (int i = 0; i < nBytesWritten; i++) {
|
|
|
|
|
|
std::cout << (char) ch[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
// end of debug.
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|