### Interface

# Gio PollableOutputStream

since: 2.28

#### Description

    interface Gio.PollableOutputStream : Gio.OutputStream

`GPollableOutputStream` is implemented by `GOutputStream`s that can be polled for readiness to write. 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 `GPollableOutputStream` but have only certain instances of that class be pollable. If `g_pollable_output_stream_can_poll()` returns false, then the behavior of other `GPollableOutputStream` methods is undefined.

Available since: 2.28

#### Prerequisite

In order to implement PollableOutputStream, your type must inherit from`GOutputStream`.

#### Implementations

- GConverterOutputStream
- GMemoryOutputStream
- GUnixOutputStream

#### Instance methods

###### g_pollable_output_stream_can_poll

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

since: 2.28

###### g_pollable_output_stream_create_source

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

since: 2.28

###### g_pollable_output_stream_is_writable

Checks if `stream` can be written.

since: 2.28

###### g_pollable_output_stream_write_nonblocking

Attempts to write up to `count` bytes from `buffer` to `stream`, as with g_output_stream_write(). If `stream` is not currently writable, this will immediately return `G_IO_ERROR_WOULD_BLOCK`, and you can use `g_pollable_output_stream_create_source()` to create a `GSource` that will be triggered when `stream` is writable.

since: 2.0

###### g_pollable_output_stream_writev_nonblocking

Attempts to write the bytes contained in the `n_vectors` `vectors` to `stream`, as with g_output_stream_writev(). If `stream` is not currently writable, this will immediately return %`G_POLLABLE_RETURN_WOULD_BLOCK`, and you can use `g_pollable_output_stream_create_source()` to create a `GSource` that will be triggered when `stream` is writable. `error` will not be set in that case.

since: 2.60

#### Interface structure

    struct GioPollableOutputStreamInterface {
      GTypeInterface g_iface;
      gboolean (* can_poll) (
        GPollableOutputStream* stream
      );
      gboolean (* is_writable) (
        GPollableOutputStream* stream
      );
      GSource* (* create_source) (
        GPollableOutputStream* stream,
        GCancellable* cancellable
      );
      gssize (* write_nonblocking) (
        GPollableOutputStream* stream,
        void* buffer,
        gsize count,
        GError** error
      );
      GPollableReturn (* writev_nonblocking) (
        GPollableOutputStream* stream,
        const GOutputVector* vectors,
        gsize n_vectors,
        gsize* bytes_written,
        GError** error
      );

    }

The interface for pollable output streams.

The default implementation of `can_poll` always returns `TRUE`.

The default implementation of `write_nonblocking` calls g_pollable_output_stream_is_writable(), and then calls `g_output_stream_write()` if it returns `TRUE`. This means you only need to override it if it is possible that your `is_writable` implementation may return `TRUE` when the stream is not actually writable.

The default implementation of `writev_nonblocking` calls `g_pollable_output_stream_write_nonblocking()` for each vector, and converts its return value and error (if set) to a `GPollableReturn`. You should override this where possible to avoid having to allocate a `GError` to return `G_IO_ERROR_WOULD_BLOCK`.

###### Interface members

`g_iface` |
    GTypeInterface
| The parent interface.
`can_poll` |
    gboolean (* can_poll) (
        GPollableOutputStream* stream
      )
| Checks if the `GPollableOutputStream` instance is actually pollable.
`is_writable` |
    gboolean (* is_writable) (
        GPollableOutputStream* stream
      )
| Checks if the stream is writable.
`create_source` |
    GSource* (* create_source) (
        GPollableOutputStream* stream,
        GCancellable* cancellable
      )
| Creates a `GSource` to poll the stream.
`write_nonblocking` |
    gssize (* write_nonblocking) (
        GPollableOutputStream* stream,
        void* buffer,
        gsize count,
        GError** error
      )
| Does a non-blocking write or returns `G_IO_ERROR_WOULD_BLOCK`.
`writev_nonblocking` |
    GPollableReturn (* writev_nonblocking) (
        GPollableOutputStream* stream,
        const GOutputVector* vectors,
        gsize n_vectors,
        gsize* bytes_written,
        GError** error
      )
| Does a vectored non-blocking write, or returns `G_POLLABLE_RETURN_WOULD_BLOCK`.

#### Virtual methods

###### Gio.PollableOutputStream.can_poll

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

since: 2.28

###### Gio.PollableOutputStream.create_source

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

since: 2.28

###### Gio.PollableOutputStream.is_writable

Checks if `stream` can be written.

since: 2.28

###### Gio.PollableOutputStream.write_nonblocking

Attempts to write up to `count` bytes from `buffer` to `stream`, as with g_output_stream_write(). If `stream` is not currently writable, this will immediately return `G_IO_ERROR_WOULD_BLOCK`, and you can use `g_pollable_output_stream_create_source()` to create a `GSource` that will be triggered when `stream` is writable.

since: 2.0

###### Gio.PollableOutputStream.writev_nonblocking

Attempts to write the bytes contained in the `n_vectors` `vectors` to `stream`, as with g_output_stream_writev(). If `stream` is not currently writable, this will immediately return %`G_POLLABLE_RETURN_WOULD_BLOCK`, and you can use `g_pollable_output_stream_create_source()` to create a `GSource` that will be triggered when `stream` is writable. `error` will not be set in that case.

since: 2.60