| Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
|---|---|
| License | LGPL-2.1 |
| Maintainer | Iñaki García Etxebarria |
| Safe Haskell | None |
| Language | Haskell2010 |
GI.Gio.Interfaces.PollableInputStream
Description
PollableInputStream is implemented by GInputStreams that
can be polled for readiness to read. This can be used when
interfacing with a non-GIO API that expects
UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
Since: 2.28
Synopsis
- newtype PollableInputStream = PollableInputStream (ManagedPtr PollableInputStream)
- noPollableInputStream :: Maybe PollableInputStream
- class (GObject o, IsDescendantOf PollableInputStream o) => IsPollableInputStream o
- toPollableInputStream :: (MonadIO m, IsPollableInputStream o) => o -> m PollableInputStream
- pollableInputStreamCanPoll :: (HasCallStack, MonadIO m, IsPollableInputStream a) => a -> m Bool
- pollableInputStreamCreateSource :: (HasCallStack, MonadIO m, IsPollableInputStream a, IsCancellable b) => a -> Maybe b -> m Source
- pollableInputStreamIsReadable :: (HasCallStack, MonadIO m, IsPollableInputStream a) => a -> m Bool
- pollableInputStreamReadNonblocking :: (HasCallStack, MonadIO m, IsPollableInputStream a, IsCancellable b) => a -> Maybe ByteString -> Maybe b -> m Int64
Exported types
newtype PollableInputStream Source #
Memory-managed wrapper type.
Constructors
| PollableInputStream (ManagedPtr PollableInputStream) |
Instances
| Eq PollableInputStream Source # | |
Defined in GI.Gio.Interfaces.PollableInputStream Methods (==) :: PollableInputStream -> PollableInputStream -> Bool # (/=) :: PollableInputStream -> PollableInputStream -> Bool # | |
| GObject PollableInputStream Source # | |
Defined in GI.Gio.Interfaces.PollableInputStream Methods gobjectType :: IO GType # | |
| IsGValue PollableInputStream Source # | Convert |
Defined in GI.Gio.Interfaces.PollableInputStream Methods toGValue :: PollableInputStream -> IO GValue # fromGValue :: GValue -> IO PollableInputStream # | |
| HasParentTypes PollableInputStream Source # | |
Defined in GI.Gio.Interfaces.PollableInputStream | |
| type ParentTypes PollableInputStream Source # | |
Defined in GI.Gio.Interfaces.PollableInputStream | |
noPollableInputStream :: Maybe PollableInputStream Source #
A convenience alias for Nothing :: Maybe PollableInputStream.
class (GObject o, IsDescendantOf PollableInputStream o) => IsPollableInputStream o Source #
Type class for types which can be safely cast to PollableInputStream, for instance with toPollableInputStream.
Instances
| (GObject o, IsDescendantOf PollableInputStream o) => IsPollableInputStream o Source # | |
Defined in GI.Gio.Interfaces.PollableInputStream | |
toPollableInputStream :: (MonadIO m, IsPollableInputStream o) => o -> m PollableInputStream Source #
Cast to PollableInputStream, for types for which this is known to be safe. For general casts, use castTo.
Methods
Overloaded methods
canPoll
pollableInputStreamCanPoll Source #
Arguments
| :: (HasCallStack, MonadIO m, IsPollableInputStream a) | |
| => a |
|
| -> m Bool |
Checks if stream is actually pollable. Some classes may implement
PollableInputStream but have only certain instances of that class
be pollable. If this method returns False, then the behavior of
other PollableInputStream methods is undefined.
For any given stream, the value returned by this method is constant; a stream cannot switch from pollable to non-pollable or vice versa.
Since: 2.28
createSource
pollableInputStreamCreateSource Source #
Arguments
| :: (HasCallStack, MonadIO m, IsPollableInputStream a, IsCancellable b) | |
| => a |
|
| -> Maybe b |
|
| -> m Source | Returns: a new |
Creates a Source that triggers when stream can be read, or
cancellable is triggered or an error occurs. The callback on the
source is of the PollableSourceFunc type.
As with pollableInputStreamIsReadable, it is possible that
the stream may not actually be readable even after the source
triggers, so you should use pollableInputStreamReadNonblocking
rather than inputStreamRead from the callback.
Since: 2.28
isReadable
pollableInputStreamIsReadable Source #
Arguments
| :: (HasCallStack, MonadIO m, IsPollableInputStream a) | |
| => a |
|
| -> m Bool | Returns: |
Checks if stream can be read.
Note that some stream types may not be able to implement this 100%
reliably, and it is possible that a call to inputStreamRead
after this returns True would still block. To guarantee
non-blocking behavior, you should always use
pollableInputStreamReadNonblocking, which will return a
IOErrorEnumWouldBlock error rather than blocking.
Since: 2.28
readNonblocking
pollableInputStreamReadNonblocking Source #
Arguments
| :: (HasCallStack, MonadIO m, IsPollableInputStream a, IsCancellable b) | |
| => a |
|
| -> Maybe ByteString |
|
| -> Maybe b |
|
| -> m Int64 | Returns: the number of bytes read, or -1 on error (including
|
Attempts to read up to count bytes from stream into buffer, as
with inputStreamRead. If stream is not currently readable,
this will immediately return IOErrorEnumWouldBlock, and you can
use pollableInputStreamCreateSource to create a Source
that will be triggered when stream is readable.
Note that since this method never blocks, you cannot actually
use cancellable to cancel it. However, it will return an error
if cancellable has already been cancelled when you call, which
may happen if you call this method after a source triggers due
to having been cancelled.