Reverse DNS lookups on accept in network

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


Yitzchak Gale <gale at sefer.org> 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
              (do   
                 (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?
    
[1]: http://hackage.haskell.org/packages/archive/network/2.4.1.2/doc/html/src/Network.html#accept



More information about the Libraries mailing list