Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Network.TypedProtocol.Channel
Synopsis
- data Channel m a = Channel {}
- hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a
- isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b
- fixedInputChannel :: MonadSTM m => [a] -> m (Channel m a)
- mvarsAsChannel :: MonadSTM m => TMVar m a -> TMVar m a -> Channel m a
- handlesAsChannel :: Handle -> Handle -> Channel IO ByteString
- createConnectedChannels :: MonadSTM m => m (Channel m a, Channel m a)
- createConnectedBufferedChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m a)
- createPipelineTestChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m a)
- channelEffect :: forall m a. Monad m => (a -> m ()) -> (Maybe a -> m ()) -> Channel m a -> Channel m a
- delayChannel :: MonadDelay m => DiffTime -> Channel m a -> Channel m a
- loggingChannel :: (MonadSay m, Show id, Show a) => id -> Channel m a -> Channel m a
Documentation
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
|
hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a Source #
isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b Source #
fixedInputChannel :: MonadSTM 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.
Arguments
:: Handle | Read handle |
-> Handle | Write handle |
-> Channel IO ByteString |
Make a Channel
from a pair of IO Handle
s, 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.
createConnectedChannels :: MonadSTM 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 :: 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.
createPipelineTestChannels :: 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 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.
Arguments
:: forall m a. Monad m | |
=> (a -> m ()) | Action before |
-> (Maybe a -> m ()) | Action after |
-> Channel m a | |
-> Channel m a |
Transform a channel to add an extra action before every send and after every receive.