Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
- Exported types
- Methods
- close
- errorFromErrno
- errorQuark
- flush
- getBufferCondition
- getBufferSize
- getBuffered
- getCloseOnUnref
- getEncoding
- getFlags
- getLineTerm
- init
- newFile
- read
- readChars
- readLine
- readToEnd
- readUnichar
- ref
- seek
- seekPosition
- setBufferSize
- setBuffered
- setCloseOnUnref
- setEncoding
- setFlags
- setLineTerm
- shutdown
- unixGetFd
- unixNew
- unref
- write
- writeChars
- writeUnichar
A data structure representing an IO Channel. The fields should be considered private and should only be accessed with the following functions.
Synopsis
- newtype IOChannel = IOChannel (ManagedPtr IOChannel)
- newZeroIOChannel :: MonadIO m => m IOChannel
- iOChannelClose :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- iOChannelErrorFromErrno :: (HasCallStack, MonadIO m) => Int32 -> m IOChannelError
- iOChannelErrorQuark :: (HasCallStack, MonadIO m) => m Word32
- iOChannelFlush :: (HasCallStack, MonadIO m) => IOChannel -> m IOStatus
- iOChannelGetBufferCondition :: (HasCallStack, MonadIO m) => IOChannel -> m [IOCondition]
- iOChannelGetBufferSize :: (HasCallStack, MonadIO m) => IOChannel -> m Word64
- iOChannelGetBuffered :: (HasCallStack, MonadIO m) => IOChannel -> m Bool
- iOChannelGetCloseOnUnref :: (HasCallStack, MonadIO m) => IOChannel -> m Bool
- iOChannelGetEncoding :: (HasCallStack, MonadIO m) => IOChannel -> m Text
- iOChannelGetFlags :: (HasCallStack, MonadIO m) => IOChannel -> m [IOFlags]
- iOChannelGetLineTerm :: (HasCallStack, MonadIO m) => IOChannel -> Int32 -> m Text
- iOChannelInit :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- iOChannelNewFile :: (HasCallStack, MonadIO m) => [Char] -> Text -> m IOChannel
- iOChannelRead :: (HasCallStack, MonadIO m) => IOChannel -> Text -> Word64 -> Word64 -> m IOError
- iOChannelReadChars :: (HasCallStack, MonadIO m) => IOChannel -> ByteString -> m (IOStatus, ByteString, Word64)
- iOChannelReadLine :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, Text, Word64, Word64)
- iOChannelReadToEnd :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, ByteString)
- iOChannelReadUnichar :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, Char)
- iOChannelRef :: (HasCallStack, MonadIO m) => IOChannel -> m IOChannel
- iOChannelSeek :: (HasCallStack, MonadIO m) => IOChannel -> Int64 -> SeekType -> m IOError
- iOChannelSeekPosition :: (HasCallStack, MonadIO m) => IOChannel -> Int64 -> SeekType -> m IOStatus
- iOChannelSetBufferSize :: (HasCallStack, MonadIO m) => IOChannel -> Word64 -> m ()
- iOChannelSetBuffered :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m ()
- iOChannelSetCloseOnUnref :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m ()
- iOChannelSetEncoding :: (HasCallStack, MonadIO m) => IOChannel -> Maybe Text -> m IOStatus
- iOChannelSetFlags :: (HasCallStack, MonadIO m) => IOChannel -> [IOFlags] -> m IOStatus
- iOChannelSetLineTerm :: (HasCallStack, MonadIO m) => IOChannel -> Maybe Text -> Int32 -> m ()
- iOChannelShutdown :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m IOStatus
- iOChannelUnixGetFd :: (HasCallStack, MonadIO m) => IOChannel -> m Int32
- iOChannelUnixNew :: (HasCallStack, MonadIO m) => Int32 -> m IOChannel
- iOChannelUnref :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- iOChannelWrite :: (HasCallStack, MonadIO m) => IOChannel -> Text -> Word64 -> Word64 -> m IOError
- iOChannelWriteChars :: (HasCallStack, MonadIO m) => IOChannel -> Ptr Word8 -> Int64 -> m (IOStatus, Word64)
- iOChannelWriteUnichar :: (HasCallStack, MonadIO m) => IOChannel -> Char -> m IOStatus
Exported types
Memory-managed wrapper type.
Instances
Eq IOChannel Source # | |
GBoxed IOChannel Source # | |
Defined in GI.GLib.Structs.IOChannel | |
ManagedPtrNewtype IOChannel Source # | |
Defined in GI.GLib.Structs.IOChannel | |
TypedObject IOChannel Source # | |
Defined in GI.GLib.Structs.IOChannel | |
HasParentTypes IOChannel Source # | |
Defined in GI.GLib.Structs.IOChannel | |
tag ~ 'AttrSet => Constructible IOChannel tag Source # | |
Defined in GI.GLib.Structs.IOChannel | |
IsGValue (Maybe IOChannel) Source # | Convert |
Defined in GI.GLib.Structs.IOChannel | |
type ParentTypes IOChannel Source # | |
Defined in GI.GLib.Structs.IOChannel |
newZeroIOChannel :: MonadIO m => m IOChannel Source #
Construct a IOChannel
struct initialized to zero.
Methods
Click to display all available methods, including inherited ones
Methods
close, flush, init, read, readChars, readLine, readToEnd, readUnichar, ref, seek, seekPosition, shutdown, unixGetFd, unref, write, writeChars, writeUnichar.
Getters
getBufferCondition, getBufferSize, getBuffered, getCloseOnUnref, getEncoding, getFlags, getLineTerm.
Setters
setBufferSize, setBuffered, setCloseOnUnref, setEncoding, setFlags, setLineTerm.
close
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m () |
Deprecated: (Since version 2.2)Use iOChannelShutdown
instead.
Close an IO channel. Any pending data to be written will be
flushed, ignoring errors. The channel will not be freed until the
last reference is dropped using iOChannelUnref
.
errorFromErrno
iOChannelErrorFromErrno Source #
:: (HasCallStack, MonadIO m) | |
=> Int32 |
|
-> m IOChannelError | Returns: a |
Converts an errno
error number to a IOChannelError
.
errorQuark
iOChannelErrorQuark :: (HasCallStack, MonadIO m) => m Word32 Source #
No description available in the introspection data.
flush
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m IOStatus | Returns: the status of the operation: One of
|
Flushes the write buffer for the GIOChannel.
getBufferCondition
iOChannelGetBufferCondition Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m [IOCondition] | Returns: A |
This function returns a IOCondition
depending on whether there
is data to be read/space to write data in the internal buffers in
the IOChannel
. Only the flags IOConditionIn
and IOConditionOut
may be set.
getBufferSize
iOChannelGetBufferSize Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Word64 | Returns: the size of the buffer. |
Gets the buffer size.
getBuffered
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Bool | Returns: |
Returns whether channel
is buffered.
getCloseOnUnref
getEncoding
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Text | Returns: A string containing the encoding, this string is owned by GLib and must not be freed. |
Gets the encoding for the input/output of the channel.
The internal encoding is always UTF-8. The encoding Nothing
makes the channel safe for binary data.
getFlags
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m [IOFlags] | Returns: the flags which are set on the channel |
Gets the current flags for a IOChannel
, including read-only
flags such as IOFlagsIsReadable
.
The values of the flags IOFlagsIsReadable
and IOFlagsIsWritable
are cached for internal use by the channel when it is created.
If they should change at some later point (e.g. partial shutdown
of a socket with the UNIX shutdown()
function), the user
should immediately call iOChannelGetFlags
to update
the internal values of these flags.
getLineTerm
init
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m () |
newFile
:: (HasCallStack, MonadIO m) | |
=> [Char] |
|
-> Text |
|
-> m IOChannel | Returns: A |
Open a file filename
as a IOChannel
using mode mode
. This
channel will be closed when the last reference to it is dropped,
so there is no need to call iOChannelClose
(though doing
so will not cause problems, as long as no attempt is made to
access the channel after it is closed).
read
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Text |
|
-> Word64 |
|
-> Word64 |
|
-> m IOError | Returns: |
Deprecated: (Since version 2.2)Use iOChannelReadChars
instead.
Reads data from a IOChannel
.
readChars
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> ByteString |
|
-> m (IOStatus, ByteString, Word64) | Returns: the status of the operation. (Can throw |
Replacement for iOChannelRead
with the new API.
readLine
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m (IOStatus, Text, Word64, Word64) | Returns: the status of the operation. (Can throw |
Reads a line, including the terminating character(s),
from a IOChannel
into a newly-allocated string.
strReturn
will contain allocated memory if the return
is IOStatusNormal
.
readToEnd
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m (IOStatus, ByteString) | Returns: |
Reads all the remaining data from the file.
readUnichar
Reads a Unicode character from channel
.
This function cannot be called on a channel with Nothing
encoding.
ref
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m IOChannel | Returns: the |
Increments the reference count of a IOChannel
.
seek
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Int64 |
|
-> SeekType |
|
-> m IOError | Returns: |
Deprecated: (Since version 2.2)Use iOChannelSeekPosition
instead.
Sets the current position in the IOChannel
, similar to the standard
library function fseek()
.
seekPosition
iOChannelSeekPosition Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Int64 |
|
-> SeekType |
|
-> m IOStatus | Returns: the status of the operation. (Can throw |
Replacement for iOChannelSeek
with the new API.
setBufferSize
iOChannelSetBufferSize Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Word64 |
|
-> m () |
Sets the buffer size.
setBuffered
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Bool |
|
-> m () |
The buffering state can only be set if the channel's encoding
is Nothing
. For any other encoding, the channel must be buffered.
A buffered channel can only be set unbuffered if the channel's
internal buffers have been flushed. Newly created channels or
channels which have returned IOStatusEof
not require such a flush. For write-only channels, a call to
g_io_channel_flush () is sufficient. For all other channels,
the buffers may be flushed by a call to g_io_channel_seek_position ().
This includes the possibility of seeking with seek type SeekTypeCur
and an offset of zero. Note that this means that socket-based
channels cannot be set unbuffered once they have had data
read from them.
On unbuffered channels, it is safe to mix read and write calls from the new and old APIs, if this is necessary for maintaining old code.
The default state of the channel is buffered.
setCloseOnUnref
iOChannelSetCloseOnUnref Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Bool |
|
-> m () |
Whether to close the channel on the final unref of the IOChannel
data structure. The default value of this is True
for channels
created by g_io_channel_new_file (), and False
for all other channels.
Setting this flag to True
for a channel you have already closed
can cause problems when the final reference to the IOChannel
is dropped.
setEncoding
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Maybe Text |
|
-> m IOStatus | Returns: |
Sets the encoding for the input/output of the channel. The internal encoding is always UTF-8. The default encoding for the external file is UTF-8.
The encoding Nothing
is safe to use with binary data.
The encoding can only be set if one of the following conditions is true:
- The channel was just created, and has not been written to or read from yet.
- The channel is write-only.
- The channel is a file, and the file pointer was just repositioned
by a call to
iOChannelSeekPosition
. (This flushes all the internal buffers.) - The current encoding is
Nothing
or UTF-8. - One of the (new API) read functions has just returned
IOStatusEof
(or, in the case ofiOChannelReadToEnd
,IOStatusNormal
). - One of the functions
iOChannelReadChars
oriOChannelReadUnichar
has returnedIOStatusAgain
orIOStatusError
. This may be useful in the case ofConvertErrorIllegalSequence
. Returning one of these statuses fromiOChannelReadLine
,g_io_channel_read_line_string()
, oriOChannelReadToEnd
does not guarantee that the encoding can be changed.
Channels which do not meet one of the above conditions cannot call
iOChannelSeekPosition
with an offset of SeekTypeCur
, and, if
they are "seekable", cannot call iOChannelWriteChars
after
calling one of the API "read" functions.
setFlags
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> [IOFlags] |
|
-> m IOStatus | Returns: the status of the operation. (Can throw |
Sets the (writeable) flags in channel
to (flags
& IOFlagsSetMask
).
setLineTerm
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Maybe Text |
|
-> Int32 |
|
-> m () |
This sets the string that IOChannel
uses to determine
where in the file a line break occurs.
shutdown
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Bool |
|
-> m IOStatus | Returns: the status of the operation. (Can throw |
Close an IO channel. Any pending data to be written will be
flushed if flush
is True
. The channel will not be freed until the
last reference is dropped using iOChannelUnref
.
unixGetFd
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Int32 | Returns: the file descriptor of the |
unixNew
:: (HasCallStack, MonadIO m) | |
=> Int32 |
|
-> m IOChannel | Returns: a new |
Creates a new IOChannel
given a file descriptor. On UNIX systems
this works for plain files, pipes, and sockets.
The returned IOChannel
has a reference count of 1.
The default encoding for IOChannel
is UTF-8. If your application
is reading output from a command using via pipe, you may need to set
the encoding to the encoding of the current locale (see
getCharset
) with the iOChannelSetEncoding
function.
By default, the fd passed will not be closed when the final reference
to the IOChannel
data structure is dropped.
If you want to read raw binary data without interpretation, then
call the iOChannelSetEncoding
function with Nothing
for the
encoding argument.
This function is available in GLib on Windows, too, but you should avoid using it on Windows. The domain of file descriptors and sockets overlap. There is no way for GLib to know which one you mean in case the argument you pass to this function happens to be both a valid file descriptor and socket. If that happens a warning is issued, and GLib assumes that it is the file descriptor you mean.
unref
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m () |
Decrements the reference count of a IOChannel
.
write
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Text |
|
-> Word64 |
|
-> Word64 |
|
-> m IOError | Returns: |
Deprecated: (Since version 2.2)Use iOChannelWriteChars
instead.
Writes data to a IOChannel
.
writeChars
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Ptr Word8 |
|
-> Int64 |
|
-> m (IOStatus, Word64) | Returns: the status of the operation. (Can throw |
Replacement for iOChannelWrite
with the new API.
On seekable channels with encodings other than Nothing
or UTF-8, generic
mixing of reading and writing is not allowed. A call to g_io_channel_write_chars ()
may only be made on a channel from which data has been read in the
cases described in the documentation for g_io_channel_set_encoding ().