packages feed

net-mqtt 0.6.0.1 → 0.6.0.2

raw patch · 4 files changed

+45/−21 lines, 4 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Network.MQTT.Client: BadData :: MQTTException
+ Network.MQTT.Client: Discod :: DisconnectRequest -> MQTTException
+ Network.MQTT.Client: MQTTException :: String -> MQTTException
+ Network.MQTT.Client: Timeout :: MQTTException
+ Network.MQTT.Client: data MQTTException
+ Network.MQTT.Client: isConnectedSTM :: MQTTClient -> STM Bool

Files

Changelog.md view
@@ -1,5 +1,15 @@ # Changelog for net-mqtt +## 0.6.0.2++Export MQTTException (thrown from various internal bits).++Added isConnectedSTM for verifying connection state inside of STM+transactions (e.g., verifying you're connected while also waiting for+a value in a TChan).++Also, mqtt-watch reconnects on error now.+ ## 0.6.0.1  Relaxed QuickCheck constraint slightly.
app/mqtt-watch/Main.hs view
@@ -1,11 +1,14 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RecordWildCards   #-}+{-# LANGUAGE OverloadedStrings   #-}+{-# LANGUAGE RecordWildCards     #-}+{-# LANGUAGE ScopedTypeVariables #-}  module Main where +import           Control.Concurrent       (threadDelay) import           Control.Concurrent.Async (async, link) import           Control.Concurrent.STM   (TChan, atomically, newTChanIO,                                            readTChan, writeTChan)+import           Control.Exception        (Handler (..), IOException, catches) import           Control.Monad            (forever, void, when) import qualified Data.ByteString.Lazy     as BL import           Data.Maybe               (fromJust)@@ -46,18 +49,25 @@   ch <- newTChanIO   async (printer ch (not optHideProps)) >>= link -  mc <- connectURI mqttConfig{_msgCB=SimpleCallback (showme ch), _protocol=Protocol50,-                              _connProps=[PropReceiveMaximum 65535,-                                          PropTopicAliasMaximum 10,-                                          PropRequestResponseInformation 1,-                                          PropRequestProblemInformation 1]}+  forever $ catches (go ch) [Handler (\(ex :: MQTTException) -> handler (show ex)),+                             Handler (\(ex :: IOException) -> handler (show ex))]++  where+    go ch = do+      mc <- connectURI mqttConfig{_msgCB=SimpleCallback (showme ch), _protocol=Protocol50,+                                  _connProps=[PropReceiveMaximum 65535,+                                              PropTopicAliasMaximum 10,+                                              PropRequestResponseInformation 1,+                                              PropRequestProblemInformation 1]}         optUri -  void $ subscribe mc [(t, subOptions) | t <- optTopics] mempty+      void $ subscribe mc [(t, subOptions) | t <- optTopics] mempty -  print =<< waitForClient mc+      print =<< waitForClient mc -    where showme ch _ t m props = atomically $ writeTChan ch $ Msg t m props+    showme ch _ t m props = atomically $ writeTChan ch $ Msg t m props++    handler e = putStrLn ("ERROR: " <> e) >> threadDelay 1000000  main :: IO () main = run =<< execParser opts
net-mqtt.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.1.+-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 2d689138895486415ae00cada1b378197a188735047e04bd037c0f147fdd81f5+-- hash: 0cfcfaf1554a40ae7f8ade026cc7d416ad0f198dd2a780919b6f4a6789ccc83d  name:           net-mqtt-version:        0.6.0.1+version:        0.6.0.2 synopsis:       An MQTT Protocol Implementation. description:    Please see the README on GitHub at <https://github.com/dustin/mqtt-hs#readme> category:       Network
src/Network/MQTT/Client.hs view
@@ -28,9 +28,9 @@   disconnect, normalDisconnect,   -- * General client interactions.   subscribe, unsubscribe, publish, publishq, pubAliased,-  svrProps,+  svrProps, MQTTException(..),   -- * Low-level bits-  runMQTTConduit, MQTTConduit+  runMQTTConduit, MQTTConduit, isConnectedSTM   ) where  import           Control.Concurrent         (threadDelay)@@ -142,7 +142,7 @@ -- >   mc <- connectURI mqttConfig{} uri -- >   publish mc "tmp/topic" "hello!" False connectURI :: MQTTConfig -> URI -> IO MQTTClient-connectURI cfg@(MQTTConfig{..}) uri = do+connectURI cfg@MQTTConfig{..} uri = do   let cf = case uriScheme uri of              "mqtt:"  -> runClient              "mqtts:" -> runClientTLS@@ -188,12 +188,12 @@  -- Compatibility mechanisms for TCP Conduit bits. tcpCompat :: ((AppData -> IO ()) -> IO ()) -> MQTTConfig -> IO MQTTClient-tcpCompat mkconn cfg = runMQTTConduit (adapt mkconn) cfg+tcpCompat mkconn = runMQTTConduit (adapt mkconn)   where adapt mk f = mk (f . adaptor)         adaptor ad = (appSource ad, appSink ad)  runWS :: URI -> Bool -> MQTTConfig -> IO MQTTClient-runWS uri secure cfg@MQTTConfig{..} = runMQTTConduit (adapt $ (cf secure) _hostname _port (uriPath uri) WS.defaultConnectionOptions hdrs) cfg+runWS uri secure cfg@MQTTConfig{..} = runMQTTConduit (adapt $ cf secure _hostname _port (uriPath uri) WS.defaultConnectionOptions hdrs) cfg   where     hdrs = [("Sec-WebSocket-Protocol", "mqtt")]     adapt mk f = mk (f . adaptor)@@ -432,10 +432,14 @@     Nothing -> pure ()     Just x  -> E.throw x --- | True if we're currently in a normally connected state.+-- | True if we're currently in a normally connected state (in the IO monad). isConnected :: MQTTClient -> IO Bool-isConnected MQTTClient{..} = (Connected ==) <$> readTVarIO _st+isConnected = atomically . isConnectedSTM +-- | True if we're currently in a normally connected state (in the STM monad).+isConnectedSTM :: MQTTClient -> STM Bool+isConnectedSTM MQTTClient{..} = (Connected ==) <$> readTVar _st+ sendPacket :: MQTTClient -> MQTTPkt -> STM () sendPacket c@MQTTClient{..} p = checkConnected c >> writeTChan _ch p @@ -554,7 +558,7 @@                 when (st /= 0) $ mqttFail ("qos 2 REC publish error: " <> show st <> " " <> show recprops)                 sendPacketIO c (PubRELPkt $ PubREL pid 0 mempty)                 cancel p -- must not publish after rel-              PubCOMPPkt (PubCOMP _ st' compprops) -> do+              PubCOMPPkt (PubCOMP _ st' compprops) ->                 when (st' /= 0) $ mqttFail ("qos 2 COMP publish error: " <> show st' <> " " <> show compprops)               wtf -> mqttFail ("unexpected packet received in QoS2 publish: " <> show wtf)