hsdns-1.1Source codeContentsIndex
PortabilityHaskell 2-pre
Resolver API
This module provides a poll-based I/O scheduler for Network.DNS.ADNS. See the test.hs program included in the distribution for an example of how to use this resolver. Link your program with the threaded runtime-system when you use this module. In GHC, this is accomplished by specifying -threaded on the command-line.
type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer)
initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO a
resolveA :: Resolver -> HostName -> IO (Either Status [HostAddress])
resolvePTR :: Resolver -> HostAddress -> IO (Either Status [HostName])
resolveMX :: Resolver -> HostName -> IO (Either Status [(HostName, HostAddress)])
query :: (Resolver -> a -> IO (Either Status [b])) -> Resolver -> a -> IO (Maybe [b])
dummyDNS :: Resolver
data ResolverState = RState {
adns :: AdnsState
pollfds :: ForeignPtr Pollfd
capacity :: Int
queries :: [(Query, MVar Answer)]
resolve :: MVar ResolverState -> Resolver
resolveLoop :: MVar ResolverState -> IO ()
Resolver API
type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer)Source
A Resolver is an IO computation which -- given the name and type of the record to query -- returns an MVar that will eventually contain the Answer from the Domain Name System.
initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO aSource
Run the given IO computation with an Initialized Resolver. Note that resolver functions can be shared, and should be shared between any number of IO threads. You may use multiple resolvers, of course, but doing so defeats the purpose of an asynchronous resolver.
resolveA :: Resolver -> HostName -> IO (Either Status [HostAddress])Source
Resolve a hostname's A records.
resolvePTR :: Resolver -> HostAddress -> IO (Either Status [HostName])Source
Get the PTR records assigned to a host address. Note that although the API allows for a record to have more than one PTR entry, this will actually not happen because the GNU adns library can't handle this case and will return sINCONSISTENT.
resolveMX :: Resolver -> HostName -> IO (Either Status [(HostName, HostAddress)])Source
Resolve the mail exchangers for a hostname. The returned list may contain more than one entry per hostname, in case the host has several A records. The records are returned in the order you should try to contact them as determined by the priority in the RRMX response.
query :: (Resolver -> a -> IO (Either Status [b])) -> Resolver -> a -> IO (Maybe [b])Source

Convenience wrapper that will modify any of the revolveXXX functions above to return Maybe rather than Either. The idea is that Nothing signifies any sort of failure; Just [] signifies sNXDOMAIN; and everything else signifies sOK.

So if you aren't interested in getting accurate Status codes in case of failures. Wrap your DNS queries as follows:

 queryA :: Resolver -> HostName -> IO (Maybe [HostAddress])
 queryA = query resolveA
dummyDNS :: ResolverSource
Use this function to disable DNS resolving. It will always return (Answer sSYSTEMFAIL Nothing (Just host) (-1) []).
data ResolverState Source
The internal state of the resolver is stored in an MVar so that it is shared (and synchronized) between any number of concurrent IO threads.
adns :: AdnsStateopaque ADNS state
pollfds :: ForeignPtr Pollfdarray for poll(2)
capacity :: Intsize of the array
queries :: [(Query, MVar Answer)]currently open queries
resolve :: MVar ResolverState -> ResolverSource
Submit a DNS query to the resolver and check whether we have a running resolveLoop thread already. If we don't, start one with forkIO. Make sure you link the threaded RTS so that the main loop will not block other threads.
resolveLoop :: MVar ResolverState -> IO ()Source
Loop until all open queries have been resolved. Uses poll internally to avoid busy-polling the ADNS sockets.
Produced by Haddock version 2.4.2