network-service-0.1.0.0: Provide a service at the data type level.

Copyright(c) Moritz Angermann 2014
LicenseMIT
Maintainermoritz@lichtzwerge.de
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.Service

Description

A service is an endpoint that can receive and send messages.

Synopsis

Documentation

class ServiceMessage a where Source

Services operate on Messages, the ServiceMessage class abstracts the serialization.

Methods

toBS Source

Arguments

:: a 
-> ByteString

serialization to ByteString representation

fromBS Source

Arguments

:: ByteString 
-> a

deserialization from ByteString representation

data Service a Source

A Service of a certain Message data.

Constructors

Service 

Fields

sDone :: IO Bool

tells whether the service is done or not.

sRecv :: IO a

receive a message.

sSend :: a -> IO ()

send a message.

sTerm :: IO ()

terminate the service.

type ServiceHandler a = Service a -> IO () Source

A handler takes a service and returns an IO action. The idea is that a service handler will run a service

a simple echo handler might look like the following:

handler service = do { msg <- sRecv service
                     ; sSend service msg
                     ; isDone <- sDone service
                     ; unless isDone (handler service)
                     }