diff options
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/Server.hs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/Presence/Server.hs b/Presence/Server.hs index f82a93c5..1e46c051 100644 --- a/Presence/Server.hs +++ b/Presence/Server.hs | |||
@@ -6,6 +6,7 @@ | |||
6 | {-# LANGUAGE RankNTypes #-} | 6 | {-# LANGUAGE RankNTypes #-} |
7 | {-# LANGUAGE StandaloneDeriving #-} | 7 | {-# LANGUAGE StandaloneDeriving #-} |
8 | {-# LANGUAGE TupleSections #-} | 8 | {-# LANGUAGE TupleSections #-} |
9 | {-# LANGUAGE LambdaCase #-} | ||
9 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
10 | -- | | 11 | -- | |
11 | -- Module : Server | 12 | -- Module : Server |
@@ -313,15 +314,13 @@ server allocate = do | |||
313 | (post <=< flip connWrite bs . cstate) | 314 | (post <=< flip connWrite bs . cstate) |
314 | $ Map.lookup con map | 315 | $ Map.lookup con map |
315 | 316 | ||
316 | doit server (Connect addr params) = do | 317 | doit server (Connect addr params) = join $ atomically $ do |
317 | mb <- atomically $ do | 318 | Map.lookup addr <$> readTVar (retrymap server) |
318 | rmap <- readTVar (retrymap server) | 319 | >>= return . \case |
319 | return $ Map.lookup addr rmap | 320 | Nothing -> forkit |
320 | maybe forkit | 321 | Just (v,d) -> do b <- atomically $ readTVar v |
321 | (\(v,d) -> do b <- atomically $ readTVar v | 322 | interruptDelay d |
322 | interruptDelay d | 323 | when (not b) forkit |
323 | when (not b) forkit) | ||
324 | mb | ||
325 | where | 324 | where |
326 | forkit = void . forkIO $ do | 325 | forkit = void . forkIO $ do |
327 | proto <- getProtocolNumber "tcp" | 326 | proto <- getProtocolNumber "tcp" |
@@ -347,17 +346,14 @@ server allocate = do | |||
347 | resultVar <- atomically newEmptyTMVar | 346 | resultVar <- atomically newEmptyTMVar |
348 | timer <- interruptibleDelay | 347 | timer <- interruptibleDelay |
349 | (retryVar,action) <- atomically $ do | 348 | (retryVar,action) <- atomically $ do |
350 | let noop = return () | ||
351 | map <- readTVar (retrymap server) | 349 | map <- readTVar (retrymap server) |
352 | let mb = Map.lookup addr map | 350 | action <- case Map.lookup addr map of |
353 | action <- | 351 | Nothing -> return $ return () |
354 | maybe (return noop) | 352 | Just (v,d) -> do writeTVar v False |
355 | (\(v,d) -> do writeTVar v False | 353 | return $ interruptDelay d |
356 | return $ interruptDelay d) | ||
357 | mb | ||
358 | v <- newTVar True | 354 | v <- newTVar True |
359 | writeTVar (retrymap server) (Map.insert addr (v,timer) map) | 355 | writeTVar (retrymap server) $! Map.insert addr (v,timer) map |
360 | return (v,action) | 356 | return (v,action :: IO ()) |
361 | action | 357 | action |
362 | fix $ \retryLoop -> do | 358 | fix $ \retryLoop -> do |
363 | utc <- getCurrentTime | 359 | utc <- getCurrentTime |