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 |
- 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.
- newtype IOChannel = IOChannel (ManagedPtr IOChannel)
- newZeroIOChannel :: MonadIO m => m IOChannel
- noIOChannel :: Maybe IOChannel
- data IOChannelCloseMethodInfo
- iOChannelClose :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- iOChannelErrorFromErrno :: (HasCallStack, MonadIO m) => Int32 -> m IOChannelError
- iOChannelErrorQuark :: (HasCallStack, MonadIO m) => m Word32
- data IOChannelFlushMethodInfo
- iOChannelFlush :: (HasCallStack, MonadIO m) => IOChannel -> m IOStatus
- data IOChannelGetBufferConditionMethodInfo
- iOChannelGetBufferCondition :: (HasCallStack, MonadIO m) => IOChannel -> m [IOCondition]
- data IOChannelGetBufferSizeMethodInfo
- iOChannelGetBufferSize :: (HasCallStack, MonadIO m) => IOChannel -> m Word64
- data IOChannelGetBufferedMethodInfo
- iOChannelGetBuffered :: (HasCallStack, MonadIO m) => IOChannel -> m Bool
- data IOChannelGetCloseOnUnrefMethodInfo
- iOChannelGetCloseOnUnref :: (HasCallStack, MonadIO m) => IOChannel -> m Bool
- data IOChannelGetEncodingMethodInfo
- iOChannelGetEncoding :: (HasCallStack, MonadIO m) => IOChannel -> m Text
- data IOChannelGetFlagsMethodInfo
- iOChannelGetFlags :: (HasCallStack, MonadIO m) => IOChannel -> m [IOFlags]
- data IOChannelGetLineTermMethodInfo
- iOChannelGetLineTerm :: (HasCallStack, MonadIO m) => IOChannel -> Int32 -> m Text
- data IOChannelInitMethodInfo
- iOChannelInit :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- iOChannelNewFile :: (HasCallStack, MonadIO m) => [Char] -> Text -> m IOChannel
- data IOChannelReadMethodInfo
- iOChannelRead :: (HasCallStack, MonadIO m) => IOChannel -> Text -> Word64 -> Word64 -> m IOError
- data IOChannelReadCharsMethodInfo
- iOChannelReadChars :: (HasCallStack, MonadIO m) => IOChannel -> ByteString -> m (IOStatus, ByteString, Word64)
- data IOChannelReadLineMethodInfo
- iOChannelReadLine :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, Text, Word64, Word64)
- data IOChannelReadToEndMethodInfo
- iOChannelReadToEnd :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, ByteString)
- data IOChannelReadUnicharMethodInfo
- iOChannelReadUnichar :: (HasCallStack, MonadIO m) => IOChannel -> m (IOStatus, Char)
- data IOChannelRefMethodInfo
- iOChannelRef :: (HasCallStack, MonadIO m) => IOChannel -> m IOChannel
- data IOChannelSeekMethodInfo
- iOChannelSeek :: (HasCallStack, MonadIO m) => IOChannel -> Int64 -> SeekType -> m IOError
- data IOChannelSeekPositionMethodInfo
- iOChannelSeekPosition :: (HasCallStack, MonadIO m) => IOChannel -> Int64 -> SeekType -> m IOStatus
- data IOChannelSetBufferSizeMethodInfo
- iOChannelSetBufferSize :: (HasCallStack, MonadIO m) => IOChannel -> Word64 -> m ()
- data IOChannelSetBufferedMethodInfo
- iOChannelSetBuffered :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m ()
- data IOChannelSetCloseOnUnrefMethodInfo
- iOChannelSetCloseOnUnref :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m ()
- data IOChannelSetEncodingMethodInfo
- iOChannelSetEncoding :: (HasCallStack, MonadIO m) => IOChannel -> Maybe Text -> m IOStatus
- data IOChannelSetFlagsMethodInfo
- iOChannelSetFlags :: (HasCallStack, MonadIO m) => IOChannel -> [IOFlags] -> m IOStatus
- data IOChannelSetLineTermMethodInfo
- iOChannelSetLineTerm :: (HasCallStack, MonadIO m) => IOChannel -> Maybe Text -> Int32 -> m ()
- data IOChannelShutdownMethodInfo
- iOChannelShutdown :: (HasCallStack, MonadIO m) => IOChannel -> Bool -> m IOStatus
- data IOChannelUnixGetFdMethodInfo
- iOChannelUnixGetFd :: (HasCallStack, MonadIO m) => IOChannel -> m Int32
- iOChannelUnixNew :: (HasCallStack, MonadIO m) => Int32 -> m IOChannel
- data IOChannelUnrefMethodInfo
- iOChannelUnref :: (HasCallStack, MonadIO m) => IOChannel -> m ()
- data IOChannelWriteMethodInfo
- iOChannelWrite :: (HasCallStack, MonadIO m) => IOChannel -> Text -> Word64 -> Word64 -> m IOError
- data IOChannelWriteCharsMethodInfo
- iOChannelWriteChars :: (HasCallStack, MonadIO m) => IOChannel -> Ptr Word8 -> Int64 -> m (IOStatus, Word64)
- data IOChannelWriteUnicharMethodInfo
- iOChannelWriteUnichar :: (HasCallStack, MonadIO m) => IOChannel -> Char -> m IOStatus
Exported types
newZeroIOChannel :: MonadIO m => m IOChannel Source #
Construct a IOChannel
struct initialized to zero.
Methods
close
data IOChannelCloseMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * IOChannelCloseMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelFlushMethodInfo Source #
((~) * signature (m IOStatus), MonadIO m) => MethodInfo * IOChannelFlushMethodInfo IOChannel signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m IOStatus | Returns: the status of the operation: One of
|
Flushes the write buffer for the GIOChannel.
getBufferCondition
data IOChannelGetBufferConditionMethodInfo Source #
((~) * signature (m [IOCondition]), MonadIO m) => MethodInfo * IOChannelGetBufferConditionMethodInfo IOChannel signature Source # | |
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
data IOChannelGetBufferSizeMethodInfo Source #
((~) * signature (m Word64), MonadIO m) => MethodInfo * IOChannelGetBufferSizeMethodInfo IOChannel signature Source # | |
iOChannelGetBufferSize Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Word64 | Returns: the size of the buffer. |
Gets the buffer size.
getBuffered
data IOChannelGetBufferedMethodInfo Source #
((~) * signature (m Bool), MonadIO m) => MethodInfo * IOChannelGetBufferedMethodInfo IOChannel signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Bool | Returns: |
Returns whether channel
is buffered.
getCloseOnUnref
data IOChannelGetCloseOnUnrefMethodInfo Source #
((~) * signature (m Bool), MonadIO m) => MethodInfo * IOChannelGetCloseOnUnrefMethodInfo IOChannel signature Source # | |
iOChannelGetCloseOnUnref Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m Bool | Returns: Whether the channel will be closed on the final unref of the GIOChannel data structure. |
getEncoding
data IOChannelGetEncodingMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * IOChannelGetEncodingMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelGetFlagsMethodInfo Source #
((~) * signature (m [IOFlags]), MonadIO m) => MethodInfo * IOChannelGetFlagsMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelGetLineTermMethodInfo Source #
((~) * signature (Int32 -> m Text), MonadIO m) => MethodInfo * IOChannelGetLineTermMethodInfo IOChannel signature Source # | |
init
data IOChannelInitMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * IOChannelInitMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelReadCharsMethodInfo Source #
((~) * signature (ByteString -> m (IOStatus, ByteString, Word64)), MonadIO m) => MethodInfo * IOChannelReadCharsMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelReadToEndMethodInfo Source #
((~) * signature (m (IOStatus, ByteString)), MonadIO m) => MethodInfo * IOChannelReadToEndMethodInfo IOChannel signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> m (IOStatus, ByteString) | Returns: |
Reads all the remaining data from the file.
readUnichar
data IOChannelReadUnicharMethodInfo Source #
((~) * signature (m (IOStatus, Char)), MonadIO m) => MethodInfo * IOChannelReadUnicharMethodInfo IOChannel signature Source # | |
Reads a Unicode character from channel
.
This function cannot be called on a channel with Nothing
encoding.
ref
data IOChannelRefMethodInfo Source #
((~) * signature (m IOChannel), MonadIO m) => MethodInfo * IOChannelRefMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelSetBufferSizeMethodInfo Source #
((~) * signature (Word64 -> m ()), MonadIO m) => MethodInfo * IOChannelSetBufferSizeMethodInfo IOChannel signature Source # | |
iOChannelSetBufferSize Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Word64 |
|
-> m () |
Sets the buffer size.
setBuffered
data IOChannelSetBufferedMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m) => MethodInfo * IOChannelSetBufferedMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelSetCloseOnUnrefMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m) => MethodInfo * IOChannelSetCloseOnUnrefMethodInfo IOChannel signature Source # | |
iOChannelSetCloseOnUnref Source #
:: (HasCallStack, MonadIO m) | |
=> IOChannel |
|
-> Bool |
|
-> m () |
Setting this flag to True
for a channel you have already closed
can cause problems.
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
data IOChannelSetFlagsMethodInfo Source #
((~) * signature ([IOFlags] -> m IOStatus), MonadIO m) => MethodInfo * IOChannelSetFlagsMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelShutdownMethodInfo Source #
((~) * signature (Bool -> m IOStatus), MonadIO m) => MethodInfo * IOChannelShutdownMethodInfo IOChannel signature Source # | |
:: (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
data IOChannelUnixGetFdMethodInfo Source #
((~) * signature (m Int32), MonadIO m) => MethodInfo * IOChannelUnixGetFdMethodInfo IOChannel signature Source # | |
:: (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.
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
data IOChannelUnrefMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * IOChannelUnrefMethodInfo IOChannel signature Source # | |
:: (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 ().
writeUnichar
data IOChannelWriteUnicharMethodInfo Source #
((~) * signature (Char -> m IOStatus), MonadIO m) => MethodInfo * IOChannelWriteUnicharMethodInfo IOChannel signature Source # | |