-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | In-memory instantiation of Network.Transport
--   
--   This is a transport implementation that could be used for local
--   communication in the same address space (i.e. one process).
--   
--   It could be used either for testing purposes or for local
--   communication that require the network-transport semantics.
--   
--   NB: network-tranpsport-inmemory does not support cross-transport
--   communication. All endpoints that want to comminicate should be
--   created using the same transport.
@package network-transport-inmemory
@version 0.5.2


-- | Internal part of the implementation. This module is for internal use
--   or advanced debuging. There are no guarantees about stability of this
--   module.
module Network.Transport.InMemory.Internal

-- | Create a new Transport exposing internal state.
--   
--   Useful for testing and/or debugging purposes. Should not be used in
--   production. No guarantee as to the stability of the internals API.
createTransportExposeInternals :: IO (Transport, TransportInternals)
newtype TransportInternals
TransportInternals :: (TVar TransportState) -> TransportInternals
data TransportState
TransportValid :: {-# UNPACK #-} !ValidTransportState -> TransportState
TransportClosed :: TransportState
data ValidTransportState
ValidTransportState :: !(Map EndPointAddress LocalEndPoint) -> !Int -> ValidTransportState
[_localEndPoints] :: ValidTransportState -> !(Map EndPointAddress LocalEndPoint)
[_nextLocalEndPointId] :: ValidTransportState -> !Int
data LocalEndPoint
LocalEndPoint :: !EndPointAddress -> !(TChan Event) -> !(TVar LocalEndPointState) -> LocalEndPoint
[localEndPointAddress] :: LocalEndPoint -> !EndPointAddress
[localEndPointChannel] :: LocalEndPoint -> !(TChan Event)
[localEndPointState] :: LocalEndPoint -> !(TVar LocalEndPointState)
data LocalEndPointState
LocalEndPointValid :: {-# UNPACK #-} !ValidLocalEndPointState -> LocalEndPointState
LocalEndPointClosed :: LocalEndPointState
data ValidLocalEndPointState
ValidLocalEndPointState :: !ConnectionId -> !(Map (EndPointAddress, ConnectionId) LocalConnection) -> Map MulticastAddress (TVar (Set EndPointAddress)) -> ValidLocalEndPointState
[_nextConnectionId] :: ValidLocalEndPointState -> !ConnectionId
[_connections] :: ValidLocalEndPointState -> !(Map (EndPointAddress, ConnectionId) LocalConnection)
[_multigroups] :: ValidLocalEndPointState -> Map MulticastAddress (TVar (Set EndPointAddress))
data LocalConnection
LocalConnection :: !ConnectionId -> !EndPointAddress -> !EndPointAddress -> !(TVar LocalConnectionState) -> LocalConnection
[localConnectionId] :: LocalConnection -> !ConnectionId
[localConnectionLocalAddress] :: LocalConnection -> !EndPointAddress
[localConnectionRemoteAddress] :: LocalConnection -> !EndPointAddress
[localConnectionState] :: LocalConnection -> !(TVar LocalConnectionState)
data LocalConnectionState
LocalConnectionValid :: LocalConnectionState
LocalConnectionClosed :: LocalConnectionState
LocalConnectionFailed :: LocalConnectionState

-- | Create a new end point.
apiNewEndPoint :: TVar TransportState -> IO (Either (TransportError NewEndPointErrorCode) EndPoint)
apiCloseEndPoint :: TVar TransportState -> EndPointAddress -> IO ()

-- | Tear down functions that should be called in case if conncetion fails.
apiBreakConnection :: TVar TransportState -> EndPointAddress -> EndPointAddress -> String -> STM ()

-- | Create a new connection
apiConnect :: EndPointAddress -> TVar TransportState -> EndPointAddress -> Reliability -> ConnectHints -> IO (Either (TransportError ConnectErrorCode) Connection)

-- | Send a message over a connection
apiSend :: TChan Event -> TVar TransportState -> LocalConnection -> [ByteString] -> IO (Either (TransportError SendErrorCode) ())

-- | Close a connection
apiClose :: TChan Event -> TVar TransportState -> LocalConnection -> IO ()


-- | Miscelanteous functions for debug purposes.
module Network.Transport.InMemory.Debug

-- | Function that simulate failing connection between two endpoints, after
--   calling this function both endpoints will receive ConnectionEventLost
--   message, and all <tt>LocalConnectionValid</tt> connections will be put
--   into <tt>LocalConnectionFailed</tt> state.
breakConnection :: TransportInternals -> EndPointAddress -> EndPointAddress -> String -> IO ()


-- | In-memory implementation of the Transport API.
module Network.Transport.InMemory

-- | Create a new Transport.
--   
--   Only a single transport should be created per Haskell process (threads
--   can, and should, create their own endpoints though).
createTransport :: IO Transport

-- | Create a new Transport exposing internal state.
--   
--   Useful for testing and/or debugging purposes. Should not be used in
--   production. No guarantee as to the stability of the internals API.
createTransportExposeInternals :: IO (Transport, TransportInternals)
newtype TransportInternals
TransportInternals :: (TVar TransportState) -> TransportInternals

-- | Function that simulate failing connection between two endpoints, after
--   calling this function both endpoints will receive ConnectionEventLost
--   message, and all <tt>LocalConnectionValid</tt> connections will be put
--   into <tt>LocalConnectionFailed</tt> state.
breakConnection :: TransportInternals -> EndPointAddress -> EndPointAddress -> String -> IO ()
