Interface

GioPollableInputStream

since: 2.28

Description

interface Gio.PollableInputStream : Gio.InputStream

GPollableInputStream is implemented by GInputStreams that can be polled for readiness to read. This can be used when interfacing with a non-GIO API that expects UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.

Some classes may implement GPollableInputStream but have only certain instances of that class be pollable. If g_pollable_input_stream_can_poll() returns false, then the behavior of other GPollableInputStream methods is undefined.

Available since: 2.28

Prerequisite

In order to implement PollableInputStream, your type must inherit fromGInputStream.

Instance methods

g_pollable_input_stream_can_poll

Checks if stream is actually pollable. Some classes may implement GPollableInputStream but have only certain instances of that class be pollable. If this method returns FALSE, then the behavior of other GPollableInputStream methods is undefined.

since: 2.28

g_pollable_input_stream_create_source

Creates a GSource that triggers when stream can be read, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type.

since: 2.28

g_pollable_input_stream_is_readable

Checks if stream can be read.

since: 2.28

g_pollable_input_stream_read_nonblocking

Attempts to read up to count bytes from stream into buffer, as with g_input_stream_read(). If stream is not currently readable, this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can use g_pollable_input_stream_create_source() to create a GSource that will be triggered when stream is readable.

Interface structure

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
  );
  
}

The interface for pollable input streams.

The default implementation of can_poll always returns TRUE.

The default implementation of read_nonblocking calls g_pollable_input_stream_is_readable(), and then calls g_input_stream_read() if it returns TRUE. This means you only need to override it if it is possible that your is_readable implementation may return TRUE when the stream is not actually readable.

Interface members
g_iface
GTypeInterface
 

The parent interface.

can_poll
gboolean (* can_poll) (
    GPollableInputStream* stream
  )
 No description available.
is_readable
gboolean (* is_readable) (
    GPollableInputStream* stream
  )
 No description available.
create_source
GSource* (* create_source) (
    GPollableInputStream* stream,
    GCancellable* cancellable
  )
 No description available.
read_nonblocking
gssize (* read_nonblocking) (
    GPollableInputStream* stream,
    void* buffer,
    gsize count,
    GError** error
  )
 No description available.

Virtual methods

Gio.PollableInputStream.can_poll

Checks if stream is actually pollable. Some classes may implement GPollableInputStream but have only certain instances of that class be pollable. If this method returns FALSE, then the behavior of other GPollableInputStream methods is undefined.

since: 2.28

Gio.PollableInputStream.create_source

Creates a GSource that triggers when stream can be read, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type.

since: 2.28

Gio.PollableInputStream.is_readable

Checks if stream can be read.

since: 2.28

Gio.PollableInputStream.read_nonblocking

Attempts to read up to count bytes from stream into buffer, as with g_input_stream_read(). If stream is not currently readable, this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can use g_pollable_input_stream_create_source() to create a GSource that will be triggered when stream is readable.