Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
GIOStream
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 GIOStream
objects are SocketConnection
, which represents
a two-way network connection; and 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 iOStreamGetInputStream
and
iOStreamGetOutputStream
.
The GIOStream
object owns the input and the output streams, not the other
way around, so keeping the substreams alive will not keep the GIOStream
object alive. If the GIOStream
object is freed it will be closed, thus
closing the substreams, so even if the substreams stay alive they will
always return G_IO_ERROR_CLOSED
for all operations.
To close a stream use iOStreamClose
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
GIOStream
may still be open. However, some streams may support
‘half-closed’ states where one direction of the stream is actually shut down.
Operations on GIOStream
s cannot be started while another operation on the
GIOStream
or its substreams is in progress. Specifically, an application can
read from the InputStream
and write to the
OutputStream
simultaneously (either in separate threads, or as
asynchronous operations in the same thread), but an application cannot start
any GIOStream
operation while there is a GIOStream
, GInputStream
or
GOutputStream
operation in progress, and an application can’t start any
GInputStream
or GOutputStream
operation while there is a GIOStream
operation in progress.
This is a product of individual stream operations being associated with a
given [typegLib
.MainContext] (the thread-default context at the time the
operation was started), rather than entire streams being associated with a
single GMainContext
.
GIO may run operations on GIOStream
s from other (worker) threads, and this
may be exposed to application code in the behaviour of wrapper streams, such
as BufferedInputStream
or 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).
Since: 2.22
Synopsis
- newtype IOStream = IOStream (ManagedPtr IOStream)
- class (GObject o, IsDescendantOf IOStream o) => IsIOStream o
- toIOStream :: (MonadIO m, IsIOStream o) => o -> m IOStream
- iOStreamClearPending :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m ()
- iOStreamClose :: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) => a -> Maybe b -> m ()
- iOStreamCloseAsync :: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) => a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- iOStreamCloseFinish :: (HasCallStack, MonadIO m, IsIOStream a, IsAsyncResult b) => a -> b -> m ()
- iOStreamGetInputStream :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m InputStream
- iOStreamGetOutputStream :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m OutputStream
- iOStreamHasPending :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m Bool
- iOStreamIsClosed :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m Bool
- iOStreamSetPending :: (HasCallStack, MonadIO m, IsIOStream a) => a -> m ()
- iOStreamSpliceAsync :: (HasCallStack, MonadIO m, IsIOStream a, IsIOStream b, IsCancellable c) => a -> b -> [IOStreamSpliceFlags] -> Int32 -> Maybe c -> Maybe AsyncReadyCallback -> m ()
- iOStreamSpliceFinish :: (HasCallStack, MonadIO m, IsAsyncResult a) => a -> m ()
- getIOStreamClosed :: (MonadIO m, IsIOStream o) => o -> m Bool
- getIOStreamInputStream :: (MonadIO m, IsIOStream o) => o -> m InputStream
- getIOStreamOutputStream :: (MonadIO m, IsIOStream o) => o -> m OutputStream
Exported types
Memory-managed wrapper type.
Instances
Eq IOStream Source # | |
GObject IOStream Source # | |
Defined in GI.Gio.Objects.IOStream | |
ManagedPtrNewtype IOStream Source # | |
Defined in GI.Gio.Objects.IOStream toManagedPtr :: IOStream -> ManagedPtr IOStream # | |
TypedObject IOStream Source # | |
Defined in GI.Gio.Objects.IOStream | |
HasParentTypes IOStream Source # | |
Defined in GI.Gio.Objects.IOStream | |
IsGValue (Maybe IOStream) Source # | Convert |
Defined in GI.Gio.Objects.IOStream | |
type ParentTypes IOStream Source # | |
Defined in GI.Gio.Objects.IOStream type ParentTypes IOStream = '[Object] |
class (GObject o, IsDescendantOf IOStream o) => IsIOStream o Source #
Type class for types which can be safely cast to IOStream
, for instance with toIOStream
.
Instances
(GObject o, IsDescendantOf IOStream o) => IsIOStream o Source # | |
Defined in GI.Gio.Objects.IOStream |
toIOStream :: (MonadIO m, IsIOStream o) => o -> m IOStream Source #
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, clearPending, close, closeAsync, closeFinish, forceFloating, freezeNotify, getv, hasPending, isClosed, isFloating, notify, notifyByPspec, ref, refSink, runDispose, spliceAsync, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getData, getInputStream, getOutputStream, getProperty, getQdata.
Setters
clearPending
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m () |
Clears the pending flag on stream
.
Since: 2.22
close
:: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m () | (Can throw |
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
IOErrorEnumClosed
. 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 IOErrorEnumClosed
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 error IOErrorEnumCancelled
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.
Since: 2.22
closeAsync
:: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) | |
=> a |
|
-> Int32 |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
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 iOStreamCloseFinish
to get
the result of the operation.
For behaviour details see iOStreamClose
.
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.
Since: 2.22
closeFinish
:: (HasCallStack, MonadIO m, IsIOStream a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m () | (Can throw |
Closes a stream.
Since: 2.22
getInputStream
iOStreamGetInputStream Source #
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m InputStream | Returns: a |
Gets the input stream for this object. This is used for reading.
Since: 2.22
getOutputStream
iOStreamGetOutputStream Source #
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m OutputStream | Returns: a |
Gets the output stream for this object. This is used for writing.
Since: 2.22
hasPending
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m Bool | Returns: |
Checks if a stream has pending actions.
Since: 2.22
isClosed
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m Bool | Returns: |
Checks if a stream is closed.
Since: 2.22
setPending
:: (HasCallStack, MonadIO m, IsIOStream a) | |
=> a |
|
-> m () | (Can throw |
Sets stream
to have actions pending. If the pending flag is
already set or stream
is closed, it will return False
and set
error
.
Since: 2.22
spliceAsync
:: (HasCallStack, MonadIO m, IsIOStream a, IsIOStream b, IsCancellable c) | |
=> a |
|
-> b |
|
-> [IOStreamSpliceFlags] |
|
-> Int32 |
|
-> Maybe c |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
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
.
When the operation is finished callback
will be called.
You can then call iOStreamSpliceFinish
to get the
result of the operation.
Since: 2.28
spliceFinish
:: (HasCallStack, MonadIO m, IsAsyncResult a) | |
=> a |
|
-> m () | (Can throw |
Finishes an asynchronous io stream splice operation.
Since: 2.28
Properties
closed
Whether the stream is closed.
Since: 2.22
getIOStreamClosed :: (MonadIO m, IsIOStream o) => o -> m Bool Source #
Get the value of the “closed
” property.
When overloading is enabled, this is equivalent to
get
iOStream #closed
inputStream
The InputStream
to read from.
Since: 2.22
getIOStreamInputStream :: (MonadIO m, IsIOStream o) => o -> m InputStream Source #
Get the value of the “input-stream
” property.
When overloading is enabled, this is equivalent to
get
iOStream #inputStream
outputStream
The OutputStream
to write to.
Since: 2.22
getIOStreamOutputStream :: (MonadIO m, IsIOStream o) => o -> m OutputStream Source #
Get the value of the “output-stream
” property.
When overloading is enabled, this is equivalent to
get
iOStream #outputStream