diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-27 14:36:20 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-27 14:36:20 -0400 |
commit | ceedcd65ddbc74ea1bdc186db6c19f5466674659 (patch) | |
tree | ff96be192a087cfc8c6c08dda0b54fe89a9fe4c6 | |
parent | bf8c9ffe2fc678b4414d28de55224cb044012229 (diff) |
when xmpp connection fails, show the host(s) it tried to connect to
-rw-r--r-- | Assistant/XMPP/Client.hs | 29 | ||||
-rw-r--r-- | Utility/SRV.hs | 1 |
2 files changed, 19 insertions, 11 deletions
diff --git a/Assistant/XMPP/Client.hs b/Assistant/XMPP/Client.hs index c2a86cb41..960073036 100644 --- a/Assistant/XMPP/Client.hs +++ b/Assistant/XMPP/Client.hs @@ -27,36 +27,43 @@ data XMPPCreds = XMPPCreds } deriving (Read, Show) -connectXMPP :: XMPPCreds -> (JID -> XMPP a) -> IO (Either SomeException ()) +connectXMPP :: XMPPCreds -> (JID -> XMPP a) -> IO [(HostPort, Either SomeException ())] connectXMPP c a = case parseJID (xmppJID c) of Nothing -> error "bad JID" Just jid -> connectXMPP' jid c a {- Do a SRV lookup, but if it fails, fall back to the cached xmppHostname. -} -connectXMPP' :: JID -> XMPPCreds -> (JID -> XMPP a) -> IO (Either SomeException ()) -connectXMPP' jid c a = go =<< lookupSRV srvrecord +connectXMPP' :: JID -> XMPPCreds -> (JID -> XMPP a) -> IO [(HostPort, Either SomeException ())] +connectXMPP' jid c a = reverse <$> (go [] =<< lookupSRV srvrecord) where srvrecord = mkSRVTcp "xmpp-client" $ T.unpack $ strDomain $ jidDomain jid serverjid = JID Nothing (jidDomain jid) Nothing - go [] = run (xmppHostname c) - (PortNumber $ fromIntegral $ xmppPort c) - (a jid) - go ((h,p):rest) = do + go l [] = do + let h = xmppHostname c + let p = PortNumber $ fromIntegral $ xmppPort c + r <- run h p $ a jid + return (r : l) + go l ((h,p):rest) = do {- Try each SRV record in turn, until one connects, - at which point the MVar will be full. -} mv <- newEmptyMVar r <- run h p $ do liftIO $ putMVar mv () a jid - ifM (isEmptyMVar mv) (go rest, return r) + ifM (isEmptyMVar mv) + ( go (r : l) rest + , return (r : l) + ) {- Async exceptions are let through so the XMPP thread can - be killed. -} - run h p a' = tryNonAsync $ - runClientError (Server serverjid h p) jid - (xmppUsername c) (xmppPassword c) (void a') + run h p a' = do + r <- tryNonAsync $ + runClientError (Server serverjid h p) jid + (xmppUsername c) (xmppPassword c) (void a') + return ((h, p), r) {- XMPP runClient, that throws errors rather than returning an Either -} runClientError :: Server -> JID -> T.Text -> T.Text -> XMPP a -> IO a diff --git a/Utility/SRV.hs b/Utility/SRV.hs index b39bf71b2..da1342c2c 100644 --- a/Utility/SRV.hs +++ b/Utility/SRV.hs @@ -15,6 +15,7 @@ module Utility.SRV ( mkSRV, lookupSRV, lookupSRVHost, + HostPort, ) where import Utility.Process |