mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-23 00:02:44 +00:00
smp-server: reuse resolver connection on errors
This commit is contained in:
1 parent
9f582e65f8
commit
cae0c4a4ad
3 files changed
+23
-4
No files matched your search
@@ -9,6 +9,7 @@
|
||||
module NamesResolverServer
|
||||
( withResolverServer,
|
||||
withResolverServerDelayed,
|
||||
withResolverServerConns,
|
||||
resolveResp,
|
||||
testNamesConfig,
|
||||
memCfg,
|
||||
@@ -36,9 +37,18 @@ withResolverServer :: ([Text] -> (Status, LB.ByteString)) -> (Int -> IORef [[Tex
|
||||
withResolverServer = withResolverServerDelayed 0
|
||||
|
||||
withResolverServerDelayed :: Int -> ([Text] -> (Status, LB.ByteString)) -> (Int -> IORef [[Text]] -> IO a) -> IO a
|
||||
withResolverServerDelayed delayMs handler action = do
|
||||
withResolverServerDelayed delayMs handler action = withResolverServer_ delayMs handler $ \port reqs _ -> action port reqs
|
||||
|
||||
-- | Also counts the TCP connections the resolver accepted.
|
||||
withResolverServerConns :: ([Text] -> (Status, LB.ByteString)) -> (Int -> IORef [[Text]] -> IORef Int -> IO a) -> IO a
|
||||
withResolverServerConns = withResolverServer_ 0
|
||||
|
||||
withResolverServer_ :: Int -> ([Text] -> (Status, LB.ByteString)) -> (Int -> IORef [[Text]] -> IORef Int -> IO a) -> IO a
|
||||
withResolverServer_ delayMs handler action = do
|
||||
reqs <- newIORef []
|
||||
Warp.withApplication (pure (app reqs)) $ \port -> action port reqs
|
||||
conns <- newIORef 0
|
||||
let settings = Warp.setOnOpen (\_ -> True <$ atomicModifyIORef' conns (\n -> (n + 1, ()))) Warp.defaultSettings
|
||||
Warp.withApplicationSettings settings (pure (app reqs)) $ \port -> action port reqs conns
|
||||
where
|
||||
app :: IORef [[Text]] -> Application
|
||||
app reqs req send = do
|
||||
|
||||
Reference in new issue
Block a user