接口
GioPollableInputStream
自 2.28 版开始
描述 [源]
interface Gio.PollableInputStream : Gio.InputStream
GPollableInputStream 由实现可轮询以读取的 GInputStream 实现。这可以在与非 GIO API 进行接口交互时使用,该 API 预期 UNIX 文件描述符风格的异步 I/O 而不是 GIO 风格。
某些类可能实现 GPollableInputStream 但只有该类的特定实例是可轮询的。如果 g_pollable_input_stream_can_poll() 返回 false,则其他 GPollableInputStream 方法的行为将是未定义的。
自 2.28 版开始
先决条件
为了实现 PollableInputStream,您的类型必须继承自 GInputStream。
实例方法
g_pollable_input_stream_can_poll
检查 stream 是否实际可轮询。某些类可能实现 GPollableInputStream 但只有该类的特定实例是可轮询的。如果此方法返回 FALSE,则其他 GPollableInputStream 方法的操作是未定义的。
自 2.28 版开始
g_pollable_input_stream_create_source
创建一个在 stream 可读时、cancellable 被触发或发生错误时触发的 GSource。源上的回调为 GPollableSourceFunc 类型。
自 2.28 版开始
g_pollable_input_stream_read_nonblocking
尝试从 stream 读取最多 count 个字节到 buffer 中,就像在 g_input_stream_read() 中一样。如果 stream 当前不可读,则会立即返回 G_IO_ERROR_WOULD_BLOCK,您可以使用 g_pollable_input_stream_create_source() 创建将在 stream 可读时触发的 GSource。
接口结构
struct GioPollableInputStreamInterface {
GTypeInterface g_iface;
gboolean (* can_poll) (
GPollableInputStream* stream
);
gboolean (* is_readable) (
GPollableInputStream* stream
);
GSource* (* create_source) (
GPollableInputStream* stream,
GCancellable* cancellable
);
gssize (* read_nonblocking) (
GPollableInputStream* stream,
void* buffer,
gsize count,
GError** error
);
}
可轮询输入流的接口。
can_poll 的默认实现始终返回 TRUE。
read_nonblocking 的默认实现调用 g_pollable_input_stream_is_readable(),然后根据返回值为 TRUE 时调用 g_input_stream_read()。这意味着如果您的 is_readable 实现可能在流实际不可读时返回 TRUE,则您只需要重写它。
接口成员
g_iface |
|
父接口。 |
|
can_poll |
|
检查 |
|
is_readable |
|
检查流是否可读。 |
|
create_source |
|
创建一个用于轮询流的 |
|
read_nonblocking |
|
执行非阻塞读取,或返回 |
虚拟方法
Gio.PollableInputStream.can_poll
检查 stream 是否实际可轮询。某些类可能实现 GPollableInputStream 但只有该类的特定实例是可轮询的。如果此方法返回 FALSE,则其他 GPollableInputStream 方法的操作是未定义的。
自 2.28 版开始
Gio.PollableInputStream.create_source
创建一个在 stream 可读时、cancellable 被触发或发生错误时触发的 GSource。源上的回调为 GPollableSourceFunc 类型。
自 2.28 版开始
Gio.PollableInputStream.read_nonblocking
尝试从 stream 读取最多 count 个字节到 buffer 中,就像在 g_input_stream_read() 中一样。如果 stream 当前不可读,则会立即返回 G_IO_ERROR_WOULD_BLOCK,您可以使用 g_pollable_input_stream_create_source() 创建将在 stream 可读时触发的 GSource。