Reverse DNS lookups on accept in network

Herbert Valerio Riedel hvr at
Wed Apr 10 10:08:09 CEST 2013

Yitzchak Gale <gale at> writes:


> Although the function Network.accept
> does an implied reverse DNS lookup,
> it does so lazily. So the actual lookup
> should not happen unless the library client
> actually tries to use the host name.

I've looked at the source code but I don't recognize how the lazyness is
achieved w.r.t. to the RDNS lookup, here's the relevant source fragment
from [1]:

    accept sock@(MkSocket _ AF_INET _ _ _) = do
        ~(sock', (SockAddrInet port haddr)) <- Socket.accept sock
        peer <- catchIO
                 (HostEntry peer _ _ _) <- getHostByAddr AF_INET haddr
                 return peer
              (\_e -> inet_ntoa haddr)
        handle <- socketToHandle sock' ReadWriteMode
        return (handle, peer, port)

the blocking operation would be 'getHostByAddr' but I don't see any
measure to turn that into a lazy I/O operation. What am I overlooking?

More information about the Libraries mailing list