diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-13 21:40:09 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-13 21:40:09 +0400 |
commit | ad4d96b1850fea7d6f40a48a085ed8d18ba4fd8a (patch) | |
tree | 919a2054404e2abf253b819c62d70ca37a00066f /src/Network/BitTorrent/Exchange.hs | |
parent | 6fc2cec0666b4cadf72f89f4027ffb6cffadae12 (diff) |
~ Remove throttling from Exchange.
Diffstat (limited to 'src/Network/BitTorrent/Exchange.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange.hs | 28 |
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 @@ | |||
47 | module Network.BitTorrent.Exchange | 47 | module 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 | ||
156 | runSession :: SwarmSession -> PeerAddr -> P2P () -> IO () | 155 | runP2P :: (Socket, PeerSession) -> P2P () -> IO () |
157 | runSession se addr p2p = | 156 | runP2P (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. | ||
167 | runP2P :: SwarmSession -> PeerAddr -> P2P () -> IO () | ||
168 | runP2P 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. | ||
173 | spawnP2P :: SwarmSession -> PeerAddr -> P2P () -> IO ThreadId | ||
174 | spawnP2P se addr p2p = forkThrottle se $ runSession se addr p2p | ||
175 | |||
176 | -- TODO unify this all using PeerConnection | ||
177 | {- | ||
178 | listenP2P :: SwarmSession -> P2P () -> IO PortNumber | ||
179 | listenP2P _ _ = undefined | ||
180 | |||
181 | chainP2P :: SwarmSession -> PeerConnection -> P2P () -> IO () | ||
182 | -} | ||
183 | {----------------------------------------------------------------------- | 163 | {----------------------------------------------------------------------- |
184 | Exceptions | 164 | Exceptions |
185 | -----------------------------------------------------------------------} | 165 | -----------------------------------------------------------------------} |