summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Client/Types.hs16
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs11
2 files changed, 26 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Client/Types.hs b/src/Network/BitTorrent/Client/Types.hs
index 9bae7dc3..7f228276 100644
--- a/src/Network/BitTorrent/Client/Types.hs
+++ b/src/Network/BitTorrent/Client/Types.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE FlexibleInstances #-} 2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE TypeFamilies #-} 3{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE MultiParamTypeClasses #-} 4{-# LANGUAGE MultiParamTypeClasses #-}
@@ -106,6 +107,18 @@ newtype BitTorrent a = BitTorrent
106class MonadBitTorrent m where 107class MonadBitTorrent m where
107 liftBT :: BitTorrent a -> m a 108 liftBT :: BitTorrent a -> m a
108 109
110#if MIN_VERSION_monad_control(1,0,0)
111newtype BTStM a = BTStM { unBTSt :: StM (ReaderT Client IO) a }
112
113instance MonadBaseControl IO BitTorrent where
114 type StM BitTorrent a = BTStM a
115 liftBaseWith cc = BitTorrent $ liftBaseWith $ \ cc' ->
116 cc $ \ (BitTorrent m) -> BTStM <$> cc' m
117 {-# INLINE liftBaseWith #-}
118
119 restoreM = BitTorrent . restoreM . unBTSt
120 {-# INLINE restoreM #-}
121#else
109instance MonadBaseControl IO BitTorrent where 122instance MonadBaseControl IO BitTorrent where
110 newtype StM BitTorrent a = StM { unSt :: StM (ReaderT Client IO) a } 123 newtype StM BitTorrent a = StM { unSt :: StM (ReaderT Client IO) a }
111 liftBaseWith cc = BitTorrent $ liftBaseWith $ \ cc' -> 124 liftBaseWith cc = BitTorrent $ liftBaseWith $ \ cc' ->
@@ -114,6 +127,7 @@ instance MonadBaseControl IO BitTorrent where
114 127
115 restoreM = BitTorrent . restoreM . unSt 128 restoreM = BitTorrent . restoreM . unSt
116 {-# INLINE restoreM #-} 129 {-# INLINE restoreM #-}
130#endif
117 131
118-- | NOP. 132-- | NOP.
119instance MonadBitTorrent BitTorrent where 133instance MonadBitTorrent BitTorrent where
@@ -146,4 +160,4 @@ runBitTorrent client action = runReaderT (unBitTorrent action) client
146 160
147getClient :: BitTorrent Client 161getClient :: BitTorrent Client
148getClient = BitTorrent ask 162getClient = BitTorrent ask
149{-# INLINE getClient #-} \ No newline at end of file 163{-# INLINE getClient #-}
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 38b3ed11..bc5c6201 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -10,6 +10,7 @@
10-- to. Normally, you don't need to import this module, use 10-- to. Normally, you don't need to import this module, use
11-- "Network.BitTorrent.DHT" instead. 11-- "Network.BitTorrent.DHT" instead.
12-- 12--
13{-# LANGUAGE CPP #-}
13{-# LANGUAGE RecordWildCards #-} 14{-# LANGUAGE RecordWildCards #-}
14{-# LANGUAGE FlexibleContexts #-} 15{-# LANGUAGE FlexibleContexts #-}
15{-# LANGUAGE FlexibleInstances #-} 16{-# LANGUAGE FlexibleInstances #-}
@@ -258,10 +259,20 @@ newtype DHT ip a = DHT { unDHT :: ReaderT (Node ip) IO a }
258 , MonadBase IO, MonadReader (Node ip), MonadThrow 259 , MonadBase IO, MonadReader (Node ip), MonadThrow
259 ) 260 )
260 261
262#if MIN_VERSION_monad_control(1,0,0)
263newtype DHTStM ip a = StM {
264 unSt :: StM (ReaderT (Node ip) IO) a
265 }
266#endif
267
261instance MonadBaseControl IO (DHT ip) where 268instance MonadBaseControl IO (DHT ip) where
269#if MIN_VERSION_monad_control(1,0,0)
270 type StM (DHT ip) a = DHTStM ip a
271#else
262 newtype StM (DHT ip) a = StM { 272 newtype StM (DHT ip) a = StM {
263 unSt :: StM (ReaderT (Node ip) IO) a 273 unSt :: StM (ReaderT (Node ip) IO) a
264 } 274 }
275#endif
265 liftBaseWith cc = DHT $ liftBaseWith $ \ cc' -> 276 liftBaseWith cc = DHT $ liftBaseWith $ \ cc' ->
266 cc $ \ (DHT m) -> StM <$> cc' m 277 cc $ \ (DHT m) -> StM <$> cc' m
267 {-# INLINE liftBaseWith #-} 278 {-# INLINE liftBaseWith #-}