diff options
Diffstat (limited to 'src/Network/KRPC/Manager.hs')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs index b1e93101..58ac7674 100644 --- a/src/Network/KRPC/Manager.hs +++ b/src/Network/KRPC/Manager.hs | |||
@@ -151,7 +151,11 @@ data Manager h = Manager | |||
151 | , listenerThread :: !(MVar ThreadId) | 151 | , listenerThread :: !(MVar ThreadId) |
152 | , transactionCounter :: {-# UNPACK #-} !TransactionCounter | 152 | , transactionCounter :: {-# UNPACK #-} !TransactionCounter |
153 | , pendingCalls :: {-# UNPACK #-} !PendingCalls | 153 | , pendingCalls :: {-# UNPACK #-} !PendingCalls |
154 | #ifdef VERSION_bencoding | ||
154 | , handlers :: [Handler h KMessageOf BValue] | 155 | , handlers :: [Handler h KMessageOf BValue] |
156 | #else | ||
157 | , handlers :: [Handler h KMessageOf BC.ByteString] | ||
158 | #endif | ||
155 | } | 159 | } |
156 | 160 | ||
157 | -- | A monad which can perform or handle queries. | 161 | -- | A monad which can perform or handle queries. |
@@ -185,7 +189,11 @@ sockAddrFamily (SockAddrCan _ ) = AF_CAN | |||
185 | -- run 'listen'. | 189 | -- run 'listen'. |
186 | newManager :: Options -- ^ various protocol options; | 190 | newManager :: Options -- ^ various protocol options; |
187 | -> SockAddr -- ^ address to listen on; | 191 | -> SockAddr -- ^ address to listen on; |
192 | #ifdef VERSION_bencoding | ||
188 | -> [Handler h KMessageOf BValue] -- ^ handlers to run on incoming queries. | 193 | -> [Handler h KMessageOf BValue] -- ^ handlers to run on incoming queries. |
194 | #else | ||
195 | -> [Handler h KMessageOf BC.ByteString] -- ^ handlers to run on incoming queries. | ||
196 | #endif | ||
189 | -> IO (Manager h) -- ^ new rpc manager. | 197 | -> IO (Manager h) -- ^ new rpc manager. |
190 | newManager opts @ Options {..} servAddr handlers = do | 198 | newManager opts @ Options {..} servAddr handlers = do |
191 | validateOptions opts | 199 | validateOptions opts |
@@ -218,7 +226,11 @@ isActive Manager {..} = liftIO $ isBound sock | |||
218 | 226 | ||
219 | -- | Normally you should use Control.Monad.Trans.Resource.allocate | 227 | -- | Normally you should use Control.Monad.Trans.Resource.allocate |
220 | -- function. | 228 | -- function. |
229 | #ifdef VERSION_bencoding | ||
221 | withManager :: Options -> SockAddr -> [Handler h KMessageOf BValue] | 230 | withManager :: Options -> SockAddr -> [Handler h KMessageOf BValue] |
231 | #else | ||
232 | withManager :: Options -> SockAddr -> [Handler h KMessageOf BC.ByteString] | ||
233 | #endif | ||
222 | -> (Manager h -> IO a) -> IO a | 234 | -> (Manager h -> IO a) -> IO a |
223 | withManager opts addr hs = bracket (newManager opts addr hs) closeManager | 235 | withManager opts addr hs = bracket (newManager opts addr hs) closeManager |
224 | 236 | ||
@@ -420,14 +432,22 @@ handler msging body = (name, wrapper) | |||
420 | Right a -> Right . seal <$> body addr a | 432 | Right a -> Right . seal <$> body addr a |
421 | 433 | ||
422 | runHandler :: MonadKRPC h m | 434 | runHandler :: MonadKRPC h m |
435 | #ifdef VERSION_bencoding | ||
423 | => HandlerBody h KMessageOf BValue -> SockAddr -> KQuery -> m KResult | 436 | => HandlerBody h KMessageOf BValue -> SockAddr -> KQuery -> m KResult |
437 | #else | ||
438 | => HandlerBody h KMessageOf BC.ByteString -> SockAddr -> KQuery -> m KResult | ||
439 | #endif | ||
424 | runHandler h addr m = Lifted.catches wrapper failbacks | 440 | runHandler h addr m = Lifted.catches wrapper failbacks |
425 | where | 441 | where |
426 | signature = querySignature (queryMethod m) (queryId m) addr | 442 | signature = querySignature (queryMethod m) (queryId m) addr |
427 | 443 | ||
428 | wrapper = do | 444 | wrapper = do |
429 | $(logDebugS) "handler.quered" signature | 445 | $(logDebugS) "handler.quered" signature |
446 | #ifdef VERSION_bencoding | ||
430 | result <- liftHandler (h addr (Q m)) | 447 | result <- liftHandler (h addr (Q m)) |
448 | #else | ||
449 | result <- liftHandler (h addr m) | ||
450 | #endif | ||
431 | 451 | ||
432 | case result of | 452 | case result of |
433 | Left msg -> do | 453 | Left msg -> do |