Gio.PollableInputStream
Description: Reference for Gio.PollableInputStream

### Interface

# GioPollableInputStream

since: 2.28

#### Description [src]

    interface Gio.PollableInputStream : Gio.InputStream

`GPollableInputStream` is implemented by `GInputStream`s 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 from`GInputStream`.

#### Implementations

- GConverterInputStream
- GMemoryInputStream

#### 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
      )
| Checks if the `GPollableInputStream` instance is actually pollable.
`is_readable` |
    gboolean (* is_readable) (
        GPollableInputStream* stream
      )
| Checks if the stream is readable.
`create_source` |
    GSource* (* create_source) (
        GPollableInputStream* stream,
        GCancellable* cancellable
      )
| Creates a `GSource` to poll the stream.
`read_nonblocking` |
    gssize (* read_nonblocking) (
        GPollableInputStream* stream,
        void* buffer,
        gsize count,
        GError** error
      )
| Does a non-blocking read or returns `G_IO_ERROR_WOULD_BLOCK`.

#### 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.