diff options
Diffstat (limited to 'src/Network/BitTorrent/Tracker/RPC.hs')
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC.hs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC.hs b/src/Network/BitTorrent/Tracker/RPC.hs index 3acffce9..b3e962fa 100644 --- a/src/Network/BitTorrent/Tracker/RPC.hs +++ b/src/Network/BitTorrent/Tracker/RPC.hs | |||
@@ -5,7 +5,11 @@ | |||
5 | -- Stability : experimental | 5 | -- Stability : experimental |
6 | -- Portability : portable | 6 | -- Portability : portable |
7 | -- | 7 | -- |
8 | -- Protocol independent bittorrent tracker API. | 8 | -- This module provides unified RPC interface to BitTorrent |
9 | -- trackers. The tracker is an UDP/HTTP/HTTPS service used to discovery | ||
10 | -- peers for a particular existing torrent and keep statistics about | ||
11 | -- the swarm. This module also provides a way to easily request | ||
12 | -- scrape info for a particular torrent list. | ||
9 | -- | 13 | -- |
10 | {-# LANGUAGE DeriveDataTypeable #-} | 14 | {-# LANGUAGE DeriveDataTypeable #-} |
11 | module Network.BitTorrent.Tracker.RPC | 15 | module Network.BitTorrent.Tracker.RPC |
@@ -104,18 +108,26 @@ data Manager = Manager | |||
104 | , udpMgr :: !UDP.Manager | 108 | , udpMgr :: !UDP.Manager |
105 | } | 109 | } |
106 | 110 | ||
107 | -- | Normally a bittorrent client session need a single RPC manager | 111 | -- | Create a new 'Manager'. You /must/ manually 'closeManager' |
108 | -- only. | 112 | -- otherwise resource leakage is possible. Normally, a bittorrent |
113 | -- client need a single RPC manager only. | ||
114 | -- | ||
115 | -- This function can throw 'IOException' on invalid 'Options'. | ||
116 | -- | ||
109 | newManager :: Options -> PeerInfo -> IO Manager | 117 | newManager :: Options -> PeerInfo -> IO Manager |
110 | newManager opts info = do | 118 | newManager opts info = do |
111 | h <- HTTP.newManager (optHttpRPC opts) | 119 | h <- HTTP.newManager (optHttpRPC opts) |
112 | u <- UDP.newManager (optUdpRPC opts) `onException` HTTP.closeManager h | 120 | u <- UDP.newManager (optUdpRPC opts) `onException` HTTP.closeManager h |
113 | return $ Manager opts info h u | 121 | return $ Manager opts info h u |
114 | 122 | ||
123 | -- | Close all pending RPCs. Behaviour of currently in-flight RPCs can | ||
124 | -- differ depending on underlying protocol used. No rpc calls should | ||
125 | -- be performed after manager becomes closed. | ||
115 | closeManager :: Manager -> IO () | 126 | closeManager :: Manager -> IO () |
116 | closeManager Manager {..} = do | 127 | closeManager Manager {..} = do |
117 | UDP.closeManager udpMgr `finally` HTTP.closeManager httpMgr | 128 | UDP.closeManager udpMgr `finally` HTTP.closeManager httpMgr |
118 | 129 | ||
130 | -- | Normally you need to use 'Control.Monad.Trans.Resource.allocate'. | ||
119 | withManager :: Options -> PeerInfo -> (Manager -> IO a) -> IO a | 131 | withManager :: Options -> PeerInfo -> (Manager -> IO a) -> IO a |
120 | withManager opts info = bracket (newManager opts info) closeManager | 132 | withManager opts info = bracket (newManager opts info) closeManager |
121 | 133 | ||