/** * @file multilogdevice.cc * @brief Implementation of the MultilogDevice class * @author Andreas Aardal Hanssen * @date 2003/2023 */ #include "multilogdevice.h" #include #include #include #include #include #include using namespace Binc; MultilogDevice::MultilogDevice(int f) : IODevice(f) {} MultilogDevice::~MultilogDevice() {} std::string MultilogDevice::service() const { return "log"; } bool MultilogDevice::waitForWrite() const { fd_set writeMask; FD_ZERO(&writeMask); FD_SET(fileno(stderr), &writeMask); struct timeval tv; tv.tv_sec = getTimeout(); tv.tv_usec = 0; int result = select(fileno(stderr) + 1, nullptr, &writeMask, nullptr, tv.tv_sec ? &tv : nullptr); return result > 0; } bool MultilogDevice::waitForRead() const { return false; } IODevice::WriteResult MultilogDevice::write() { for (;;) { ssize_t wrote = ::write(fileno(stderr), outputBuffer.str().c_str(), outputBuffer.getSize()); if (wrote == -1) { if (errno == EINTR) continue; else return WriteError; } if ((unsigned int)wrote == outputBuffer.getSize()) { outputBuffer.clear(); return WriteDone; } outputBuffer.popString(wrote); return WriteWait; } } bool MultilogDevice::fillInputBuffer() { return false; }