From 2fd045d59b06ff1b4fc9cf412118ad58cf2e92ac Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 3 Mar 2018 09:57:11 +0000 Subject: [PATCH] Fix STM blocking on connecting When attempting to connect to an address that doesn't exist, startEuphConnection now doesn't result in a thread blocked by an STM transaction any more. It now throws a simple ConnectionFailed exception. --- src/EuphApi/Connection.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/EuphApi/Connection.hs b/src/EuphApi/Connection.hs index b8624d9..ef47391 100644 --- a/src/EuphApi/Connection.hs +++ b/src/EuphApi/Connection.hs @@ -107,13 +107,16 @@ startEuphConnection host room = do let euphCon = Connection locked sendQueue eventQueue void $ forkIO - $ handle (handleException eventQueue) + $ handle (handleIOException eventQueue) + $ handle (handleHandshakeException eventQueue) $ WSS.runSecureClient host 443 ("/room/" ++ room ++ "/ws") $ recvClient euphCon return euphCon where - handleException :: EventQueue -> WS.HandshakeException -> IO () - handleException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed + handleHandshakeException :: EventQueue -> WS.HandshakeException -> IO () + handleHandshakeException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed + handleIOException :: EventQueue -> IOException -> IO () + handleIOException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed {- - Send thread