Copyright | (c) Lars Petersen 2016 |
---|---|
License | MIT |
Maintainer | info@lars-petersen.net |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
- data TLS a
- data WebSocket a
- class Typeable a => ServerStack a where
- data Server a
- data ServerConfig a
- data ServerException a
- data ServerConnection a
- data ServerConnectionInfo a
- class ServerStack a => StreamServerStack a where
- class ServerStack a => MessageServerStack a where
- type ClientMessage a
- type ServerMessage a
Documentation
Eq (ServerException (TLS a)) Source # | |
Ord (ServerException (TLS a)) Source # | |
Show (ServerException (TLS a)) Source # | |
Show (ServerConnectionInfo a) => Show (ServerConnectionInfo (TLS a)) Source # | |
Typeable * a => Exception (ServerException (TLS a)) Source # | |
StreamServerStack a => StreamServerStack (TLS a) Source # | |
(StreamServerStack a, Typeable * a) => ServerStack (TLS a) Source # | |
(StreamServerStack a, MqttServerTransportStack a) => MqttServerTransportStack (TLS a) Source # | |
data Server (TLS a) Source # | |
data ServerConfig (TLS a) Source # | |
data ServerException (TLS a) Source # | |
data ServerConnection (TLS a) Source # | |
data ServerConnectionInfo (TLS a) Source # | |
Show (ServerConnectionInfo a) => Show (ServerConnectionInfo (WebSocket a)) Source # | |
StreamServerStack a => StreamServerStack (WebSocket a) Source # | |
StreamServerStack a => ServerStack (WebSocket a) Source # | |
(StreamServerStack a, MqttServerTransportStack a) => MqttServerTransportStack (WebSocket a) Source # | |
data Server (WebSocket a) Source # | |
data ServerConfig (WebSocket a) Source # | |
data ServerException (WebSocket a) Source # | |
data ServerConnection (WebSocket a) Source # | |
data ServerConnectionInfo (WebSocket a) Source # | |
class Typeable a => ServerStack a where Source #
data ServerConfig a Source #
data ServerException a Source #
data ServerConnection a Source #
data ServerConnectionInfo a Source #
withServer :: ServerConfig a -> (Server a -> IO b) -> IO b Source #
Creates a new server from a configuration and passes it to a handler function.
The server given to the handler function shall be bound and in
listening state. The handler function is usually a
forever
loop that accepts and handles new connections.
withServer config $ \server-> forever $ withConnection handleConnection
withConnection :: Server a -> (ServerConnection a -> ServerConnectionInfo a -> IO b) -> IO (Async b) Source #
Waits for and accepts a new connection from a listening server and passes it to a handler function.
This operation is blocking until the lowest layer in the stack accepts
a new connection. The handlers of all other layers are executed within
an Async
which is returned. This allows
the main thread waiting on the underlying socket to block just as long
as necessary. Upper layer protocol handshakes (TLS etc) will be executed
in the new thread.
withServer config $ \server-> forever $ future <- withConnection server handleConnection putStrLn "The lowest layer accepted a new connection!" async $ do result <- wait future putStrLn "The connection handler returned:" print result
StreamServerStack a => ServerStack (WebSocket a) Source # | |
(StreamServerStack a, Typeable * a) => ServerStack (TLS a) Source # | |
StreamServerStack transport => ServerStack (MQTT transport) Source # | |
(Family f, Type t, Protocol p, Typeable * f, Typeable * t, Typeable * p) => ServerStack (Socket f t p) Source # | |
class ServerStack a => StreamServerStack a where Source #
sendStream :: ServerConnection a -> ByteString -> IO Int Source #
sendStreamLazy :: ServerConnection a -> ByteString -> IO Int64 Source #
sendStreamBuilder :: ServerConnection a -> Int -> Builder -> IO Int64 Source #
receiveStream :: ServerConnection a -> Int -> IO ByteString Source #
receiveStreamLazy :: ServerConnection a -> Int -> IO ByteString Source #
StreamServerStack a => StreamServerStack (WebSocket a) Source # | |
StreamServerStack a => StreamServerStack (TLS a) Source # | |
(Typeable * f, Typeable * p, Family f, Protocol p) => StreamServerStack (Socket f Stream p) Source # | |
class ServerStack a => MessageServerStack a where Source #
This class is an abstraction for ServerStack
s that support the
transmission and reception of finite messages.
type ClientMessage a Source #
type ServerMessage a Source #
sendMessage :: ServerConnection a -> ServerMessage a -> IO Int64 Source #
Send a message.
- Returns the encoded message size.
sendMessages :: Foldable t => ServerConnection a -> t (ServerMessage a) -> IO Int64 Source #
Send several messages. This might lead to an improvement for very short messages.
- Returns the summed size of all encoded messages.
receiveMessage :: ServerConnection a -> Int64 -> IO (ClientMessage a) Source #
Receive a message.
- The second parameter determines the maximum encoded message size which must not be exceeded by the client or an exception will be thrown. Implementations shall track the consumed bytes and shall throw an exception as soon as the limit is exceeded even if the message is not yet complete. This is important to prevent _denial of service_ attacks.
consumeMessages :: ServerConnection a -> Int64 -> (ClientMessage a -> IO Bool) -> IO () Source #
Consumes incoming messages with a supplied consumer callback.
- The second parameter limits the size of a single encoded message
(see
receiveMessage
).
StreamServerStack transport => MessageServerStack (MQTT transport) Source # | |