diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /src/unique_pipe.hh | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
Diffstat (limited to 'src/unique_pipe.hh')
| -rw-r--r-- | src/unique_pipe.hh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/unique_pipe.hh b/src/unique_pipe.hh new file mode 100644 index 0000000..7020cdf --- /dev/null +++ b/src/unique_pipe.hh @@ -0,0 +1,51 @@ +#ifndef UNIQUE_PIPE_HH +#define UNIQUE_PIPE_HH + +#include <cstddef> + +#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 |
