diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-04 01:43:15 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-04 01:43:15 +0400 |
commit | 67c47caaccf28d012e7bb34def41f83500d3c72a (patch) | |
tree | bdf953897e8dac0b02b80172b4faac10c5ade8f2 /src/Network/BitTorrent | |
parent | 91621c7fb503cb8919053730a2b4b91075a4cf58 (diff) |
[Client] Emit TorrentAdded event
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Client/Handle.hs | 14 |
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 | ||
21 | import Control.Concurrent.Chan.Split | ||
21 | import Control.Concurrent.Lifted as L | 22 | import Control.Concurrent.Lifted as L |
22 | import Control.Monad | 23 | import Control.Monad |
23 | import Control.Monad.Trans | 24 | import Control.Monad.Trans |
@@ -40,16 +41,23 @@ import Network.BitTorrent.Tracker as Tracker | |||
40 | allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle | 41 | allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle |
41 | allocHandle ih m = do | 42 | allocHandle 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 | ||
50 | freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () | 57 | freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () |
51 | freeHandle ih finalizer = do | 58 | freeHandle 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 |