readping fd's and flushing buffers

Keean Schupke k.schupke@ic.ac.uk
Thu, 09 Jan 2003 12:21:16 +0000


This may be related to the answer just given to do with finalizing the 
Handles, as I have a
problem with sockets hanging around after a host name resolution has 
failed (using the simple socket
library). Having looked at the code I would like to suggest the 
following change:

connectTo hostname (PortNumber port) = do
    proto   <- getProtocolNumber "tcp"
    sock        <- socket AF_INET Stream proto
    he     <- getHostByName hostname
    connect sock (SockAddrInet port (hostAddress he))
    socketToHandle sock ReadWriteMode

Should become:

connectTo hostname (PortNumber port) = 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` (\e -> do 
sClose sock;throw e)

Is this a sensible change to make?

    Regards,
    Keean Schupke.