epass-0.2.1: Baisc, Erlang-like message passing supporting sockets.

Control.Concurrent.Mailbox.Wrapper

Contents

Description

This module provides a wrapping mechanism for file handles (e.g. sockets)

Synopsis

Wrapping types

class Wrappable m whereSource

Messages send over wrapped handles must be instance of this class.

You only need to implement either fromString or fromStringReadS.

Methods

toStringSource

Arguments

:: m

the message

-> String

its String representation

Convert a message to a String

fromStringSource

Arguments

:: String

String representation of a message

-> Maybe m

Just the message or Nothing in case of parse error

Convert a String to the represented message.

fromStringReadS :: ReadS mSource

Same as fromString but using ReadS type.

data WrapBox m Source

Wrapper around Mailbox. For now the only MailboxClass instance allowed for wrapping.

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

wrapReadHandleSource

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.

wrapWriteHandleSource

Arguments

:: Wrappable m 
=> Handle

handle to wrap

-> ErrorHandler m

error handler

-> IO (WrapBox m)

the wrapped mailbox

Wrap the given Handle for writing. The returned WrapBox can be used to send messages through the Handle.

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.