IOStream
Added in version 2.22.
Superclasses: Object
Subclasses: FileIOStream
, SimpleIOStream
, SocketConnection
, TlsConnection
- Constructors:
IOStream(**properties)
Methods
- class IOStream
-
- close(cancellable: Cancellable | None = None) 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
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
CLOSED
for 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 NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorCANCELLED
will 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.
Added in version 2.22.
- Parameters:
cancellable – optional
Cancellable
object,None
to ignore
- close_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished
callback
will be called. You can then callclose_finish()
to get the result of the operation.For behaviour details see
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.
Added in version 2.22.
- Parameters:
io_priority – the io priority of the request
cancellable – optional cancellable object
callback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- close_finish(result: AsyncResult) bool
Closes a stream.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
- get_input_stream() InputStream
Gets the input stream for this object. This is used for reading.
Added in version 2.22.
- get_output_stream() OutputStream
Gets the output stream for this object. This is used for writing.
Added in version 2.22.
- set_pending() bool
Sets
stream
to have actions pending. If the pending flag is already set orstream
is closed, it will returnFalse
and seterror
.Added in version 2.22.
- splice_async(stream2: IOStream, flags: IOStreamSpliceFlags, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
Asynchronously splice the output stream of
stream1
to the input stream ofstream2
, and splice the output stream ofstream2
to the input stream ofstream1
.When the operation is finished
callback
will be called. You can then callsplice_finish()
to get the result of the operation.Added in version 2.28.
- Parameters:
stream2 – a
IOStream
.flags – a set of
IOStreamSpliceFlags
.io_priority – the io priority of the request.
cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- splice_finish(result: AsyncResult) bool
Finishes an asynchronous io stream splice operation.
Added in version 2.28.
- Parameters:
result – a
AsyncResult
.
Properties
- class IOStream
-
- props.input_stream: InputStream
The
InputStream
to read from.Added in version 2.22.
- props.output_stream: OutputStream
The
OutputStream
to write to.Added in version 2.22.
Virtual Methods
- class IOStream
- do_close_async(io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished
callback
will be called. You can then callclose_finish()
to get the result of the operation.For behaviour details see
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.
Added in version 2.22.
- Parameters:
io_priority – the io priority of the request
cancellable – optional cancellable object
callback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- do_close_finish(result: AsyncResult) bool
Closes a stream.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
- do_close_fn(cancellable: Cancellable | None = None) bool
- Parameters:
cancellable
- do_get_input_stream() InputStream
Gets the input stream for this object. This is used for reading.
Added in version 2.22.
- do_get_output_stream() OutputStream
Gets the output stream for this object. This is used for writing.
Added in version 2.22.