Skip to content

Commit

Permalink
doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Feb 17, 2014
1 parent 22c1863 commit 97578f1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Network/DNS/Resolver.hs
Expand Up @@ -46,16 +46,18 @@ import Control.Monad (when)
-- --
-- >>> let cache = RCHostName "8.8.8.8" -- >>> let cache = RCHostName "8.8.8.8"
-- --
data FileOrNumericHost = RCFilePath FilePath | RCHostName HostName data FileOrNumericHost = RCFilePath FilePath -- ^ A path for \"resolv.conf\"

| RCHostName HostName -- ^ A numeric IP address


-- | Type for resolver configuration. The easiest way to construct a -- | Type for resolver configuration. The easiest way to construct a
-- @ResolvConf@ object is to modify the 'defaultResolvConf'. -- @ResolvConf@ object is to modify the 'defaultResolvConf'.
data ResolvConf = ResolvConf { data ResolvConf = ResolvConf {
resolvInfo :: FileOrNumericHost resolvInfo :: FileOrNumericHost
-- | Timeout in micro seconds.
, resolvTimeout :: Int , resolvTimeout :: Int
-- | The number of retries including the first try.
, resolvRetry :: Int , resolvRetry :: Int
-- | This field was obsoleted. -- | This field was obsoleted.
, resolvBufsize :: Integer , resolvBufsize :: Integer
} }


Expand Down Expand Up @@ -85,7 +87,8 @@ defaultResolvConf = ResolvConf {


---------------------------------------------------------------- ----------------------------------------------------------------


-- | Abstract data type of DNS Resolver seed -- | Abstract data type of DNS Resolver seed.
-- When implementing a DNS cache, this should be re-used.
data ResolvSeed = ResolvSeed { data ResolvSeed = ResolvSeed {
addrInfo :: AddrInfo addrInfo :: AddrInfo
, rsTimeout :: Int , rsTimeout :: Int
Expand All @@ -94,6 +97,7 @@ data ResolvSeed = ResolvSeed {
} }


-- | Abstract data type of DNS Resolver -- | Abstract data type of DNS Resolver
-- When implementing a DNS cache, this MUST NOT be re-used.
data Resolver = Resolver { data Resolver = Resolver {
genId :: IO Int genId :: IO Int
, dnsSock :: Socket , dnsSock :: Socket
Expand Down Expand Up @@ -139,13 +143,14 @@ makeAddrInfo addr = do




-- | Giving a thread-safe 'Resolver' to the function of the second -- | Giving a thread-safe 'Resolver' to the function of the second
-- argument. 'withResolver' should be passed to 'forkIO'. For -- argument. A socket for UDP is opened inside and is surely closed.
-- examples, see "Network.DNS.Lookup".
withResolver :: ResolvSeed -> (Resolver -> IO a) -> IO a withResolver :: ResolvSeed -> (Resolver -> IO a) -> IO a
withResolver seed func = bracket (openSocket seed) sClose $ \sock -> do withResolver seed func = bracket (openSocket seed) sClose $ \sock -> do
connectSocket sock seed connectSocket sock seed
func $ makeResolver seed sock func $ makeResolver seed sock


-- | Giving thread-safe 'Resolver's to the function of the second
-- argument. Sockets for UDP are opened inside and are surely closed.
withResolvers :: [ResolvSeed] -> ([Resolver] -> IO a) -> IO a withResolvers :: [ResolvSeed] -> ([Resolver] -> IO a) -> IO a
withResolvers seeds func = bracket openSockets closeSockets $ \socks -> do withResolvers seeds func = bracket openSockets closeSockets $ \socks -> do
mapM_ (uncurry connectSocket) $ zip socks seeds mapM_ (uncurry connectSocket) $ zip socks seeds
Expand Down

0 comments on commit 97578f1

Please sign in to comment.