NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
pipe.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_SYSTEM_PIPE_HPP__
2#define NEFORCE_CORE_SYSTEM_PIPE_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
24struct pipe_exception final : system_exception {
25 explicit pipe_exception(const char* info = "Pipe Operation Failed.", const char* type = static_type,
26 const int code = 0) noexcept :
27 system_exception(info, type, code) {}
28
29 explicit pipe_exception(const exception& e) :
30 system_exception(e) {}
31
32 ~pipe_exception() override = default;
33 static constexpr auto static_type = "pipe_exception";
34};
35 // Exceptions
37
43
50class NEFORCE_API pipe {
51public:
52 using native_handle_type = _NEFORCE native_handle_type;
53
54private:
55#ifdef NEFORCE_PLATFORM_WINDOWS
56 native_handle_type read_handle_ = nullptr;
57 native_handle_type write_handle_ = nullptr;
58#else
59 native_handle_type fds_[2] = {-1, -1};
60#endif
61
62public:
68 pipe() noexcept {}
69
75 explicit pipe(bool inheritable);
76
83
84 pipe(const pipe&) = delete;
85 pipe& operator=(const pipe&) = delete;
86
90 pipe(pipe&& other) noexcept;
91
95 pipe& operator=(pipe&& other) noexcept;
96
103 int read(void* buffer, size_t size) noexcept;
104
109 NEFORCE_NODISCARD string read_available();
110
117 int write(const void* data, size_t size) noexcept;
118
122 void close_read() noexcept;
123
127 void close_write() noexcept;
128
132 void close() noexcept;
133
138 NEFORCE_NODISCARD bool is_valid() const noexcept;
139
143 NEFORCE_NODISCARD native_handle_type native_read_handle() const noexcept {
144#ifdef NEFORCE_PLATFORM_WINDOWS
145 return read_handle_;
146#else
147 return fds_[0];
148#endif
149 }
150
154 NEFORCE_NODISCARD native_handle_type native_write_handle() const noexcept {
155#ifdef NEFORCE_PLATFORM_WINDOWS
156 return write_handle_;
157#else
158 return fds_[1];
159#endif
160 }
161
165 NEFORCE_NODISCARD native_handle_type detach_read_handle() noexcept;
166
170 NEFORCE_NODISCARD native_handle_type detach_write_handle() noexcept;
171};
172 // Pipe
174
175NEFORCE_END_NAMESPACE__
176#endif // NEFORCE_CORE_SYSTEM_PIPE_HPP__
pipe() noexcept
默认构造函数
int read(void *buffer, size_t size) noexcept
从管道读取数据
NEFORCE_NODISCARD native_handle_type native_write_handle() const noexcept
获取写端句柄
void close() noexcept
关闭管道的所有端
NEFORCE_NODISCARD native_handle_type native_read_handle() const noexcept
获取读端句柄
pipe(bool inheritable)
创建管道
pipe(pipe &&other) noexcept
移动构造函数
int write(const void *data, size_t size) noexcept
向管道写入数据
NEFORCE_NODISCARD bool is_valid() const noexcept
检查管道是否有效
pipe & operator=(pipe &&other) noexcept
移动赋值运算符
NEFORCE_NODISCARD native_handle_type detach_read_handle() noexcept
分离读端句柄(调用者负责关闭)
NEFORCE_NODISCARD native_handle_type detach_write_handle() noexcept
分离写端句柄(调用者负责关闭)
void close_write() noexcept
关闭管道的写端
void close_read() noexcept
关闭管道的读端
~pipe()
析构函数
NEFORCE_NODISCARD string read_available()
从管道读取所有可用数据(非阻塞)
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) size(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的大小
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
字符串类型别名和实用函数
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
NEFORCE_NODISCARD int code() const noexcept
获取异常码
NEFORCE_NODISCARD const char * type() const noexcept
获取异常类型