summaryrefslogtreecommitdiff
path: root/src/Network/KRPC/Manager.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-18 20:11:36 -0500
committerjoe <joe@jerkface.net>2017-01-18 20:11:36 -0500
commita8498921ddf37e864968a3865e3e254352b5d285 (patch)
tree41b709b7ec71efd4e918f0800125599bd86da677 /src/Network/KRPC/Manager.hs
parent5d0791e6ed2e500c08e7dadda39a254c8340cef5 (diff)
Aeson-based pretty-printing of server requests.
Diffstat (limited to 'src/Network/KRPC/Manager.hs')
-rw-r--r--src/Network/KRPC/Manager.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs
index 9477d23c..c90c92f9 100644
--- a/src/Network/KRPC/Manager.hs
+++ b/src/Network/KRPC/Manager.hs
@@ -52,6 +52,7 @@ import Control.Monad.Reader
52import Control.Monad.Trans.Control 52import Control.Monad.Trans.Control
53import Data.BEncode as BE 53import Data.BEncode as BE
54import Data.BEncode.Internal as BE 54import Data.BEncode.Internal as BE
55import Data.BEncode.Pretty (showBEncode)
55import Data.ByteString as BS 56import Data.ByteString as BS
56import Data.ByteString.Char8 as BC 57import Data.ByteString.Char8 as BC
57import Data.ByteString.Lazy as BL 58import Data.ByteString.Lazy as BL
@@ -428,11 +429,17 @@ dispatchHandler q @ KQuery {..} addr = do
428-- peer B fork too many threads 429-- peer B fork too many threads
429-- ... space leak 430-- ... space leak
430-- 431--
431handleQuery :: MonadKRPC h m => KQuery -> SockAddr -> m () 432handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m ()
432handleQuery q addr = void $ fork $ do 433handleQuery raw q addr = void $ fork $ do
433 Manager {..} <- getManager 434 Manager {..} <- getManager
434 res <- dispatchHandler q addr 435 res <- dispatchHandler q addr
435 sendMessage sock addr $ either toBEncode toBEncode res 436 let resbe = either toBEncode toBEncode res
437 $(logOther "q") $ T.unlines
438 [ either (const "<unicode-fail>") id $ T.decodeUtf8' (BL.toStrict $ showBEncode raw)
439 , "==>"
440 , either (const "<unicode-fail>") id $ T.decodeUtf8' (BL.toStrict $ showBEncode resbe)
441 ]
442 sendMessage sock addr resbe
436 443
437handleResponse :: MonadKRPC h m => BValue -> KResult -> SockAddr -> m () 444handleResponse :: MonadKRPC h m => BValue -> KResult -> SockAddr -> m ()
438handleResponse raw result addr = do 445handleResponse raw result addr = do
@@ -445,7 +452,7 @@ handleResponse raw result addr = do
445 Just ares -> putMVar ares (raw,result) 452 Just ares -> putMVar ares (raw,result)
446 453
447handleMessage :: MonadKRPC h m => BValue -> KMessage -> SockAddr -> m () 454handleMessage :: MonadKRPC h m => BValue -> KMessage -> SockAddr -> m ()
448handleMessage _ (Q q) = handleQuery q 455handleMessage raw (Q q) = handleQuery raw q
449handleMessage raw (R r) = handleResponse raw (Right r) 456handleMessage raw (R r) = handleResponse raw (Right r)
450handleMessage raw (E e) = handleResponse raw (Left e) 457handleMessage raw (E e) = handleResponse raw (Left e)
451 458