My code is something like this:
connectFarEnc ip port = withSocketsDo $ do
addrinfo <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE]})) ip (Just port)
let addr = head addrinfo
sock <- socket (addrFamily addr) Stream defaultProtocol
connected <- timeout 2000000 $ connect sock (addrAddress addr)
print $ show connected
return (sock, connected)
I expect timeout of two second if cannot connect to the server, but it doesn't work. Instead, throw out an exception of connection failed, and quit the program.
How should I deal with this situation to avoid quit?