From d27be4aaf8182bc8c5dd84c7b8cc7f5250614613 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Mon, 10 Dec 2018 14:25:23 -0500 Subject: Exception handling for TCP-relay client connect. --- src/Network/QueryResponse/TCP.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Network/QueryResponse/TCP.hs') diff --git a/src/Network/QueryResponse/TCP.hs b/src/Network/QueryResponse/TCP.hs index c0bdcd3c..154e9145 100644 --- a/src/Network/QueryResponse/TCP.hs +++ b/src/Network/QueryResponse/TCP.hs @@ -67,9 +67,12 @@ acquireConnection mvar tcpcache stream addr = do case MM.lookup' (TCPAddress $ streamAddr stream addr) cache of Nothing -> do proto <- getProtocolNumber "tcp" - sock <- socket (socketFamily $ streamAddr stream addr) Stream proto - connect sock (streamAddr stream addr) `catchIOError` (\e -> close sock) - h <- socketToHandle sock ReadWriteMode + mh <- catchIOError (do sock <- socket (socketFamily $ streamAddr stream addr) Stream proto + connect sock (streamAddr stream addr) `catchIOError` (\e -> close sock) + h <- socketToHandle sock ReadWriteMode + return $ Just h) + $ \e -> return Nothing + fmap join $ forM mh $ \h -> do st <- streamHello stream addr h t <- getPOSIXTime rthread <- forkIO $ fix $ \loop -> do -- cgit v1.2.3