Gio.IOStream¶
| Subclasses: | Gio.FileIOStream,Gio.SimpleIOStream,Gio.SocketConnection,Gio.TlsConnection | 
|---|
Methods¶
| Inherited: | GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| class | splice_finish(result) | 
| clear_pending() | |
| close(cancellable) | |
| close_async(io_priority, cancellable, callback, *user_data) | |
| close_finish(result) | |
| get_input_stream() | |
| get_output_stream() | |
| has_pending() | |
| is_closed() | |
| set_pending() | |
| splice_async(stream2, flags, io_priority, cancellable, callback, *user_data) | 
Virtual Methods¶
| Inherited: | GObject.Object (7) | 
|---|
| do_close_async(io_priority, cancellable, callback, *user_data) | |
| do_close_finish(result) | |
| do_close_fn(cancellable) | |
| do_get_input_stream() | |
| do_get_output_stream() | 
Properties¶
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| closed | bool | r | Is the stream closed | 
| input-stream | Gio.InputStream | r | The Gio.InputStreamto read from | 
| output-stream | Gio.OutputStream | r | The Gio.OutputStreamto write to | 
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
Class Details¶
- 
class Gio.IOStream(**kwargs)¶
- Bases: - GObject.Object- Abstract: - Yes - Structure: - Gio.IOStreamClass- Gio.IOStreamrepresents 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.IOStreamobjects are- Gio.SocketConnection, which represents a two-way network connection; and- Gio.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.get_input_stream() and- Gio.IOStream.get_output_stream().- The - Gio.IOStreamobject owns the input and the output streams, not the other way around, so keeping the substreams alive will not keep the- Gio.IOStreamobject alive. If the- Gio.IOStreamobject is freed it will be closed, thus closing the substreams, so even if the substreams stay alive they will always return- Gio.IOErrorEnum.CLOSEDfor all operations.- To close a stream use - Gio.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.IOStreammay still be open. However, some streams may support “half-closed” states where one direction of the stream is actually shut down.- Operations on - Gio.IOStreamscannot be started while another operation on the- Gio.IOStreamor its substreams is in progress. Specifically, an application can read from the- Gio.InputStreamand write to the- Gio.OutputStreamsimultaneously (either in separate threads, or as asynchronous operations in the same thread), but an application cannot start any- Gio.IOStreamoperation while there is a- Gio.IOStream,- Gio.InputStreamor- Gio.OutputStreamoperation in progress, and an application can’t start any- Gio.InputStreamor- Gio.OutputStreamoperation while there is a- Gio.IOStreamoperation in progress.- This is a product of individual stream operations being associated with a given - GLib.MainContext(the thread-default context at the time the operation was started), rather than entire streams being associated with a single- GLib.MainContext.- GIO may run operations on - Gio.IOStreamsfrom other (worker) threads, and this may be exposed to application code in the behaviour of wrapper streams, such as- Gio.BufferedInputStreamor- Gio.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).- New in version 2.22. - 
classmethod splice_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - Trueon success,- Falseotherwise.- Return type: - bool- Finishes an asynchronous io stream splice operation. - New in version 2.28. 
 - 
close(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore- Raises: - GLib.Error- Returns: - Trueon success,- Falseon failure- Return type: - bool- Closes the stream, releasing resources related to it. This will also close the individual input and output streams, if they are not already closed. - Once the stream is closed, all other operations will return - Gio.IOErrorEnum.CLOSED. Closing a stream multiple times will not return an error.- Closing a stream will automatically flush any outstanding buffers in the stream. - Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. - Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details. - On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return - Gio.IOErrorEnum.CLOSEDfor all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.- If cancellable is not - None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error- Gio.IOErrorEnum.CANCELLEDwill be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn’t block to e.g. check errors.- The default implementation of this method just calls close on the individual input/output streams. - New in version 2.22. 
 - 
close_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - io_priority (int) – the io priority of the request
- cancellable (Gio.CancellableorNone) – optional cancellable object
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - 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.close_finish() to get the result of the operation.- For behaviour details see - Gio.IOStream.close().- 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. - New in version 2.22. 
- io_priority (
 - 
close_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult- Raises: - GLib.Error- Returns: - Trueif stream was successfully closed,- Falseotherwise.- Return type: - bool- Closes a stream. - New in version 2.22. 
 - 
get_input_stream()[source]¶
- Returns: - a - Gio.InputStream, owned by the- Gio.IOStream. Do not free.- Return type: - Gio.InputStream- Gets the input stream for this object. This is used for reading. - New in version 2.22. 
 - 
get_output_stream()[source]¶
- Returns: - a - Gio.OutputStream, owned by the- Gio.IOStream. Do not free.- Return type: - Gio.OutputStream- Gets the output stream for this object. This is used for writing. - New in version 2.22. 
 - 
has_pending()[source]¶
- Returns: - Trueif self has pending actions.- Return type: - bool- Checks if a stream has pending actions. - New in version 2.22. 
 - 
is_closed()[source]¶
- Returns: - Trueif the stream is closed.- Return type: - bool- Checks if a stream is closed. - New in version 2.22. 
 - 
set_pending()[source]¶
- Raises: - GLib.Error- Returns: - Trueif pending was previously unset and is now set.- Return type: - bool- Sets self to have actions pending. If the pending flag is already set or self is closed, it will return - Falseand set error.- New in version 2.22. 
 - 
splice_async(stream2, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters: - stream2 (Gio.IOStream) – aGio.IOStream.
- flags (Gio.IOStreamSpliceFlags) – a set ofGio.IOStreamSpliceFlags.
- io_priority (int) – the io priority of the request.
- cancellable (Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.
- callback (Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallback.
- user_data (objectorNone) – user data passed to callback.
 - Asynchronously splice the output stream of self to the input stream of stream2, and splice the output stream of stream2 to the input stream of self. - When the operation is finished callback will be called. You can then call - Gio.IOStream.splice_finish() to get the result of the operation.- New in version 2.28. 
- stream2 (
 - 
do_close_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters: - io_priority (int) – the io priority of the request
- cancellable (Gio.CancellableorNone) – optional cancellable object
- callback (Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
- user_data (objectorNone) – the data to pass to callback function
 - 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.close_finish() to get the result of the operation.- For behaviour details see - Gio.IOStream.close().- 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. - New in version 2.22. 
- io_priority (
 - 
do_close_finish(result) virtual¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult- Returns: - Trueif stream was successfully closed,- Falseotherwise.- Return type: - bool- Closes a stream. - New in version 2.22. 
 - 
do_close_fn(cancellable) virtual¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) –- Return type: - bool
 - 
do_get_input_stream() virtual¶
- Returns: - a - Gio.InputStream, owned by the- Gio.IOStream. Do not free.- Return type: - Gio.InputStream- Gets the input stream for this object. This is used for reading. - New in version 2.22. 
 - 
do_get_output_stream() virtual¶
- Returns: - a - Gio.OutputStream, owned by the- Gio.IOStream. Do not free.- Return type: - Gio.OutputStream- Gets the output stream for this object. This is used for writing. - New in version 2.22. 
 
- 
classmethod 
Property Details¶
- 
Gio.IOStream.props.closed¶
- Name: - closed- Type: - bool- Default Value: - False- Flags: - READABLE- Is the stream closed 
- 
Gio.IOStream.props.input_stream¶
- Name: - input-stream- Type: - Gio.InputStream- Default Value: - None- Flags: - READABLE- The - Gio.InputStreamto read from
- 
Gio.IOStream.props.output_stream¶
- Name: - output-stream- Type: - Gio.OutputStream- Default Value: - None- Flags: - READABLE- The - Gio.OutputStreamto write to