readping fd's and flushing buffers

Simon Marlow simonmar@microsoft.com
Thu, 9 Jan 2003 13:18:04 -0000


> This may be related to the answer just given to do with=20
> finalizing the=20
> Handles, as I have a
> problem with sockets hanging around after a host name resolution has=20
> failed (using the simple socket
> library). Having looked at the code I would like to suggest the=20
> following change:
>=20
> connectTo hostname (PortNumber port) =3D do
>     proto   <- getProtocolNumber "tcp"
>     sock        <- socket AF_INET Stream proto
>     he     <- getHostByName hostname
>     connect sock (SockAddrInet port (hostAddress he))
>     socketToHandle sock ReadWriteMode
>=20
> Should become:
>=20
> connectTo hostname (PortNumber port) =3D do
>     proto   <- getProtocolNumber "tcp"
>     sock        <- socket AF_INET Stream proto
>     (do
>         he     <- getHostByName hostname
>         connect sock (SockAddrInet port (hostAddress he))
>         socketToHandle sock ReadWriteMode) `Exception.catch`=20
> (\e -> do=20
> sClose sock;throw e)
>=20
> Is this a sensible change to make?

Yes, well spotted.  I'll add the exception handler.

Cheers,
	Simon