network-mux-0.1.0.1: Multiplexing library
Safe Haskell None
Language Haskell2010

Network.Mux.Channel

Description

An extension of Channel , with additional Channel implementations.

Synopsis

Documentation

data Channel m Source #

Constructors

Channel

Fields

  • send :: ByteString -> m ()

    Write bytes to the channel.

    It maybe raise exceptions.

  • recv :: m ( Maybe ByteString )

    Read some input from the channel, or Nothing to indicate EOF.

    Note that having received EOF it is still possible to send. The EOF condition is however monotonic.

    It may raise exceptions (as appropriate for the monad and kind of channel).

createBufferConnectedChannels :: forall m. MonadSTM m => m ( Channel m, Channel m) Source #

Create a pair of Channel s that are connected internally.

This is intended for inter-thread communication, such as between a multiplexing thread and a thread running a peer.

It uses lazy ByteString s but it ensures that data written to the channel is fully evaluated first. This ensures that any work to serialise the data takes place on the writer side and not the reader side .

createPipeConnectedChannels :: IO ( Channel IO , Channel IO ) Source #

Create a local pipe, with both ends in this process, and expose that as a pair of Channel s, one for each end.

This is primarily for testing purposes since it does not allow actual IPC.

withFifosAsChannel Source #

Arguments

:: FilePath

FIFO for reading

-> FilePath

FIFO for writing

-> ( Channel IO -> IO a)
-> IO a

Open a pair of Unix FIFOs, and expose that as a Channel .

The peer process needs to open the same files but the other way around, for writing and reading.

This is primarily for the purpose of demonstrations that use communication between multiple local processes. It is Unix specific.

socketAsChannel :: Socket -> Channel IO Source #

Make a Channel from a Socket . The socket must be a stream socket

channelEffect Source #

Arguments

:: forall m. Monad m
=> ( ByteString -> m ())

Action before send

-> ( Maybe ByteString -> m ())

Action after recv

-> Channel m
-> Channel m

delayChannel :: ( MonadSTM m, MonadTimer m) => DiffTime -> Channel m -> Channel m Source #

Delay a channel on the receiver end.

This is intended for testing, as a crude approximation of network delays. More accurate models along these lines are of course possible.

loggingChannel :: ( MonadSay m, Show id) => id -> Channel m -> Channel m Source #

Channel which logs sent and received messages.