summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-04-04 01:43:15 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-04-04 01:43:15 +0400
commit67c47caaccf28d012e7bb34def41f83500d3c72a (patch)
treebdf953897e8dac0b02b80172b4faac10c5ade8f2 /src/Network/BitTorrent/Client
parent91621c7fb503cb8919053730a2b4b91075a4cf58 (diff)
[Client] Emit TorrentAdded event
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