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.
This commit is contained in:
Joscha 2018-03-03 09:57:11 +00:00
parent d818aba337
commit 2fd045d59b

View file

@ -107,13 +107,16 @@ startEuphConnection host room = do
let euphCon = Connection locked sendQueue eventQueue let euphCon = Connection locked sendQueue eventQueue
void void
$ forkIO $ forkIO
$ handle (handleException eventQueue) $ handle (handleIOException eventQueue)
$ handle (handleHandshakeException eventQueue)
$ WSS.runSecureClient host 443 ("/room/" ++ room ++ "/ws") $ WSS.runSecureClient host 443 ("/room/" ++ room ++ "/ws")
$ recvClient euphCon $ recvClient euphCon
return euphCon return euphCon
where where
handleException :: EventQueue -> WS.HandshakeException -> IO () handleHandshakeException :: EventQueue -> WS.HandshakeException -> IO ()
handleException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed handleHandshakeException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed
handleIOException :: EventQueue -> IOException -> IO ()
handleIOException qEvent _ = atomically $ writeTBQueue qEvent ConnectionFailed
{- {-
- Send thread - Send thread