Copyright | (c) The University of Glasgow 1994-2008 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | libraries@haskell.org |
Stability | internal |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Type classes for I/O providers.
- class RawIO a where
- class IODevice a where
- data IODeviceType
- data SeekMode
Documentation
A low-level I/O provider where the data is bytes in memory.
read :: a -> Ptr Word8 -> Int -> IO Int #
Read up to the specified number of bytes, returning the number of bytes actually read. This function should only block if there is no data available. If there is not enough data available, then the function should just return the available data. A return value of zero indicates that the end of the data stream (e.g. end of file) has been reached.
readNonBlocking :: a -> Ptr Word8 -> Int -> IO (Maybe Int) #
Read up to the specified number of bytes, returning the number
of bytes actually read, or Nothing
if the end of the stream has
been reached.
write :: a -> Ptr Word8 -> Int -> IO () #
Write the specified number of bytes.
writeNonBlocking :: a -> Ptr Word8 -> Int -> IO Int #
Write up to the specified number of bytes without blocking. Returns the actual number of bytes written.
I/O operations required for implementing a Handle
.
ready :: a -> Bool -> Int -> IO Bool #
ready dev write msecs
returns True
if the device has data
to read (if write
is False
) or space to write new data (if
write
is True
). msecs
specifies how long to wait, in
milliseconds.
closes the device. Further operations on the device should produce exceptions.
isTerminal :: a -> IO Bool #
returns True
if the device is a terminal or console.
isSeekable :: a -> IO Bool #
seek :: a -> SeekMode -> Integer -> IO () #
seek to the specified position in the data.
return the current position in the data.
return the size of the data.
setSize :: a -> Integer -> IO () #
change the size of the data.
setEcho :: a -> Bool -> IO () #
for terminal devices, changes whether characters are echoed on the device.
returns the current echoing status.
setRaw :: a -> Bool -> IO () #
some devices (e.g. terminals) support a "raw" mode where characters entered are immediately made available to the program. If available, this operations enables raw mode.
devType :: a -> IO IODeviceType #
returns the IODeviceType
corresponding to this device.
duplicates the device, if possible. The new device is expected
to share a file pointer with the original device (like Unix dup
).
dup2 source target
replaces the target device with the source
device. The target device is closed first, if necessary, and then
it is made into a duplicate of the first device (like Unix dup2
).
data IODeviceType #
Type of a device that can be used to back a
Handle
(see also mkFileHandle
). The
standard libraries provide creation of Handle
s via
Posix file operations with file descriptors (see
mkHandleFromFD
) with FD being the underlying
IODevice
instance.
Users may provide custom instances of IODevice
which are expected to conform the following rules:
Directory | The standard libraries do not have direct support
for this device type, but a user implementation is
expected to provide a list of file names in
the directory, in any order, separated by |
Stream | A duplex communications channel (results in
creation of a duplex |
RegularFile | A file that may be read or written, and also may be seekable. |
RawDevice | A "raw" (disk) device which supports block binary read and write operations and may be seekable only to positions of certain granularity (block- aligned). |
A mode that determines the effect of hSeek
hdl mode i
.
AbsoluteSeek | the position of |
RelativeSeek | the position of |
SeekFromEnd | the position of |