gio.iostream

Module for [IOStream] class

Types 3

[gio.iostream.IOStream] represents an object that has both read and write streams. Generally the two streams act as separate input and output streams, but they share some common resources and state. For instance, for seekable streams, both streams may use the same position.

Examples of [gio.iostream.IOStream] objects are [gio.socket_connection.SocketConnection], which represents a two-way network connection; and [gio.file_iostream.FileIOStream], which represents a file handle opened in read-write mode.

To do the actual reading and writing you need to get the substreams with [gio.iostream.IOStream.getInputStream] and [gio.iostream.IOStream.getOutputStream].

The [gio.iostream.IOStream] object owns the input and the output streams, not the other way around, so keeping the substreams alive will not keep the [gio.iostream.IOStream] object alive. If the [gio.iostream.IOStream] object is freed it will be closed, thus closing the substreams, so even if the substreams stay alive they will always return [gio.types.IOErrorEnum.Closed] for all operations.

To close a stream use [gio.iostream.IOStream.close] which will close the common stream object and also the individual substreams. You can also close the substreams themselves. In most cases this only marks the substream as closed, so further I/O on it fails but common state in the [gio.iostream.IOStream] may still be open. However, some streams may support ‘half-closed’ states where one direction of the stream is actually shut down.

Operations on [gio.iostream.IOStream]s cannot be started while another operation on the [gio.iostream.IOStream] or its substreams is in progress. Specifically, an application can read from the [gio.input_stream.InputStream] and write to the [gio.output_stream.OutputStream] simultaneously (either in separate threads, or as asynchronous operations in the same thread), but an application cannot start any [gio.iostream.IOStream] operation while there is a [gio.iostream.IOStream], [gio.input_stream.InputStream] or [gio.output_stream.OutputStream] operation in progress, and an application can’t start any [gio.input_stream.InputStream] or [gio.output_stream.OutputStream] operation while there is a [gio.iostream.IOStream] operation in progress.

This is a product of individual stream operations being associated with a given [glib.main_context.MainContext] (the thread-default context at the time the operation was started), rather than entire streams being associated with a single [glib.main_context.MainContext].

GIO may run operations on [gio.iostream.IOStream]s from other (worker) threads, and this may be exposed to application code in the behaviour of wrapper streams, such as [gio.buffered_input_stream.BufferedInputStream] or [gio.tls_connection.TlsConnection]. With such wrapper APIs, application code may only run operations on the base (wrapped) stream when the wrapper stream is idle. Note that the semantics of such operations may not be well-defined due to the state the wrapper stream leaves the base stream in (though they are guaranteed not to crash).

Methods
GType _gType() @property
IOStream self()Returns `this`, for use in `with` statements.
IOStreamGidBuilder builder()Get builder for [gio.iostream.IOStream] Returns: New builder object
bool closed() @propertyGet `closed` property. Returns: Whether the stream is closed.
gio.input_stream.InputStream inputStream() @propertyGet `inputStream` property. Returns: The [gio.input_stream.InputStream] to read from.
gio.output_stream.OutputStream outputStream() @propertyGet `outputStream` property. Returns: The [gio.output_stream.OutputStream] to write to.
bool spliceFinish(gio.async_result.AsyncResult result)Finishes an asynchronous io stream splice operation.
void clearPending()Clears the pending flag on stream.
bool close(gio.cancellable.Cancellable cancellable = null)Closes the stream, releasing resources related to it. This will also close the individual input and output streams, if they are not already closed.
void closeAsync(int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call [gio.iostream.IOStream.closeFinish] to get...
bool closeFinish(gio.async_result.AsyncResult result)Closes a stream.
gio.input_stream.InputStream getInputStream()Gets the input stream for this object. This is used for reading. Returns: a #GInputStream, owned by the #GIOStream. Do not free.
gio.output_stream.OutputStream getOutputStream()Gets the output stream for this object. This is used for writing. Returns: a #GOutputStream, owned by the #GIOStream. Do not free.
bool hasPending()Checks if a stream has pending actions. Returns: true if stream has pending actions.
bool isClosed()Checks if a stream is closed. Returns: true if the stream is closed.
bool setPending()Sets stream to have actions pending. If the pending flag is already set or stream is closed, it will return false and set error. Returns: true if pending was previously unset and is now set. Throws...
void spliceAsync(gio.iostream.IOStream stream2, gio.types.IOStreamSpliceFlags flags, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Asynchronously splice the output stream of stream1 to the input stream of stream2, and splice the output stream of stream2 to the input stream of stream1.
Constructors
this(void * ptr, Flag!"Take" take)

Fluent builder for [gio.iostream.IOStream]

Methods