gi-gio-2.0.19: Gio bindings

Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com)
Safe Haskell | None
Language | Haskell2010

GI.Gio.Objects.IOStream

Contents

- Exported types
- Methods
  - clearPending
  - close
  - closeAsync
  - closeFinish
  - getInputStream
  - getOutputStream
  - hasPending
  - isClosed
  - setPending
  - spliceAsync
  - spliceFinish
- Properties
  - closed
  - inputStream
  - outputStream

Description

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 => 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

newtype IOStream Source #

Memory-managed wrapper type.

Constructors

IOStream (ManagedPtr IOStream) |

Instances

GObject IOStream Source # |
Instance details Defined in GI.Gio.Objects.IOStream Methods gobjectType :: IOStream -> IO GType Source #
IsObject IOStream Source # |
Instance details Defined in GI.Gio.Objects.IOStream
IsIOStream IOStream Source # |
Instance details Defined in GI.Gio.Objects.IOStream

class GObject o => IsIOStream o Source #

Type class for types which can be safely cast to `IOStream`, for instance with `toIOStream`.

Instances

(GObject a, (UnknownAncestorError IOStream a :: Constraint)) => IsIOStream a Source # |
Instance details Defined in GI.Gio.Objects.IOStream
IsIOStream FileIOStream Source # |
Instance details Defined in GI.Gio.Objects.FileIOStream
IsIOStream IOStream Source # |
Instance details Defined in GI.Gio.Objects.IOStream
IsIOStream SimpleIOStream Source # |
Instance details Defined in GI.Gio.Objects.SimpleIOStream
IsIOStream SocketConnection Source # |
Instance details Defined in GI.Gio.Objects.SocketConnection
IsIOStream TcpConnection Source # |
Instance details Defined in GI.Gio.Objects.TcpConnection
IsIOStream TcpWrapperConnection Source # |
Instance details Defined in GI.Gio.Objects.TcpWrapperConnection
IsIOStream TlsConnection Source # |
Instance details Defined in GI.Gio.Objects.TlsConnection
IsIOStream TlsServerConnection Source # |
Instance details Defined in GI.Gio.Interfaces.TlsServerConnection
IsIOStream TlsClientConnection Source # |
Instance details Defined in GI.Gio.Interfaces.TlsClientConnection
IsIOStream UnixConnection Source # |
Instance details Defined in GI.Gio.Objects.UnixConnection

toIOStream :: (MonadIO m, IsIOStream o) => o -> m IOStream Source #

Cast to `IOStream`, for types for which this is known to be safe. For general casts, use `castTo`.

noIOStream :: Maybe IOStream Source #

A convenience alias for `Nothing` :: `Maybe` `IOStream`.

# Methods

## clearPending

iOStreamClearPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m () |

Clears the pending flag on `stream`.

Since: 2.22

## close

iOStreamClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) |
=> a | `stream`: a `IOStream`
-> Maybe b | `cancellable`: optional `Cancellable` object, `Nothing` to ignore
-> m () | (Can throw `GError`)

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

iOStreamCloseAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsCancellable b) |
=> a | `stream`: a `IOStream`
-> Int32 | `ioPriority`: the io priority of the request
-> Maybe b | `cancellable`: optional cancellable object
-> Maybe AsyncReadyCallback | `callback`: callback to call when the request is satisfied
-> 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

iOStreamCloseFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsAsyncResult b) |
=> a | `stream`: a `IOStream`
-> b | `result`: a `AsyncResult`
-> m () | (Can throw `GError`)

Closes a stream.

Since: 2.22

## getInputStream

iOStreamGetInputStream Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m InputStream | Returns: a `InputStream`, owned by the `IOStream`. Do not free.

Gets the input stream for this object. This is used for reading.

Since: 2.22

## getOutputStream

iOStreamGetOutputStream Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m OutputStream | Returns: a `OutputStream`, owned by the `IOStream`. Do not free.

Gets the output stream for this object. This is used for writing.

Since: 2.22

## hasPending

iOStreamHasPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m Bool | Returns: `True` if `stream` has pending actions.

Checks if a stream has pending actions.

Since: 2.22

## isClosed

iOStreamIsClosed Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m Bool | Returns: `True` if the stream is closed.

Checks if a stream is closed.

Since: 2.22

## setPending

iOStreamSetPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a) |
=> a | `stream`: a `IOStream`
-> m () | (Can throw `GError`)

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

iOStreamSpliceAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsIOStream b, IsCancellable c) |
=> a | `stream1`: a `IOStream`.
-> b | `stream2`: a `IOStream`.
-> [IOStreamSpliceFlags] | `flags`: a set of `IOStreamSpliceFlags`.
-> Int32 | `ioPriority`: the io priority of the request.
-> Maybe c | `cancellable`: optional `Cancellable` object, `Nothing` to ignore.
-> Maybe AsyncReadyCallback | `callback`: a `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

iOStreamSpliceFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsAsyncResult a) |
=> a | `result`: a `AsyncResult`.
-> m () | (Can throw `GError`)

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