metro-0.1.0.1: A simple tcp and udp socket server framework

Safe HaskellNone
LanguageHaskell2010

Metro

Documentation

class GetPacketId k pkt where Source #

Methods

getPacketId :: pkt -> k Source #

class SetPacketId k pkt where Source #

Methods

setPacketId :: k -> pkt -> pkt Source #

class SendPacket spkt where Source #

Minimal complete definition

Nothing

Methods

sendPacket :: MonadIO m => spkt -> (ByteString -> m ()) -> m () Source #

sendPacket :: (MonadIO m, Binary spkt) => spkt -> (ByteString -> m ()) -> m () Source #

class RecvPacket rpkt where Source #

Methods

recvPacket :: MonadIO m => (Int -> m ByteString) -> m rpkt Source #

class Servable serv where Source #

Associated Types

data ServerConfig serv Source #

type SID serv Source #

type STP serv Source #

Methods

newServer :: MonadIO m => ServerConfig serv -> m serv Source #

servOnce :: MonadUnliftIO m => serv -> (Maybe (SID serv, TransportConfig (STP serv)) -> m ()) -> m () Source #

onConnEnter :: MonadIO m => serv -> SID serv -> m () Source #

onConnLeave :: MonadIO m => serv -> SID serv -> m () Source #

servClose :: MonadIO m => serv -> m () Source #

class Transport transport where Source #

Associated Types

data TransportConfig transport Source #

Methods

newTransport :: TransportConfig transport -> IO transport Source #

recvData :: transport -> Int -> IO ByteString Source #

sendData :: transport -> ByteString -> IO () Source #

closeTransport :: transport -> IO () Source #

sendBinary :: (MonadIO m, Binary spkt) => spkt -> (ByteString -> m ()) -> m () Source #

class FromConn m where Source #

Methods

fromConn :: Monad n => ConnT tp n a -> m tp n a Source #

Instances
FromConn ConnT Source # 
Instance details

Defined in Metro.Conn

Methods

fromConn :: Monad n => ConnT tp n a -> ConnT tp n a Source #

FromConn (SessionT u nid k rpkt) Source # 
Instance details

Defined in Metro.Session

Methods

fromConn :: Monad n => ConnT tp n a -> SessionT u nid k rpkt tp n a Source #

FromConn (NodeT u nid k rpkt) Source # 
Instance details

Defined in Metro.Node

Methods

fromConn :: Monad n => ConnT tp n a -> NodeT u nid k rpkt tp n a Source #

data ConnT tp m a Source #

Instances
FromConn ConnT Source # 
Instance details

Defined in Metro.Conn

Methods

fromConn :: Monad n => ConnT tp n a -> ConnT tp n a Source #

MonadTrans (ConnT tp) Source # 
Instance details

Defined in Metro.Conn

Methods

lift :: Monad m => m a -> ConnT tp m a #

Monad m => MonadReader (ConnEnv tp) (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

ask :: ConnT tp m (ConnEnv tp) #

local :: (ConnEnv tp -> ConnEnv tp) -> ConnT tp m a -> ConnT tp m a #

reader :: (ConnEnv tp -> a) -> ConnT tp m a #

Monad m => Monad (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

(>>=) :: ConnT tp m a -> (a -> ConnT tp m b) -> ConnT tp m b #

(>>) :: ConnT tp m a -> ConnT tp m b -> ConnT tp m b #

return :: a -> ConnT tp m a #

fail :: String -> ConnT tp m a #

Functor m => Functor (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

fmap :: (a -> b) -> ConnT tp m a -> ConnT tp m b #

(<$) :: a -> ConnT tp m b -> ConnT tp m a #

Applicative m => Applicative (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

pure :: a -> ConnT tp m a #

(<*>) :: ConnT tp m (a -> b) -> ConnT tp m a -> ConnT tp m b #

liftA2 :: (a -> b -> c) -> ConnT tp m a -> ConnT tp m b -> ConnT tp m c #

(*>) :: ConnT tp m a -> ConnT tp m b -> ConnT tp m b #

(<*) :: ConnT tp m a -> ConnT tp m b -> ConnT tp m a #

MonadIO m => MonadIO (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

liftIO :: IO a -> ConnT tp m a #

MonadUnliftIO m => MonadUnliftIO (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

withRunInIO :: ((forall a. ConnT tp m a -> IO a) -> IO b) -> ConnT tp m b #

data ConnEnv tp Source #

Instances
Monad m => MonadReader (ConnEnv tp) (ConnT tp m) Source # 
Instance details

Defined in Metro.Conn

Methods

ask :: ConnT tp m (ConnEnv tp) #

local :: (ConnEnv tp -> ConnEnv tp) -> ConnT tp m a -> ConnT tp m a #

reader :: (ConnEnv tp -> a) -> ConnT tp m a #

runConnT :: ConnEnv tp -> ConnT tp m a -> m a Source #

data SessionT u nid k rpkt tp m a Source #

Instances
FromConn (SessionT u nid k rpkt) Source # 
Instance details

Defined in Metro.Session

Methods

fromConn :: Monad n => ConnT tp n a -> SessionT u nid k rpkt tp n a Source #

Monad m => MonadReader (SessionEnv u nid k rpkt) (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

ask :: SessionT u nid k rpkt tp m (SessionEnv u nid k rpkt) #

local :: (SessionEnv u nid k rpkt -> SessionEnv u nid k rpkt) -> SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m a #

reader :: (SessionEnv u nid k rpkt -> a) -> SessionT u nid k rpkt tp m a #

MonadTrans (SessionT u nid k rpkt tp) Source # 
Instance details

Defined in Metro.Session

Methods

lift :: Monad m => m a -> SessionT u nid k rpkt tp m a #

Monad m => Monad (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

(>>=) :: SessionT u nid k rpkt tp m a -> (a -> SessionT u nid k rpkt tp m b) -> SessionT u nid k rpkt tp m b #

(>>) :: SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b -> SessionT u nid k rpkt tp m b #

return :: a -> SessionT u nid k rpkt tp m a #

fail :: String -> SessionT u nid k rpkt tp m a #

Functor m => Functor (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

fmap :: (a -> b) -> SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b #

(<$) :: a -> SessionT u nid k rpkt tp m b -> SessionT u nid k rpkt tp m a #

Applicative m => Applicative (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

pure :: a -> SessionT u nid k rpkt tp m a #

(<*>) :: SessionT u nid k rpkt tp m (a -> b) -> SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b #

liftA2 :: (a -> b -> c) -> SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b -> SessionT u nid k rpkt tp m c #

(*>) :: SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b -> SessionT u nid k rpkt tp m b #

(<*) :: SessionT u nid k rpkt tp m a -> SessionT u nid k rpkt tp m b -> SessionT u nid k rpkt tp m a #

MonadIO m => MonadIO (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

liftIO :: IO a -> SessionT u nid k rpkt tp m a #

MonadUnliftIO m => MonadUnliftIO (SessionT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Session

Methods

withRunInIO :: ((forall a. SessionT u nid k rpkt tp m a -> IO a) -> IO b) -> SessionT u nid k rpkt tp m b #

sessionState :: MonadIO m => SessionT u nid k rpkt tp m Bool Source #

send :: (MonadUnliftIO m, Transport tp, SendPacket spkt, SetPacketId k spkt) => spkt -> SessionT u nid k rpkt tp m () Source #

receive :: (MonadIO m, Transport tp) => SessionT u nid k rpkt tp m (Maybe rpkt) Source #

makeResponse :: (MonadUnliftIO m, Transport tp, SendPacket spkt, SetPacketId k spkt) => (rpkt -> m (Maybe spkt)) -> SessionT u nid k rpkt tp m () Source #

makeResponse_ :: (MonadUnliftIO m, Transport tp, SendPacket spkt, SetPacketId k spkt) => (rpkt -> Maybe spkt) -> SessionT u nid k rpkt tp m () Source #

data NodeT u nid k rpkt tp m a Source #

Instances
FromConn (NodeT u nid k rpkt) Source # 
Instance details

Defined in Metro.Node

Methods

fromConn :: Monad n => ConnT tp n a -> NodeT u nid k rpkt tp n a Source #

Monad m => MonadReader (NodeEnv u nid k rpkt) (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

ask :: NodeT u nid k rpkt tp m (NodeEnv u nid k rpkt) #

local :: (NodeEnv u nid k rpkt -> NodeEnv u nid k rpkt) -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m a #

reader :: (NodeEnv u nid k rpkt -> a) -> NodeT u nid k rpkt tp m a #

MonadTrans (NodeT u nid k rpkt tp) Source # 
Instance details

Defined in Metro.Node

Methods

lift :: Monad m => m a -> NodeT u nid k rpkt tp m a #

Monad m => Monad (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

(>>=) :: NodeT u nid k rpkt tp m a -> (a -> NodeT u nid k rpkt tp m b) -> NodeT u nid k rpkt tp m b #

(>>) :: NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b -> NodeT u nid k rpkt tp m b #

return :: a -> NodeT u nid k rpkt tp m a #

fail :: String -> NodeT u nid k rpkt tp m a #

Functor m => Functor (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

fmap :: (a -> b) -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b #

(<$) :: a -> NodeT u nid k rpkt tp m b -> NodeT u nid k rpkt tp m a #

Applicative m => Applicative (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

pure :: a -> NodeT u nid k rpkt tp m a #

(<*>) :: NodeT u nid k rpkt tp m (a -> b) -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b #

liftA2 :: (a -> b -> c) -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b -> NodeT u nid k rpkt tp m c #

(*>) :: NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b -> NodeT u nid k rpkt tp m b #

(<*) :: NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m b -> NodeT u nid k rpkt tp m a #

MonadIO m => MonadIO (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

liftIO :: IO a -> NodeT u nid k rpkt tp m a #

MonadUnliftIO m => MonadUnliftIO (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

withRunInIO :: ((forall a. NodeT u nid k rpkt tp m a -> IO a) -> IO b) -> NodeT u nid k rpkt tp m b #

data NodeEnv1 u nid k rpkt tp Source #

Constructors

NodeEnv1 

Fields

data NodeEnv u nid k rpkt Source #

Instances
Monad m => MonadReader (NodeEnv u nid k rpkt) (NodeT u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Node

Methods

ask :: NodeT u nid k rpkt tp m (NodeEnv u nid k rpkt) #

local :: (NodeEnv u nid k rpkt -> NodeEnv u nid k rpkt) -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m a #

reader :: (NodeEnv u nid k rpkt -> a) -> NodeT u nid k rpkt tp m a #

data SessionMode Source #

Constructors

SingleAction 
MultiAction 
Instances
Eq SessionMode Source # 
Instance details

Defined in Metro.Node

Show SessionMode Source # 
Instance details

Defined in Metro.Node

data NodeMode Source #

Constructors

Single 
Multi 
Instances
Eq NodeMode Source # 
Instance details

Defined in Metro.Node

Show NodeMode Source # 
Instance details

Defined in Metro.Node

runNodeT :: NodeEnv u nid k rpkt -> NodeT u nid k rpkt tp m a -> ConnT tp m a Source #

runNodeT1 :: NodeEnv1 u nid k rpkt tp -> NodeT u nid k rpkt tp m a -> m a Source #

initEnv :: MonadIO m => u -> nid -> IO k -> m (NodeEnv u nid k rpkt) Source #

withEnv :: Monad m => u -> NodeT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m a Source #

initEnv1 :: MonadIO m => (NodeEnv u nid k rpkt -> NodeEnv u nid k rpkt) -> ConnEnv tp -> u -> nid -> IO k -> m (NodeEnv1 u nid k rpkt tp) Source #

getEnv1 :: (Monad m, Transport tp) => NodeT u nid k rpkt tp m (NodeEnv1 u nid k rpkt tp) Source #

runSessionT_ :: Monad m => SessionEnv u nid k rpkt -> SessionT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m a Source #

withSessionT :: (MonadUnliftIO m, Eq k, Hashable k) => Maybe Int64 -> SessionT u nid k rpkt tp m a -> NodeT u nid k rpkt tp m a Source #

newSessionEnv :: (MonadIO m, Eq k, Hashable k) => Maybe Int64 -> k -> NodeT u nid k rpkt tp m (SessionEnv u nid k rpkt) Source #

nextSessionId :: MonadIO m => NodeT u nid k rpkt tp m k Source #

busy :: MonadIO m => NodeT u nid k rpkt tp m Bool Source #

startNodeT :: (MonadUnliftIO m, Transport tp, RecvPacket rpkt, GetPacketId k rpkt, Eq k, Hashable k) => SessionT u nid k rpkt tp m () -> NodeT u nid k rpkt tp m () Source #

startNodeT_ :: (MonadUnliftIO m, Transport tp, RecvPacket rpkt, GetPacketId k rpkt, Eq k, Hashable k) => (rpkt -> m Bool) -> SessionT u nid k rpkt tp m () -> NodeT u nid k rpkt tp m () Source #

nodeState :: MonadIO m => NodeT u nid k rpkt tp m Bool Source #

stopNodeT :: (MonadIO m, Transport tp) => NodeT u nid k rpkt tp m () Source #

env :: Monad m => NodeT u nid k rpkt tp m u Source #

request :: (MonadUnliftIO m, Transport tp, SendPacket spkt, SetPacketId k spkt, Eq k, Hashable k) => Maybe Int64 -> spkt -> NodeT u nid k rpkt tp m (Maybe rpkt) Source #

requestAndRetry :: (MonadUnliftIO m, Transport tp, SendPacket spkt, SetPacketId k spkt, Eq k, Hashable k) => Maybe Int64 -> Maybe Int -> spkt -> NodeT u nid k rpkt tp m (Maybe rpkt) Source #

getTimer :: MonadIO m => NodeT u nid k rpkt tp m Int64 Source #

getNodeId :: Monad m => NodeT n nid k rpkt tp m nid Source #

getSessionSize :: MonadIO m => NodeEnv u nid k rpkt -> m Int Source #

getSessionSize1 :: MonadIO m => NodeEnv1 u nid k rpkt tp -> m Int Source #

data ServerT serv u nid k rpkt tp m a Source #

Instances
MonadTrans (ServerT serv u nid k rpkt tp) Source # 
Instance details

Defined in Metro.Server

Methods

lift :: Monad m => m a -> ServerT serv u nid k rpkt tp m a #

Monad m => MonadReader (ServerEnv serv u nid k rpkt tp) (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

ask :: ServerT serv u nid k rpkt tp m (ServerEnv serv u nid k rpkt tp) #

local :: (ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp) -> ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m a #

reader :: (ServerEnv serv u nid k rpkt tp -> a) -> ServerT serv u nid k rpkt tp m a #

Monad m => Monad (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

(>>=) :: ServerT serv u nid k rpkt tp m a -> (a -> ServerT serv u nid k rpkt tp m b) -> ServerT serv u nid k rpkt tp m b #

(>>) :: ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b -> ServerT serv u nid k rpkt tp m b #

return :: a -> ServerT serv u nid k rpkt tp m a #

fail :: String -> ServerT serv u nid k rpkt tp m a #

Functor m => Functor (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

fmap :: (a -> b) -> ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b #

(<$) :: a -> ServerT serv u nid k rpkt tp m b -> ServerT serv u nid k rpkt tp m a #

Applicative m => Applicative (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

pure :: a -> ServerT serv u nid k rpkt tp m a #

(<*>) :: ServerT serv u nid k rpkt tp m (a -> b) -> ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b #

liftA2 :: (a -> b -> c) -> ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b -> ServerT serv u nid k rpkt tp m c #

(*>) :: ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b -> ServerT serv u nid k rpkt tp m b #

(<*) :: ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m b -> ServerT serv u nid k rpkt tp m a #

MonadIO m => MonadIO (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

liftIO :: IO a -> ServerT serv u nid k rpkt tp m a #

MonadUnliftIO m => MonadUnliftIO (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

withRunInIO :: ((forall a. ServerT serv u nid k rpkt tp m a -> IO a) -> IO b) -> ServerT serv u nid k rpkt tp m b #

data ServerEnv serv u nid k rpkt tp Source #

Instances
Monad m => MonadReader (ServerEnv serv u nid k rpkt tp) (ServerT serv u nid k rpkt tp m) Source # 
Instance details

Defined in Metro.Server

Methods

ask :: ServerT serv u nid k rpkt tp m (ServerEnv serv u nid k rpkt tp) #

local :: (ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp) -> ServerT serv u nid k rpkt tp m a -> ServerT serv u nid k rpkt tp m a #

reader :: (ServerEnv serv u nid k rpkt tp -> a) -> ServerT serv u nid k rpkt tp m a #

runServerT :: ServerEnv serv u nid k rpkt tp -> ServerT serv u nid k rpkt tp m a -> m a Source #

initServerEnv :: (MonadIO m, Servable serv) => ServerConfig serv -> IO k -> (TransportConfig (STP serv) -> TransportConfig tp) -> (SID serv -> ConnEnv tp -> IO (Maybe (nid, u))) -> m (ServerEnv serv u nid k rpkt tp) Source #

setNodeMode :: NodeMode -> ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp Source #

setSessionMode :: SessionMode -> ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp Source #

setServerName :: String -> ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp Source #

setKeepalive :: Int64 -> ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp Source #

setDefaultSessionTimeout :: Int64 -> ServerEnv serv u nid k rpkt tp -> ServerEnv serv u nid k rpkt tp Source #

setOnNodeLeave :: MonadIO m => ServerEnv serv u nid k rpkt tp -> (nid -> u -> IO ()) -> m () Source #

handleConn :: (MonadUnliftIO m, Transport tp, Show nid, Eq nid, Hashable nid, Eq k, Hashable k, GetPacketId k rpkt, RecvPacket rpkt, Servable serv) => String -> SID serv -> ConnEnv tp -> nid -> u -> (rpkt -> m Bool) -> SessionT u nid k rpkt tp m () -> ServerT serv u nid k rpkt tp m (NodeEnv1 u nid k rpkt tp, Async ()) Source #

startServer :: (MonadUnliftIO m, Transport tp, Show nid, Eq nid, Hashable nid, Eq k, Hashable k, GetPacketId k rpkt, RecvPacket rpkt, Servable serv) => ServerEnv serv u nid k rpkt tp -> SessionT u nid k rpkt tp m () -> m () Source #

startServer_ :: (MonadUnliftIO m, Transport tp, Show nid, Eq nid, Hashable nid, Eq k, Hashable k, GetPacketId k rpkt, RecvPacket rpkt, Servable serv) => ServerEnv serv u nid k rpkt tp -> (rpkt -> m Bool) -> SessionT u nid k rpkt tp m () -> m () Source #

stopServerT :: (MonadIO m, Servable serv) => ServerT serv u nid k rpkt tp m () Source #

serverEnv :: Monad m => ServerT serv u nid k rpkt tp m (ServerEnv serv u nid k rpkt tp) Source #

getNodeEnvList :: ServerEnv serv u nid k rpkt tp -> IOHashMap nid (NodeEnv1 u nid k rpkt tp) Source #

getServ :: ServerEnv serv u nid k rpkt tp -> serv Source #