summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-13 21:40:09 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-13 21:40:09 +0400
commitad4d96b1850fea7d6f40a48a085ed8d18ba4fd8a (patch)
tree919a2054404e2abf253b819c62d70ca37a00066f /src/Network/BitTorrent/Exchange.hs
parent6fc2cec0666b4cadf72f89f4027ffb6cffadae12 (diff)
~ Remove throttling from Exchange.
Diffstat (limited to 'src/Network/BitTorrent/Exchange.hs')
-rw-r--r--src/Network/BitTorrent/Exchange.hs28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/Network/BitTorrent/Exchange.hs b/src/Network/BitTorrent/Exchange.hs
index a0e7df8c..6ba56a22 100644
--- a/src/Network/BitTorrent/Exchange.hs
+++ b/src/Network/BitTorrent/Exchange.hs
@@ -47,7 +47,6 @@
47module Network.BitTorrent.Exchange 47module Network.BitTorrent.Exchange
48 ( P2P 48 ( P2P
49 , runP2P 49 , runP2P
50 , spawnP2P
51 50
52 -- * Query 51 -- * Query
53 , getHaveCount 52 , getHaveCount
@@ -153,33 +152,14 @@ instance MonadState SessionState P2P where
153 put !s = asks sessionState >>= \ref -> liftIO $ writeIORef ref s 152 put !s = asks sessionState >>= \ref -> liftIO $ writeIORef ref s
154 {-# INLINE put #-} 153 {-# INLINE put #-}
155 154
156runSession :: SwarmSession -> PeerAddr -> P2P () -> IO () 155runP2P :: (Socket, PeerSession) -> P2P () -> IO ()
157runSession se addr p2p = 156runP2P (sock, ses) p2p =
158 handle isIOException $ 157 handle isIOException $
159 initiatePeerSession se addr $ \(sock, pses) -> do 158 runPeerWire sock (runReaderT (unP2P p2p) ses)
160 runPeerWire sock (runReaderT (unP2P p2p) pses)
161 where 159 where
162 isIOException :: IOException -> IO () 160 isIOException :: IOException -> IO ()
163 isIOException _ = return () 161 isIOException _ = return ()
164 162
165-- | Run P2P session in the current thread. Normally you don't need this
166-- function in client application, except for debugging.
167runP2P :: SwarmSession -> PeerAddr -> P2P () -> IO ()
168runP2P se addr p2p = waitVacancy se $ runSession se addr p2p
169
170-- | Run P2P session in forked thread. Might be used in listener or
171-- some other loop. Note that this function may block while waiting
172-- for a vacant place: use forkIO and runP2P instead.
173spawnP2P :: SwarmSession -> PeerAddr -> P2P () -> IO ThreadId
174spawnP2P se addr p2p = forkThrottle se $ runSession se addr p2p
175
176-- TODO unify this all using PeerConnection
177{-
178listenP2P :: SwarmSession -> P2P () -> IO PortNumber
179listenP2P _ _ = undefined
180
181chainP2P :: SwarmSession -> PeerConnection -> P2P () -> IO ()
182-}
183{----------------------------------------------------------------------- 163{-----------------------------------------------------------------------
184 Exceptions 164 Exceptions
185-----------------------------------------------------------------------} 165-----------------------------------------------------------------------}