summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client/Handle.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-04-04 01:22:27 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-04-04 01:22:27 +0400
commit2a64b6b3e5766242d012baefde7bca54adc675f1 (patch)
treed92df65ddb60b6f9e923ed4fba69083aec021d21 /src/Network/BitTorrent/Client/Handle.hs
parentc3e85d6baeba53168ed9dd2157f9b8f70bb1532d (diff)
[Client] Use lifted concurrent operations
Diffstat (limited to 'src/Network/BitTorrent/Client/Handle.hs')
-rw-r--r--src/Network/BitTorrent/Client/Handle.hs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs
index 6e2dd0dc..2da3b357 100644
--- a/src/Network/BitTorrent/Client/Handle.hs
+++ b/src/Network/BitTorrent/Client/Handle.hs
@@ -19,7 +19,7 @@ module Network.BitTorrent.Client.Handle
19 ) where 19 ) where
20 20
21import Control.Applicative 21import Control.Applicative
22import Control.Concurrent 22import Control.Concurrent.Lifted as L
23import Control.Monad 23import Control.Monad
24import Control.Monad.Trans 24import Control.Monad.Trans
25import Data.Default 25import Data.Default
@@ -40,28 +40,28 @@ import Network.BitTorrent.Tracker as Tracker
40 40
41allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle 41allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle
42allocHandle ih m = do 42allocHandle ih m = do
43 c @ Client {..} <- getClient 43 Client {..} <- getClient
44 liftIO $ modifyMVar clientTorrents $ \ handles -> do 44 modifyMVar clientTorrents $ \ handles -> do
45 case HM.lookup ih handles of 45 case HM.lookup ih handles of
46 Just h -> return (handles, h) 46 Just h -> return (handles, h)
47 Nothing -> do 47 Nothing -> do
48 h <- runBitTorrent c m 48 h <- m
49 return (HM.insert ih h handles, h) 49 return (HM.insert ih h handles, h)
50 50
51freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () 51freeHandle :: InfoHash -> BitTorrent () -> BitTorrent ()
52freeHandle ih finalizer = do 52freeHandle ih finalizer = do
53 c @ Client {..} <- getClient 53 c @ Client {..} <- getClient
54 liftIO $ modifyMVar_ clientTorrents $ \ handles -> do 54 modifyMVar_ clientTorrents $ \ handles -> do
55 case HM.lookup ih handles of 55 case HM.lookup ih handles of
56 Nothing -> return handles 56 Nothing -> return handles
57 Just _ -> do 57 Just _ -> do
58 runBitTorrent c finalizer 58 finalizer
59 return (HM.delete ih handles) 59 return (HM.delete ih handles)
60 60
61lookupHandle :: InfoHash -> BitTorrent (Maybe Handle) 61lookupHandle :: InfoHash -> BitTorrent (Maybe Handle)
62lookupHandle ih = do 62lookupHandle ih = do
63 Client {..} <- getClient 63 Client {..} <- getClient
64 handles <- liftIO $ readMVar clientTorrents 64 handles <- readMVar clientTorrents
65 return (HM.lookup ih handles) 65 return (HM.lookup ih handles)
66 66
67{----------------------------------------------------------------------- 67{-----------------------------------------------------------------------