summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Server.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Presence/Server.hs b/Presence/Server.hs
index 1141f0b0..331829e7 100644
--- a/Presence/Server.hs
+++ b/Presence/Server.hs
@@ -241,7 +241,10 @@ server = do
241 mapM_ killListener (Map.elems listening) 241 mapM_ killListener (Map.elems listening)
242 let stopRetry (v,d) = do atomically $ writeTVar v False 242 let stopRetry (v,d) = do atomically $ writeTVar v False
243 interruptDelay d 243 interruptDelay d
244 retriers <- atomically . readTVar $ retrymap server 244 retriers <- atomically $ do
245 rmap <- readTVar $ retrymap server
246 writeTVar (retrymap server) Map.empty
247 return rmap
245 mapM_ stopRetry (Map.elems retriers) 248 mapM_ stopRetry (Map.elems retriers)
246 cons <- atomically . readTVar $ conmap server 249 cons <- atomically . readTVar $ conmap server
247 atomically $ mapM_ (connClose . snd) (Map.elems cons) 250 atomically $ mapM_ (connClose . snd) (Map.elems cons)
@@ -289,7 +292,16 @@ server = do
289 $ Map.lookup con map 292 $ Map.lookup con map
290 293
291 doit server (Connect addr params) = liftIO $ do 294 doit server (Connect addr params) = liftIO $ do
292 void . forkIO $ do 295 mb <- atomically $ do
296 rmap <- readTVar (retrymap server)
297 return $ Map.lookup addr rmap
298 maybe forkit
299 (\(v,d) -> do b <- atomically $ readTVar v
300 interruptDelay d
301 when (not b) forkit)
302 mb
303 where
304 forkit = void . forkIO $ do
293 proto <- getProtocolNumber "tcp" 305 proto <- getProtocolNumber "tcp"
294 sock <- bracketOnError 306 sock <- bracketOnError
295 (socket (socketFamily addr) Stream proto) 307 (socket (socketFamily addr) Stream proto)