diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-02 22:29:11 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-03 01:52:38 +0800 |
commit | 545a638929218a83d194402b3d52f5bffd87d9eb (patch) | |
tree | f659f671fec17f3ef7dced31f3a1f59673d18690 /include/cru/base/platform/unix/UnixPipe.h | |
parent | 5035f18f44f675af2faa4019b6de14b3f3aab270 (diff) | |
download | cru-545a638929218a83d194402b3d52f5bffd87d9eb.tar.gz cru-545a638929218a83d194402b3d52f5bffd87d9eb.tar.bz2 cru-545a638929218a83d194402b3d52f5bffd87d9eb.zip |
UnixFileDescriptor.
Diffstat (limited to 'include/cru/base/platform/unix/UnixPipe.h')
-rw-r--r-- | include/cru/base/platform/unix/UnixPipe.h | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/include/cru/base/platform/unix/UnixPipe.h b/include/cru/base/platform/unix/UnixPipe.h deleted file mode 100644 index 830ddf62..00000000 --- a/include/cru/base/platform/unix/UnixPipe.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#if !defined(__unix) -#error "This file can only be included on unix." -#endif - -#include "../../Base.h" -#include "../../Bitmask.h" - -namespace cru::platform::unix { -namespace details { -struct UnixPipeFlagTag; -} -using UnixPipeFlag = Bitmask<details::UnixPipeFlagTag>; -struct UnixPipeFlags { - constexpr static auto NonBlock = UnixPipeFlag::FromOffset(1); -}; - -/** - * @brief an unix pipe, commonly for communication of parent process and child - * process. - * - * There are two types of pipes sorted by its usage. For stdin, parent process - * SEND data to child process. For stdout and stderr, parent process RECEIVE - * data from child process. Each pipe has two ends, one for read and the other - * for write. But for send and receive, they are reversed. It is a little - * confused to consider which end should be used by parent and which end should - * be used by child. So this class help you make it clear. You specify SEND or - * RECEIVE, and this class give you a parent used end and a child used end. - * - * This class will only close the end used by parent when it is destructed. It - * is the user's duty to close the one used by child. - */ -class UnixPipe : public Object { - private: - constexpr static auto kLogTag = u"cru::platform::unix::UnixPipe"; - - public: - enum class Usage { - Send, - Receive, - }; - - explicit UnixPipe(Usage usage, bool auto_close, UnixPipeFlag flags = {}); - - CRU_DELETE_COPY(UnixPipe) - CRU_DELETE_MOVE(UnixPipe) - - ~UnixPipe(); - - /** - * @brief aka, the one used by parent process. - */ - int GetSelfFileDescriptor(); - - /** - * @brief aka, the one used by child process. - */ - int GetOtherFileDescriptor(); - - private: - Usage usage_; - bool auto_close_; - UnixPipeFlag flags_; - int read_fd_; - int write_fd_; -}; -} // namespace cru::platform::unix |