packages feed

concurrent-dns-cache 0.0.0 → 0.0.1

raw patch · 4 files changed

+19/−11 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Network/DNS/Cache.hs view
@@ -19,7 +19,7 @@   ) where  import Control.Applicative ((<$>))-import Control.Concurrent (threadDelay, forkIO)+import Control.Concurrent (threadDelay, forkIO, killThread) import Control.Concurrent.Async (async, waitAnyCancel) import Control.Exception (bracket) import Control.Monad (forever, void)@@ -78,8 +78,7 @@     activeref <- S.newActiveRef     lvar <- S.newConcVar     let cache = DNSCache seeds n cacheref activeref lvar maxcon minttl maxttl negttl-    void . forkIO $ prune cacheref-    func cache+    bracket (forkIO $ prune cacheref) killThread (const $ func cache)   where     maxcon = maxConcurrency conf     minttl = minTTL conf@@ -121,7 +120,7 @@ resolveCache _ dom   | isIPAddr dom       = Just . Right . Numeric <$> return (tov4 dom)   where-    tov4 = read . BS.unpack+    tov4 = toHostAddress . read . BS.unpack resolveCache cache dom = do     (_, mx) <- lookupPSQ cache dom     case mx of@@ -136,7 +135,7 @@ resolve _     dom   | isIPAddr dom            = return $ Right $ Numeric $ tov4 dom   where-    tov4 = read . BS.unpack+    tov4 = toHostAddress . read . BS.unpack resolve cache dom = do     (key,mx) <- lookupPSQ cache dom     case mx of@@ -158,10 +157,12 @@                         Right []    -> insertNegative cache key UnexpectedRDATA                         Right addrs -> insertPositive cache key addrs                     S.deleteActiveRef key activeref-                    S.tell avar res+                    S.tell avar (toHit res)                     return res   where     activeref = cacheActiveRef cache+    toHit (Right (Resolved addr)) = Right (Hit addr)+    toHit x                       = x  insertPositive :: DNSCache -> Key -> [(HostAddress, TTL)]                -> IO (Either DNSError Result)
Network/DNS/Cache/Value.hs view
@@ -13,7 +13,7 @@     return $! Right val   where     !siz = length addrs-    !next = adjust 0 siz+    !next = adjust 0 (siz-1)     !arr = listArray (0,siz-1) addrs  rotate :: Value -> IO HostAddress@@ -25,4 +25,4 @@  adjust :: Int -> Int -> Int adjust i 0 = i-adjust i n = let !x = (i + 1) `mod` n in x+adjust i n = let !x = (i + 1) `mod` (n + 1) in x
concurrent-dns-cache.cabal view
@@ -1,5 +1,5 @@ Name:                   concurrent-dns-cache-Version:                0.0.0+Version:                0.0.1 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -55,6 +55,7 @@   Hs-Source-Dirs:       test   Type:                 exitcode-stdio-1.0   Build-Depends:        base >= 4 && < 5-                      , dns+                      , async                       , concurrent-dns-cache+                      , dns                       , hspec
test/CacheSpec.hs view
@@ -2,10 +2,11 @@  module CacheSpec where -import Test.Hspec+import Control.Concurrent.Async (concurrently) import Network.DNS hiding (lookup) import Network.DNS.Cache import Prelude hiding (lookup)+import Test.Hspec  cacheConf :: DNSCacheConf cacheConf = DNSCacheConf {@@ -42,3 +43,8 @@         resolveCache cache dom `shouldReturn` Just (Left err)         lookupCache  cache dom `shouldReturn` Nothing         lookup       cache dom `shouldReturn` Nothing+    it "waits for another query for the same domain" $ withDNSCache cacheConf $ \cache -> do+        let dom = "www.example.com"+            addr = 2010691677+        (res1,res2) <- concurrently (resolve cache dom) (resolve cache dom)+        [res1,res2] `shouldContain` [Right (Resolved addr),Right (Hit addr)]