X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Ftools%2Fmakeappimagetool%2Fpipe_reader.cpp;fp=cinelerra-5.1%2Ftools%2Fmakeappimagetool%2Fpipe_reader.cpp;h=1adc5d3117031445c66a6a54fa70d7051f78317b;hb=194ea84742f4d9973b1aad567fe833ca13a8c4f9;hp=0000000000000000000000000000000000000000;hpb=d8393b13b37b8654f0039ec1dba9a71c02af9411;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/tools/makeappimagetool/pipe_reader.cpp b/cinelerra-5.1/tools/makeappimagetool/pipe_reader.cpp new file mode 100644 index 00000000..1adc5d31 --- /dev/null +++ b/cinelerra-5.1/tools/makeappimagetool/pipe_reader.cpp @@ -0,0 +1,32 @@ +// system headers +#include +#include +#include +#include +#include +#include + +// local headers +#include "includes/pipe_reader.h" + +pipe_reader::pipe_reader(int pipe_fd) : pipe_fd_(pipe_fd) { + // add O_NONBLOCK TO fd's flags to be able to read + auto flags = fcntl(pipe_fd_, F_GETFL, 0); + flags |= O_NONBLOCK; + fcntl(pipe_fd_, F_SETFL, flags); +} + +size_t pipe_reader::read(std::vector& buffer) const { + ssize_t rv = ::read(pipe_fd_, buffer.data(), buffer.size()); + + if (rv == -1) { + // no data available + if (errno == EAGAIN) + return 0; + + // TODO: introduce custom subprocess_error + throw std::runtime_error{"unexpected error reading from pipe: " + std::string(strerror(errno))}; + } + + return rv; +}