匿名管道类
更多...
#include <pipe.hpp>
|
| | pipe () noexcept=default |
| | 默认构造函数
|
| | pipe (bool inheritable, bool nonblocking=false) |
| | 创建管道并设置非阻塞模式
|
| | ~pipe () |
| | 析构函数
|
|
| pipe (pipe &&other) noexcept |
| | 移动构造函数
|
|
pipe & | operator= (pipe &&other) noexcept |
| | 移动赋值运算符
|
| int | read (void *buffer, size_t size) noexcept |
| | 从管道读取数据
|
| string | read_available () |
| | 从管道读取所有可用数据(非阻塞)
|
| bool | set_nonblocking (bool v) noexcept |
| | 设置管道非阻塞模式
|
| bool | is_nonblocking () const noexcept |
| | 查询管道是否处于非阻塞模式
|
| int | write (const void *data, size_t size) noexcept |
| | 向管道写入数据
|
|
void | close_read () noexcept |
| | 关闭管道的读端
|
|
void | close_write () noexcept |
| | 关闭管道的写端
|
|
void | close () noexcept |
| | 关闭管道的所有端
|
| bool | is_valid () const noexcept |
| | 检查管道是否有效
|
|
native_handle_type | native_read_handle () const noexcept |
| | 获取读端句柄
|
|
native_handle_type | native_write_handle () const noexcept |
| | 获取写端句柄
|
|
native_handle_type | detach_read_handle () noexcept |
| | 分离读端句柄(调用者负责关闭)
|
|
native_handle_type | detach_write_handle () noexcept |
| | 分离写端句柄(调用者负责关闭)
|
匿名管道类
支持管道的创建、读写和关闭。 默认创建阻塞式管道,可通过参数或 set_nonblocking() 切换非阻塞模式。
在文件 pipe.hpp 第 52 行定义.
◆ pipe() [1/2]
◆ pipe() [2/2]
| neforce::pipe::pipe |
( |
bool | inheritable, |
|
|
bool | nonblocking = false ) |
|
explicit |
创建管道并设置非阻塞模式
- 参数
-
| inheritable | 子进程是否可继承(Windows) |
| nonblocking | 是否启用非阻塞模式 |
- 异常
-
非阻塞模式下,read() 在无数据可用时返回 0 而非阻塞等待, write() 在缓冲区满时返回 0 而非阻塞等待。
引用了 pipe().
◆ ~pipe()
◆ ignore_sigpipe()
| void neforce::pipe::ignore_sigpipe |
( |
| ) |
|
|
staticnoexcept |
忽略 SIGPIPE 信号
- 注解
- 在 POSIX 系统上,向没有读端的管道写入会触发 SIGPIPE 信号,默认行为是终止进程。 调用此函数后,系统将忽略该信号,改为由 write() 返回 -1 并设置 errno = EPIPE。 此操作是进程全局的,但也是线程安全的传统做法。 在 Windows 上该函数无任何效果。
引用了 ignore_sigpipe().
被这些函数引用 ignore_sigpipe().
◆ is_nonblocking()
| bool neforce::pipe::is_nonblocking |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ is_valid()
| bool neforce::pipe::is_valid |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ read()
| int neforce::pipe::read |
( |
void * | buffer, |
|
|
size_t | size ) |
|
noexcept |
◆ read_available()
| string neforce::pipe::read_available |
( |
| ) |
|
|
nodiscard |
◆ set_nonblocking()
| bool neforce::pipe::set_nonblocking |
( |
bool | v | ) |
|
|
noexcept |
◆ write()
| int neforce::pipe::write |
( |
const void * | data, |
|
|
size_t | size ) |
|
noexcept |
该类的文档由以下文件生成: