-- |
-- Module: Network.Transport.InMemory.Debug
--
-- Miscelanteous functions for debug purposes.
module Network.Transport.InMemory.Debug
  ( breakConnection
  ) where

import Control.Concurrent.STM
import Network.Transport
import Network.Transport.InMemory.Internal

-- | Function that simulate failing connection between two endpoints,
-- after calling this function both endpoints will receive ConnectionEventLost
-- message, and all @LocalConnectionValid@ connections will
-- be put into @LocalConnectionFailed@ state.
breakConnection :: TransportInternals
                -> EndPointAddress          -- ^ @From@ connection
                -> EndPointAddress          -- ^ @To@ connection
                -> String                   -- ^ Error message
                -> IO ()
breakConnection :: TransportInternals
-> EndPointAddress -> EndPointAddress -> String -> IO ()
breakConnection (TransportInternals TVar TransportState
state) EndPointAddress
from EndPointAddress
to String
message =
  STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TVar TransportState
-> EndPointAddress -> EndPointAddress -> String -> STM ()
apiBreakConnection TVar TransportState
state EndPointAddress
from EndPointAddress
to String
message