Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (inaki@blueleaf.cc) |
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 IOStream
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 IOStream
object owns the input and the output streams, not the other
way around, so keeping the substreams alive will not keep the IOStream
object alive. If the IOStream
object is freed it will be closed, thus
closing the substreams, so even if the substreams stay alive they will
always return IOErrorEnumClosed
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
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 GIOStreams
cannot be started while another operation on the
IOStream
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 IOStream
operation while there
is a IOStream
, InputStream
or OutputStream
operation in progress, and
an application can’t start any InputStream
or OutputStream
operation
while there is a IOStream
operation in progress.
This is a product of individual stream operations being associated with a
given MainContext
(the thread-default context at the time the operation was
started), rather than entire streams being associated with a single
MainContext
.
GIO may run operations on GIOStreams
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
- noIOStream :: Maybe 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
GObject IOStream Source # | |
Defined in GI.Gio.Objects.IOStream gobjectType :: IO GType # | |
HasParentTypes IOStream Source # | |
Defined in GI.Gio.Objects.IOStream | |
type ParentTypes IOStream Source # | |
Defined in GI.Gio.Objects.IOStream |
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
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 () |
Asyncronously 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
No description available in the introspection data.
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
No description available in the introspection data.
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
No description available in the introspection data.
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