1#ifndef NEFORCE_CORE_SYSTEM_PIPE_HPP__
2#define NEFORCE_CORE_SYSTEM_PIPE_HPP__
12NEFORCE_BEGIN_NAMESPACE__
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) {}
29 explicit pipe_exception(
const exception& e) :
30 system_exception(e) {}
32 ~pipe_exception()
override =
default;
33 static constexpr auto static_type =
"pipe_exception";
52 using native_handle_type = _NEFORCE native_handle_type;
55#ifdef NEFORCE_PLATFORM_WINDOWS
56 native_handle_type read_handle_ =
nullptr;
57 native_handle_type write_handle_ =
nullptr;
59 native_handle_type fds_[2] = {-1, -1};
75 explicit pipe(
bool inheritable);
85 pipe& operator=(
const pipe&) =
delete;
144#ifdef NEFORCE_PLATFORM_WINDOWS
155#ifdef NEFORCE_PLATFORM_WINDOWS
156 return write_handle_;
175NEFORCE_END_NAMESPACE__
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
关闭管道的读端
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
获取异常类型