Virtual Method



write_async (
  GOutputStream* stream,
  void* buffer,
  gsize count,
  int io_priority,
  GCancellable* cancellable,
  GAsyncReadyCallback callback,
  gpointer user_data


Request an asynchronous write of count bytes from buffer into the stream. When the operation is finished callback will be called. You can then call g_output_stream_write_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in G_IO_ERROR_PENDING errors.

A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.

On success, the number of bytes written will be passed to the callback. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

You are guaranteed that this method will never fail with G_IO_ERROR_WOULD_BLOCK - if stream can’t accept more data, the method will just wait until this changes.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is G_PRIORITY_DEFAULT.

The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see g_output_stream_write().

Note that no copy of buffer will be made, so it must stay valid until callback is called. See g_output_stream_write_bytes_async() for a GBytes version that will automatically hold a reference to the contents (without copying) for the duration of the call.



Type: An array of guint8

The buffer containing the data to write.

The argument can be NULL.
The length of the array is specified in the count argument.
The data is owned by the caller of the function.

Type: gsize

The number of bytes to write.


Type: int

The io priority of the request.


Type: GCancellable

Optional GCancellable object, NULL to ignore.

The argument can be NULL.
The data is owned by the caller of the function.

Type: GAsyncReadyCallback

A GAsyncReadyCallback to call when the request is satisfied.


Type: gpointer

The data to pass to callback function.

The argument can be NULL.
The data is owned by the caller of the function.