diff options
author | joe <joe@jerkface.net> | 2017-01-18 20:11:36 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-18 20:11:36 -0500 |
commit | a8498921ddf37e864968a3865e3e254352b5d285 (patch) | |
tree | 41b709b7ec71efd4e918f0800125599bd86da677 /src/Network/KRPC/Manager.hs | |
parent | 5d0791e6ed2e500c08e7dadda39a254c8340cef5 (diff) |
Aeson-based pretty-printing of server requests.
Diffstat (limited to 'src/Network/KRPC/Manager.hs')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 15 |
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 | |||
52 | import Control.Monad.Trans.Control | 52 | import Control.Monad.Trans.Control |
53 | import Data.BEncode as BE | 53 | import Data.BEncode as BE |
54 | import Data.BEncode.Internal as BE | 54 | import Data.BEncode.Internal as BE |
55 | import Data.BEncode.Pretty (showBEncode) | ||
55 | import Data.ByteString as BS | 56 | import Data.ByteString as BS |
56 | import Data.ByteString.Char8 as BC | 57 | import Data.ByteString.Char8 as BC |
57 | import Data.ByteString.Lazy as BL | 58 | import 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 | -- |
431 | handleQuery :: MonadKRPC h m => KQuery -> SockAddr -> m () | 432 | handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m () |
432 | handleQuery q addr = void $ fork $ do | 433 | handleQuery 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 | ||
437 | handleResponse :: MonadKRPC h m => BValue -> KResult -> SockAddr -> m () | 444 | handleResponse :: MonadKRPC h m => BValue -> KResult -> SockAddr -> m () |
438 | handleResponse raw result addr = do | 445 | handleResponse 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 | ||
447 | handleMessage :: MonadKRPC h m => BValue -> KMessage -> SockAddr -> m () | 454 | handleMessage :: MonadKRPC h m => BValue -> KMessage -> SockAddr -> m () |
448 | handleMessage _ (Q q) = handleQuery q | 455 | handleMessage raw (Q q) = handleQuery raw q |
449 | handleMessage raw (R r) = handleResponse raw (Right r) | 456 | handleMessage raw (R r) = handleResponse raw (Right r) |
450 | handleMessage raw (E e) = handleResponse raw (Left e) | 457 | handleMessage raw (E e) = handleResponse raw (Left e) |
451 | 458 | ||