Control.Concurrent.Mailbox.Wrapper
Contents
Description
This module provides a wrapping mechanism for file handles (e.g. sockets)
- class Wrappable m where
- toString :: m -> String
- fromString :: String -> Maybe m
- fromStringReadS :: ReadS m
- data WrapBox m
- type ErrorHandler m = WrapBox m -> IOError -> IO ()
- wrapReadHandle :: Wrappable m => Handle -> ErrorHandler m -> IO (WrapBox m)
- wrapWriteHandle :: Wrappable m => Handle -> ErrorHandler m -> IO (WrapBox m)
- wrapReadHandleWithMailbox :: Wrappable m => Handle -> Mailbox m -> ErrorHandler m -> IO (WrapBox m)
- wrapWriteHandleWithMailbox :: Wrappable m => Handle -> Mailbox m -> ErrorHandler m -> IO (WrapBox m)
Wrapping types
Messages send over wrapped handles must be instance of this class.
You only need to implement either fromString or fromStringReadS.
Methods
Convert a message to a String
Convert a String to the represented message.
fromStringReadS :: ReadS mSource
Same as fromString but using ReadS type.
Wrapper around Mailbox. For now the only MailboxClass instance allowed
for wrapping.
Instances
type ErrorHandler m = WrapBox m -> IOError -> IO ()Source
Function to be called in case of error. WrapBox is the mailbox the error
occured on.
Wrapping functions
Arguments
| :: Wrappable m | |
| => Handle | handle to wrap |
| -> ErrorHandler m | error handler |
| -> IO (WrapBox m) | the wrapped mailbox |
Wrap the given Handle for reading. The returned WrapBox can be used
to receive messages from the Handle.
Notice: The ErrorHandler will be given the returned WrapBox. Writing to
may not be what you want to do. Instead you might first call
wrapWriteHandle and then use its WrapBox in wrapReadHandles
ErrorHandler.
Arguments
| :: Wrappable m | |
| => Handle | handle to wrap |
| -> ErrorHandler m | error handler |
| -> IO (WrapBox m) | the wrapped mailbox |
wrapReadHandleWithMailboxSource
Arguments
| :: Wrappable m | |
| => Handle | the handle to wrap |
| -> Mailbox m | the mailbox to use |
| -> ErrorHandler m | error handler |
| -> IO (WrapBox m) | the wrapped mailbox |
Same as wrapReadHandle but use an existing Mailbox for wrapping.
wrapWriteHandleWithMailboxSource
Arguments
| :: Wrappable m | |
| => Handle | the handle to wrap |
| -> Mailbox m | the mailbox to use |
| -> ErrorHandler m | error handler |
| -> IO (WrapBox m) | the wrapped mailbox |
Same as wrapWriteHandle but use an existing Mailbox for wrapping.