mqtt-hs-1.0.1: A MQTT client library.

Maintainerkoomi+mqtt@hackerspace-bamberg.de
Safe HaskellNone

Network.MQTT.Internal

Contents

Description

MQTT Internals.

Use with care and expected changes.

Synopsis

User interaction

data Config Source

The various options when establishing a connection. See below for available accessors.

Constructors

Config 

Fields

cHost :: HostName

Hostname of the broker.

cPort :: PortNumber

Port of the broker.

cClean :: Bool

Should the server forget subscriptions and other state on disconnects?

cWill :: Maybe Will

Optional Will message.

cUsername :: Maybe Text

Optional username used for authentication.

cPassword :: Maybe Text

Optional password used for authentication.

cKeepAlive :: Maybe Word16

Time (in seconds) after which a PingReq is sent to the broker if no regular message was sent. Nothing means no limit.

cClientID :: Text

Client ID used by the server to identify clients.

cLogDebug :: String -> IO ()

Function for debug-level logging.

cResendTimeout :: Int

Time in seconds after which messages that have not been but should be acknowledged are retransmitted.

cPublished :: TChan (Message PUBLISH)

The channel received Publish messages are written to.

cCommands :: Commands

The channel used by publish, subscribe, etc.

cInputBufferSize :: Int

Maximum number of bytes read from the network at once.

data Terminated Source

Reasons for why the connection was terminated.

Constructors

ParseFailed [String] String

at the context in [String] with the given message.

ConnectFailed ConnectError 
UserRequested

disconnect was called

Instances

newtype Commands Source

The communication channel used by publish, subscribe, etc.

Constructors

Cmds 

Fields

getCmds :: TChan Command
 

mkCommands :: IO CommandsSource

Create a new Commands channel.

There should be one channel per MQTT connection. It might be reused by subsequent connections, but never by multiple connections concurrently.

send :: SingI t => Config -> Message t -> IO ()Source

Tell the mainLoop to send the given Message.

await :: SingI t => Config -> MVar (Message t) -> Maybe MsgID -> IO AwaitMessageSource

Tell the MQTT instance to place the next Message of correct MsgType and MsgID (if present) into the MVar.

data AwaitMessage whereSource

Constructors

AwaitMessage :: SingI t => MVar (Message t) -> Maybe MsgID -> AwaitMessage 

Instances

stopWaiting :: Config -> AwaitMessage -> IO ()Source

Stop waiting for the described Message.

sendAwait :: (SingI t, SingI r) => Config -> Message t -> SMsgType r -> IO (Message r)Source

Execute the common pattern of sending a message and awaiting a response in a safe, non-racy way. The message message is retransmitted if no response has been received after cResendTimeout seconds, with exponential backoff for further retransmissions

An incoming message is considered a response if it is of the requested type and the MsgIDs match (if present).

Main loop

data MqttState Source

Internal state for the main loop

Constructors

MqttState 

Fields

msParseCC :: ParseCC

Current parser continuation

msUnconsumed :: ByteString

Not yet parsed input

msWaiting :: [AwaitMessage]

Messages we're waiting for

type ParseCC = ByteString -> IResult ByteString SomeMessageSource

data Input Source

Input for the main loop

parseBytes :: Monad m => ByteString -> StateT MqttState m (Maybe Input)Source

Parse the given ByteString and update the current MqttState.

Returns Nothing if more input is needed.

Misc