aboutsummaryrefslogtreecommitdiff
path: root/hsm-core/Hsm
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-01-28 21:59:21 +0000
committerPaul Oliver <contact@pauloliver.dev>2025-01-29 04:13:02 +0000
commit194800033037f25f4c9fdae365f63f6abe0e110c (patch)
treef92ffe59b3850c6c2325d8a2c2637ff87c5ac40f /hsm-core/Hsm
parent9d2f95bb58f856aaf9142426e90e5783c98af8f1 (diff)
Adds logging domain to ZMQ resource operations
Diffstat (limited to 'hsm-core/Hsm')
-rw-r--r--hsm-core/Hsm/Core/Zmq/Client.hs24
-rw-r--r--hsm-core/Hsm/Core/Zmq/Server.hs20
2 files changed, 24 insertions, 20 deletions
diff --git a/hsm-core/Hsm/Core/Zmq/Client.hs b/hsm-core/Hsm/Core/Zmq/Client.hs
index 97728f7..aa74ed3 100644
--- a/hsm-core/Hsm/Core/Zmq/Client.hs
+++ b/hsm-core/Hsm/Core/Zmq/Client.hs
@@ -75,14 +75,16 @@ runClient ::
)
=> Eff (Client : es) a
-> Eff es a
-runClient action =
- withSocket Z.Sub >>= \sock ->
- E.evalStaticRep (Client sock) $ do
- localDomain domain $ do
- logInfo_ "Initializing ZMQ client"
- env <- ask @env
- forM_ env.subEps $ E.unsafeEff_ . Z.connect sock . unpack
- forM_ env.topics $ E.unsafeEff_ . Z.subscribe sock . encodeUtf8
- logTrace_ $ "Listening to " <> pack (show env.subEps)
- logTrace_ $ "Subscribed to " <> pack (show env.topics)
- action
+runClient action = do
+ sock <- localDomain domain $ withSocket Z.Sub
+ E.evalStaticRep (Client sock) $ do
+ localDomain domain $ initialize sock
+ action
+ where
+ initialize sock = do
+ logInfo_ "Initializing ZMQ client"
+ env <- ask @env
+ forM_ env.subEps $ E.unsafeEff_ . Z.connect sock . unpack
+ forM_ env.topics $ E.unsafeEff_ . Z.subscribe sock . encodeUtf8
+ logTrace_ $ "Listening to " <> pack (show env.subEps)
+ logTrace_ $ "Subscribed to " <> pack (show env.topics)
diff --git a/hsm-core/Hsm/Core/Zmq/Server.hs b/hsm-core/Hsm/Core/Zmq/Server.hs
index 6ea8aeb..fd2f159 100644
--- a/hsm-core/Hsm/Core/Zmq/Server.hs
+++ b/hsm-core/Hsm/Core/Zmq/Server.hs
@@ -54,12 +54,14 @@ runServer ::
)
=> Eff (Server : es) a
-> Eff es a
-runServer action =
- withSocket Z.Pub >>= \sock ->
- E.evalStaticRep (Server sock) $ do
- localDomain domain $ do
- logInfo_ "Initializing ZMQ server"
- env <- ask @env
- E.unsafeEff_ $ Z.bind sock $ unpack env.pubEp
- logTrace_ $ "Publishing to " <> env.pubEp
- action
+runServer action = do
+ sock <- localDomain domain $ withSocket Z.Pub
+ E.evalStaticRep (Server sock) $ do
+ localDomain domain $ initialize sock
+ action
+ where
+ initialize sock = do
+ logInfo_ "Initializing ZMQ server"
+ env <- ask @env
+ E.unsafeEff_ $ Z.bind sock $ unpack env.pubEp
+ logTrace_ $ "Publishing to " <> env.pubEp