summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Tracker/RPC/UDP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Tracker/RPC/UDP.hs')
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/UDP.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs
index 632e3d86..160397dd 100644
--- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs
+++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs
@@ -5,7 +5,8 @@
5-- Stability : provisional 5-- Stability : provisional
6-- Portability : portable 6-- Portability : portable
7-- 7--
8-- This module implement low-level UDP tracker protocol. 8-- This module implement UDP tracker protocol.
9--
9-- For more info see: 10-- For more info see:
10-- <http://www.bittorrent.org/beps/bep_0015.html> 11-- <http://www.bittorrent.org/beps/bep_0015.html>
11-- 12--
@@ -142,6 +143,7 @@ type PendingResponse = MVar (Either RpcException Response)
142type PendingTransactions = Map TransactionId PendingResponse 143type PendingTransactions = Map TransactionId PendingResponse
143type PendingQueries = Map SockAddr PendingTransactions 144type PendingQueries = Map SockAddr PendingTransactions
144 145
146-- | UDP tracker manager.
145data Manager = Manager 147data Manager = Manager
146 { options :: !Options 148 { options :: !Options
147 , sock :: !Socket 149 , sock :: !Socket
@@ -176,7 +178,7 @@ resetState Manager {..} = do
176 where 178 where
177 err = error "UDP tracker manager closed" 179 err = error "UDP tracker manager closed"
178 180
179-- | This function will throw 'IOException' if or 181-- | This function will throw 'IOException' on invalid 'Options'.
180newManager :: Options -> IO Manager 182newManager :: Options -> IO Manager
181newManager opts = do 183newManager opts = do
182 checkOptions opts 184 checkOptions opts
@@ -185,6 +187,8 @@ newManager opts = do
185 putMVar (listenerThread mgr) tid 187 putMVar (listenerThread mgr) tid
186 return mgr 188 return mgr
187 189
190-- | Unblock all RPCs by throwing 'ManagerClosed' exception. No rpc
191-- calls should be performed after manager becomes closed.
188closeManager :: Manager -> IO () 192closeManager :: Manager -> IO ()
189closeManager Manager {..} = do 193closeManager Manager {..} = do
190 close sock 194 close sock
@@ -193,6 +197,7 @@ closeManager Manager {..} = do
193 Nothing -> return () 197 Nothing -> return ()
194 Just tid -> killThread tid 198 Just tid -> killThread tid
195 199
200-- | Normally you need to use 'Control.Monad.Trans.Resource.allocate'.
196withManager :: Options -> (Manager -> IO a) -> IO a 201withManager :: Options -> (Manager -> IO a) -> IO a
197withManager opts = bracket (newManager opts) closeManager 202withManager opts = bracket (newManager opts) closeManager
198 203