Safe Haskell | None |
---|
- data Server m a
- run :: (Serializable IO i, Serializable IO o, MonadIO m) => Settings i o s -> Server m a -> m (Either Failure a)
- wait :: MonadIO m => Server m ()
- countSlots :: MonadIO m => Server m Int
- runAndWait :: (Serializable IO i, Serializable IO o) => Settings i o s -> IO (Either Failure ())
- type Settings i o s = (UserProtocolSignature, ListeningMode, Timeout, MaxClients, Log, ProcessUserRequest i o s)
- type UserProtocolSignature = ByteString
- data ListeningMode
- type Port = Int
- type Authenticate = Credentials -> IO Bool
- type Credentials = Maybe ByteString
- type Timeout = Int
- type MaxClients = Int
- type Log = Text -> IO ()
- type ProcessUserRequest i o s = State s -> i -> IO o
- type State s = IORef (Maybe s)
- data Failure = ListeningSocketIsBusy
Control
Monad-transformer
A monad transformer, which runs the server in the background.
MonadTrans Server | |
MonadTransControl Server | |
MonadBase IO m => MonadBase IO (Server m) | |
MonadBaseControl IO m => MonadBaseControl IO (Server m) | |
Monad m => Monad (Server m) | |
Functor m => Functor (Server m) | |
Applicative m => Applicative (Server m) | |
MonadIO m => MonadIO (Server m) |
run :: (Serializable IO i, Serializable IO o, MonadIO m) => Settings i o s -> Server m a -> m (Either Failure a)Source
Run the server, while automatically managing all related resources.
countSlots :: MonadIO m => Server m IntSource
Count the currently available slots for new connections.
Simple
runAndWait :: (Serializable IO i, Serializable IO o) => Settings i o s -> IO (Either Failure ())Source
Run the server, while blocking the calling thread.
Settings
type Settings i o s = (UserProtocolSignature, ListeningMode, Timeout, MaxClients, Log, ProcessUserRequest i o s)Source
Settings of how to run the server.
type UserProtocolSignature = ByteStringSource
A unique identification of user's protocol version used for checking of protocol versions mismatch between client and server. It can be simply a user-supplied version number or a hash or a serialization of the representation of a type used for protocol, which can be generated using such library as type-structure.
data ListeningMode Source
Defines how to listen for connections.
Host Port Authenticate | Listen on a port with an authentication function. |
Socket FilePath | Listen on a socket file. Since sockets are local no authentication is needed. Works only on UNIX systems. |
type Authenticate = Credentials -> IO BoolSource
A function, which checks the authentication data.
If you want to provide access to anybody, use (const $ return True)
.
type Credentials = Maybe ByteStringSource
Either a plain ASCII password or an encoding of some data, e.g. an MD5 hash of a username-password pair or just a password. In more involved scenarios you can mix in serialization, e.g. a serialized pair of username and a hash of just the password.
Nothing
means anonymous.
A session timeout in microseconds. The period of keepalive signaling depends on that parameter. If you don't want excessive requests, just make it a couple of minutes.
type MaxClients = IntSource
A maximum amount of clients. When this amount is reached the server rejects all the further connections.
type ProcessUserRequest i o s = State s -> i -> IO oSource
A function which processes requests of type i
from client and
produces a response of type o
,
while maintaining a user-defined session state of type s
per each client.
This function essentially is what defines what the server actually does.
type State s = IORef (Maybe s)Source
A mutable state associated with particular client's connection.
Since we're in IO
anyway, we use a mutable state with IORef
wrapper.
You're free to extend it with whatever the data structure you want.