concurrent-dns-cache 0.1.0 → 0.1.1
raw patch · 3 files changed
+59/−57 lines, 3 filesdep ~dnsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: dns
API changes (from Hackage documentation)
Files
- concurrent-dns-cache.cabal +6/−4
- main.hs +0/−53
- test/main.hs +53/−0
concurrent-dns-cache.cabal view
@@ -1,5 +1,5 @@ Name: concurrent-dns-cache-Version: 0.1.0+Version: 0.1.1 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3@@ -24,7 +24,7 @@ , async , bytestring >= 0.10.4.0 , containers- , dns+ , dns < 3 , iproute , lifted-base , monad-control@@ -38,12 +38,14 @@ Main-Is: main.hs Default-Language: Haskell2010 GHC-Options: -Wall -threaded+ Hs-Source-Dirs: test Build-Depends: base >= 4 && < 5 , array , async , bytestring >= 0.10.4.0+ , concurrent-dns-cache , containers- , dns+ , dns < 3 , iproute , lifted-base , monad-control@@ -62,7 +64,7 @@ Build-Depends: base >= 4 && < 5 , async , concurrent-dns-cache- , dns+ , dns < 3 , hspec Source-Repository head
− main.hs
@@ -1,53 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}--module Main where--import Control.Concurrent (forkIO)-import Control.Exception (try, SomeException(..))-import Control.Monad (void, when)-import qualified Data.ByteString.Char8 as BS-import Network.DNS-import Network.DNS.Cache as DNSC-import Data.Time--confs :: [ResolvConf]-confs = [- defaultResolvConf { resolvInfo = RCHostName "8.8.8.8" }- , defaultResolvConf { resolvInfo = RCHostName "8.8.4.4" }- ]--maxCon :: Int-maxCon = 50--cacheConf :: DNSCacheConf-cacheConf = DNSCacheConf {- resolvConfs = confs- , maxConcurrency = maxCon- , minTTL = 60- , maxTTL = 300- , negativeTTL = 300- }--main :: IO ()-main = do- beg <- getCurrentTime- withDNSCache cacheConf (loop 1 beg)- where- loop :: Int -> UTCTime -> DNSCache -> IO ()- loop n beg cache = do- when (n `mod` 1000 == 0) $ do- cur <- getCurrentTime- putStrLn $ show n ++ ": " ++ show (cur `diffUTCTime` beg)- edom <- try BS.getLine- case edom of- Left (SomeException _) -> do- wait cache (== 0)- putStrLn "Done."- Right dom -> do- wait cache (< maxCon)- void $ forkIO (DNSC.resolve cache dom >>= p dom)- loop (n+1) beg cache- p _ (Right _) = return ()- p dom (Left e) = do- putStr $ show e ++ " "- BS.putStrLn dom
+ test/main.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import Control.Concurrent (forkIO)+import Control.Exception (try, SomeException(..))+import Control.Monad (void, when)+import qualified Data.ByteString.Char8 as BS+import Network.DNS+import Network.DNS.Cache as DNSC+import Data.Time++confs :: [ResolvConf]+confs = [+ defaultResolvConf { resolvInfo = RCHostName "8.8.8.8" }+ , defaultResolvConf { resolvInfo = RCHostName "8.8.4.4" }+ ]++maxCon :: Int+maxCon = 50++cacheConf :: DNSCacheConf+cacheConf = DNSCacheConf {+ resolvConfs = confs+ , maxConcurrency = maxCon+ , minTTL = 60+ , maxTTL = 300+ , negativeTTL = 300+ }++main :: IO ()+main = do+ beg <- getCurrentTime+ withDNSCache cacheConf (loop 1 beg)+ where+ loop :: Int -> UTCTime -> DNSCache -> IO ()+ loop n beg cache = do+ when (n `mod` 1000 == 0) $ do+ cur <- getCurrentTime+ putStrLn $ show n ++ ": " ++ show (cur `diffUTCTime` beg)+ edom <- try BS.getLine+ case edom of+ Left (SomeException _) -> do+ wait cache (== 0)+ putStrLn "Done."+ Right dom -> do+ wait cache (< maxCon)+ void $ forkIO (DNSC.resolve cache dom >>= p dom)+ loop (n+1) beg cache+ p _ (Right _) = return ()+ p dom (Left e) = do+ putStr $ show e ++ " "+ BS.putStrLn dom