From d0038e9bde22751c9c926796a6c46be62a3cb81b Mon Sep 17 00:00:00 2001 From: Sam T Date: Tue, 14 May 2013 10:27:36 +0400 Subject: ~ Minor changes. --- bench/Main.hs | 11 ++++++++--- bench/Server.hs | 3 ++- examples/Client.hs | 4 ++++ examples/Server.hs | 1 + examples/Shared.hs | 6 +++++- krpc.cabal | 12 ++++++------ src/Remote/KRPC/Protocol.hs | 4 ++-- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index 411282a0..87d39f14 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -1,6 +1,9 @@ {-# LANGUAGE OverloadedStrings #-} module Main (main) where +import Control.Monad +import Data.ByteString (ByteString) +import qualified Data.ByteString as B import Criterion.Main import Remote.KRPC @@ -8,10 +11,12 @@ import Remote.KRPC addr :: RemoteAddr addr = (0, 6000) -echo :: Method [Int] [Int] +echo :: Method ByteString ByteString echo = method "echo" ["x"] ["x"] main :: IO () -main = defaultMain $ map mkbench [1, 10, 100, 1000] +main = defaultMain $ map (mkbench 1) [1, 10, 100, 1000, 32 * 1024] + ++ map (mkbench 10) [1, 10, 100, 1000] where - mkbench n = bench (show n) $ nfIO $ call addr echo [1..n] \ No newline at end of file + mkbench r n = bench (show r ++ "/" ++ show n) $ nfIO $ + replicateM r $ call addr echo (B.replicate n 0) \ No newline at end of file diff --git a/bench/Server.hs b/bench/Server.hs index cb5ed316..ece5a7a9 100644 --- a/bench/Server.hs +++ b/bench/Server.hs @@ -1,10 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} module Main (main) where +import Data.ByteString (ByteString) import Remote.KRPC -echo :: Method [Int] [Int] +echo :: Method ByteString ByteString echo = method "echo" ["x"] ["x"] main :: IO () diff --git a/examples/Client.hs b/examples/Client.hs index cd340a03..ec86639e 100644 --- a/examples/Client.hs +++ b/examples/Client.hs @@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Main (main) where +import qualified Data.ByteString as B import System.Environment import Remote.KRPC import Shared @@ -16,6 +17,9 @@ main = do call addr reverseM [1..1000] print =<< call addr swapM (0, 1) print =<< call addr shiftR ((), 1, [2..10]) + let bs = B.replicate (32 * 1024) 0 + bs' <- call addr echoBytes bs + print (bs == bs') {- forM_ [1..] $ const $ do diff --git a/examples/Server.hs b/examples/Server.hs index 0407c304..f636b0be 100644 --- a/examples/Server.hs +++ b/examples/Server.hs @@ -9,6 +9,7 @@ main :: IO () main = server 6000 [ unitM ==> return , echoM ==> return + , echoBytes ==> return , swapM ==> \(a, b) -> return (b, a) , reverseM ==> return . reverse , shiftR ==> \(a, b, c) -> return (c, a, b) diff --git a/examples/Shared.hs b/examples/Shared.hs index 2d5b9cbb..e0e5268c 100644 --- a/examples/Shared.hs +++ b/examples/Shared.hs @@ -1,8 +1,9 @@ {-# LANGUAGE OverloadedStrings #-} module Shared - (echoM, unitM, swapM, reverseM, shiftR + (echoM, echoBytes, unitM, swapM, reverseM, shiftR ) where +import Data.ByteString (ByteString) import Remote.KRPC unitM :: Method () () @@ -11,6 +12,9 @@ unitM = method "unit" [] [] echoM :: Method Int Int echoM = method "echo" ["x"] ["x"] +echoBytes :: Method ByteString ByteString +echoBytes = method "echoBytes" ["x"] ["x"] + reverseM :: Method [Int] [Int] reverseM = method "reverse" ["xs"] ["ys"] diff --git a/krpc.cabal b/krpc.cabal index e0fdb718..b9bd0f1a 100644 --- a/krpc.cabal +++ b/krpc.cabal @@ -46,13 +46,13 @@ library executable exsample-client main-is: Client.hs other-modules: Shared - build-depends: base == 4.*, krpc + build-depends: base == 4.*, krpc, bytestring hs-source-dirs: examples executable exsample-server main-is: Server.hs other-modules: Shared - build-depends: base == 4.*, krpc + build-depends: base == 4.*, krpc, bytestring hs-source-dirs: examples @@ -60,13 +60,13 @@ executable exsample-server executable bench-server main-is: Server.hs - build-depends: base == 4.*, krpc + build-depends: base == 4.*, krpc, bytestring hs-source-dirs: bench - ghc-options: -O2 + ghc-options: -O2 -fforce-recomp benchmark bench-client type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: bench - build-depends: base == 4.5.*, krpc, criterion - ghc-options: -O2 \ No newline at end of file + build-depends: base == 4.5.*, krpc, criterion, bytestring + ghc-options: -O2 -fforce-recomp \ No newline at end of file diff --git a/src/Remote/KRPC/Protocol.hs b/src/Remote/KRPC/Protocol.hs index 133c899a..29aaefed 100644 --- a/src/Remote/KRPC/Protocol.hs +++ b/src/Remote/KRPC/Protocol.hs @@ -6,7 +6,7 @@ -- Portability : portable -- -- This module provides straightforward implementation of KRPC --- protocol. In many situations Network.KRPC should be prefered +-- protocol. In many situations 'Network.KRPC' should be prefered -- since it gives more safe, convenient and high level api. -- -- > See http://www.bittorrent.org/beps/bep_0005.html#krpc-protocol @@ -176,7 +176,7 @@ withRemote = bracket (liftIO (socket AF_INET Datagram defaultProtocol)) maxMsgSize :: Int -maxMsgSize = 16 * 1024 +maxMsgSize = 512 {-# INLINE maxMsgSize #-} -- cgit v1.2.3