readping fd's and flushing buffers
Simon Marlow
simonmar@microsoft.com
Fri, 10 Jan 2003 15:25:40 -0000
> A related problem... connections are refused when using accept if the
> hostname doesn't resolve. Maybe something like this would=20
> help, unless there
> is a better way?
>=20
> accept sock =3D do
> ~(sock', (SockAddrInet port haddr)) <- Socket.accept sock
> (HostEntry peer _ _ _) <- ((getHostByAddr AF_INET haddr)
> `Control.Exception.catch` (\_ ->
> return (HostEntry ((showHex ((haddr `shiftR` 24) .&. 0xff)=20
> . showChar '.'
> . showHex ((haddr `shiftR` 16) .&. 0xff)
> . showChar '.' . showHex ((haddr `shiftR` 8) .&. 0xff)=20
> . showChar '.'
> . showHex (haddr .&. 0xff)) "") [] AF_INET [])))
> handle <- socketToHandle sock' ReadWriteMode
> return (handle, peer, port)
Yes, except that inet_ntoa is the right way to get the string
representation of an IP address. I'll make this change.
Cheers,
Simon