ouroboros-network-framework-0.13.1.0: Ouroboros network framework
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Network.Channel

Synopsis

Documentation

data Channel m a Source #

One end of a duplex channel. It is a reliable, ordered channel of some medium. The medium does not imply message boundaries, it can be just bytes.

Constructors

Channel 

Fields

  • send ∷ a → m ()

    Write output to the channel.

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

  • recv ∷ m (Maybe a)

    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).

createPipeConnectedChannelsIO (Channel IO ByteString, Channel IO ByteString) Source #

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

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

hoistChannel ∷ (∀ x. m x → n x) → Channel m a → Channel n a Source #

isoKleisliChannel ∷ ∀ a b m. Monad m ⇒ (a → m b) → (b → m a) → Channel m a → Channel m b Source #

Given an isomorphism between a and b (in Kleisli category), transform a Channel m a into Channel m b.

fixedInputChannelMonadSTM m ⇒ [a] → m (Channel m a) Source #

A Channel with a fixed input, and where all output is discarded.

The input is guaranteed to be supplied via read with the given chunk boundaries.

This is only useful for testing. In particular the fixed chunk boundaries can be used to test that framing and other codecs work with any possible chunking.

mvarsAsChannelMonadSTM m ⇒ TMVar m a → TMVar m a → Channel m a Source #

Make a Channel from a pair of TMVars, one for reading and one for writing.

handlesAsChannel Source #

Arguments

Handle

Read handle

Handle

Write handle

Channel IO ByteString 

Make a Channel from a pair of IO Handles, one for reading and one for writing.

The Handles should be open in the appropriate read or write mode, and in binary mode. Writes are flushed after each write, so it is safe to use a buffering mode.

For bidirectional handles it is safe to pass the same handle for both.

createConnectedChannelsMonadSTM m ⇒ m (Channel m a, Channel m a) Source #

Create a pair of channels that are connected via one-place buffers.

This is primarily useful for testing protocols.

createConnectedBufferedChannels ∷ ∀ m a. MonadSTM m ⇒ Natural → m (Channel m a, Channel m a) Source #

Create a pair of channels that are connected via N-place buffers.

This variant blocks when send would exceed the maximum buffer size. Use this variant when you want the environment rather than the Peer to limit the pipelining.

This is primarily useful for testing protocols.

createConnectedBufferedChannelsSTMMonadSTM m ⇒ NaturalSTM m (Channel (STM m) a, Channel (STM m) a) Source #

As createConnectedBufferedChannels, but in STM.

TODO: it should return a pair of `Channel m a`.

createPipelineTestChannelsMonadSTM m ⇒ Natural → m (Channel m a, Channel m a) Source #

Create a pair of channels that are connected via N-place buffers.

This variant fails when send would exceed the maximum buffer size. Use this variant when you want the PeerPipelined to limit the pipelining itself, and you want to check that it does not exceed the expected level of pipelining.

This is primarily useful for testing protocols.

channelEffect Source #

Arguments

∷ ∀ m a. Monad m 
⇒ (a → m ())

Action before send

→ (Maybe a → m ())

Action after recv

Channel m a 
Channel m a 

Transform a channel to add an extra action before every send and after every receive.

delayChannelMonadDelay m ⇒ DiffTimeChannel m a → Channel m a 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, Show a) ⇒ id → Channel m a → Channel m a Source #

Channel which logs sent and received messages.