summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Client')
-rw-r--r--src/Network/BitTorrent/Client/Handle.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs
index a1bc163c..19ad1675 100644
--- a/src/Network/BitTorrent/Client/Handle.hs
+++ b/src/Network/BitTorrent/Client/Handle.hs
@@ -18,6 +18,7 @@ module Network.BitTorrent.Client.Handle
18 , getStatus 18 , getStatus
19 ) where 19 ) where
20 20
21import Control.Concurrent.Chan.Split
21import Control.Concurrent.Lifted as L 22import Control.Concurrent.Lifted as L
22import Control.Monad 23import Control.Monad
23import Control.Monad.Trans 24import Control.Monad.Trans
@@ -40,16 +41,23 @@ import Network.BitTorrent.Tracker as Tracker
40allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle 41allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle
41allocHandle ih m = do 42allocHandle ih m = do
42 Client {..} <- getClient 43 Client {..} <- getClient
43 modifyMVar clientTorrents $ \ handles -> do 44
45 (h, added) <- modifyMVar clientTorrents $ \ handles -> do
44 case HM.lookup ih handles of 46 case HM.lookup ih handles of
45 Just h -> return (handles, h) 47 Just h -> return (handles, (h, False))
46 Nothing -> do 48 Nothing -> do
47 h <- m 49 h <- m
48 return (HM.insert ih h handles, h) 50 return (HM.insert ih h handles, (h, True))
51
52 when added $ do
53 liftIO $ send clientEvents (TorrentAdded ih)
54
55 return h
49 56
50freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () 57freeHandle :: InfoHash -> BitTorrent () -> BitTorrent ()
51freeHandle ih finalizer = do 58freeHandle ih finalizer = do
52 Client {..} <- getClient 59 Client {..} <- getClient
60
53 modifyMVar_ clientTorrents $ \ handles -> do 61 modifyMVar_ clientTorrents $ \ handles -> do
54 case HM.lookup ih handles of 62 case HM.lookup ih handles of
55 Nothing -> return handles 63 Nothing -> return handles