#ifndef UNIQUE_PIPE_HH #define UNIQUE_PIPE_HH #include #include "unique_fd.hh" class unique_pipe { public: explicit unique_pipe(bool non_blocking = false) : unique_pipe(non_blocking, non_blocking) {} unique_pipe(bool non_blocking_reader, bool non_blocking_writer); unique_pipe(unique_pipe&& fd) noexcept; unique_pipe(std::nullptr_t) noexcept : fd_{nullptr, nullptr} {} ~unique_pipe() = default; unique_pipe& operator=(unique_pipe&& fd) noexcept { fd_[0].reset(fd.fd_[0].release()); fd_[1].reset(fd.fd_[1].release()); return *this; } unique_pipe& operator=(std::nullptr_t) noexcept { reset(); return *this; } int reader() const noexcept { return fd_[0].get(); } int writer() const noexcept { return fd_[1].get(); } explicit operator bool() const noexcept { return fd_[0] || fd_[1]; } void reset(); unique_fd release_reader(); unique_fd release_writer(); private: unique_pipe(unique_pipe const&) = delete; unique_pipe& operator=(unique_pipe const&) = delete; unique_fd fd_[2]; }; #endif // UNIQUE_PIPE_HH