diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-17 21:23:52 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-17 21:23:52 +0400 |
commit | 5bfdba75d3f59e8193c3f913527e16318986f598 (patch) | |
tree | b3145815372e77c60a6481a3f5b499fa67899d68 /src | |
parent | e2fa5180aab8c8c30e5170e9de66330b923347aa (diff) |
Add withSession and getStatus functions
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Session.hs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs index 9b7654dd..b5c05116 100644 --- a/src/Network/BitTorrent/Tracker/Session.hs +++ b/src/Network/BitTorrent/Tracker/Session.hs | |||
@@ -12,21 +12,28 @@ module Network.BitTorrent.Tracker.Session | |||
12 | Session | 12 | Session |
13 | , newSession | 13 | , newSession |
14 | , closeSession | 14 | , closeSession |
15 | , withSession | ||
15 | 16 | ||
16 | -- * Trackers | 17 | -- * Query |
17 | , notify | 18 | , Status (..) |
19 | , getStatus | ||
18 | , askPeers | 20 | , askPeers |
19 | 21 | ||
22 | -- * Events | ||
23 | , Event (..) | ||
24 | , notify | ||
25 | |||
20 | -- * Tracker Exchange | 26 | -- * Tracker Exchange |
21 | -- | BEP28: <http://www.bittorrent.org/beps/bep_0028.html> | 27 | -- | BEP28: <http://www.bittorrent.org/beps/bep_0028.html> |
22 | , addTracker | 28 | , addTracker |
23 | , removeTracker | 29 | , removeTracker |
24 | , getTrackers | ||
25 | , getTrustedTrackers | 30 | , getTrustedTrackers |
26 | ) where | 31 | ) where |
27 | 32 | ||
28 | import Control.Applicative | 33 | import Control.Applicative |
34 | import Control.Exception | ||
29 | import Control.Concurrent | 35 | import Control.Concurrent |
36 | |||
30 | import Data.Default | 37 | import Data.Default |
31 | import Data.Fixed | 38 | import Data.Fixed |
32 | import Data.Foldable | 39 | import Data.Foldable |
@@ -128,6 +135,15 @@ newSession ih origUris = do | |||
128 | closeSession :: Session -> IO () | 135 | closeSession :: Session -> IO () |
129 | closeSession _ = return () | 136 | closeSession _ = return () |
130 | 137 | ||
138 | -- | Normally you need to use 'Control.Monad.Trans.Resource.alloc'. | ||
139 | withSession :: InfoHash -> TrackerList URI -> (Session -> IO ()) -> IO () | ||
140 | withSession ih uris = bracket (newSession ih uris) closeSession | ||
141 | |||
142 | -- | Get last announced status. The only action can alter this status | ||
143 | -- is 'notify'. | ||
144 | getStatus :: Session -> IO Status | ||
145 | getStatus Session {..} = takeMVar currentStatus | ||
146 | |||
131 | seconds :: Int -> NominalDiffTime | 147 | seconds :: Int -> NominalDiffTime |
132 | seconds n = realToFrac (toEnum n :: Uni) | 148 | seconds n = realToFrac (toEnum n :: Uni) |
133 | 149 | ||