diff options
-rw-r--r-- | bench/Main.hs | 11 | ||||
-rw-r--r-- | bench/Server.hs | 3 | ||||
-rw-r--r-- | examples/Client.hs | 4 | ||||
-rw-r--r-- | examples/Server.hs | 1 | ||||
-rw-r--r-- | examples/Shared.hs | 6 | ||||
-rw-r--r-- | krpc.cabal | 12 | ||||
-rw-r--r-- | 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 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import Control.Monad | ||
5 | import Data.ByteString (ByteString) | ||
6 | import qualified Data.ByteString as B | ||
4 | import Criterion.Main | 7 | import Criterion.Main |
5 | import Remote.KRPC | 8 | import Remote.KRPC |
6 | 9 | ||
@@ -8,10 +11,12 @@ import Remote.KRPC | |||
8 | addr :: RemoteAddr | 11 | addr :: RemoteAddr |
9 | addr = (0, 6000) | 12 | addr = (0, 6000) |
10 | 13 | ||
11 | echo :: Method [Int] [Int] | 14 | echo :: Method ByteString ByteString |
12 | echo = method "echo" ["x"] ["x"] | 15 | echo = method "echo" ["x"] ["x"] |
13 | 16 | ||
14 | main :: IO () | 17 | main :: IO () |
15 | main = defaultMain $ map mkbench [1, 10, 100, 1000] | 18 | main = defaultMain $ map (mkbench 1) [1, 10, 100, 1000, 32 * 1024] |
19 | ++ map (mkbench 10) [1, 10, 100, 1000] | ||
16 | where | 20 | where |
17 | mkbench n = bench (show n) $ nfIO $ call addr echo [1..n] \ No newline at end of file | 21 | mkbench r n = bench (show r ++ "/" ++ show n) $ nfIO $ |
22 | 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 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import Data.ByteString (ByteString) | ||
4 | import Remote.KRPC | 5 | import Remote.KRPC |
5 | 6 | ||
6 | 7 | ||
7 | echo :: Method [Int] [Int] | 8 | echo :: Method ByteString ByteString |
8 | echo = method "echo" ["x"] ["x"] | 9 | echo = method "echo" ["x"] ["x"] |
9 | 10 | ||
10 | main :: IO () | 11 | 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 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import qualified Data.ByteString as B | ||
4 | import System.Environment | 5 | import System.Environment |
5 | import Remote.KRPC | 6 | import Remote.KRPC |
6 | import Shared | 7 | import Shared |
@@ -16,6 +17,9 @@ main = do | |||
16 | call addr reverseM [1..1000] | 17 | call addr reverseM [1..1000] |
17 | print =<< call addr swapM (0, 1) | 18 | print =<< call addr swapM (0, 1) |
18 | print =<< call addr shiftR ((), 1, [2..10]) | 19 | print =<< call addr shiftR ((), 1, [2..10]) |
20 | let bs = B.replicate (32 * 1024) 0 | ||
21 | bs' <- call addr echoBytes bs | ||
22 | print (bs == bs') | ||
19 | 23 | ||
20 | {- | 24 | {- |
21 | forM_ [1..] $ const $ do | 25 | 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 () | |||
9 | main = server 6000 | 9 | main = server 6000 |
10 | [ unitM ==> return | 10 | [ unitM ==> return |
11 | , echoM ==> return | 11 | , echoM ==> return |
12 | , echoBytes ==> return | ||
12 | , swapM ==> \(a, b) -> return (b, a) | 13 | , swapM ==> \(a, b) -> return (b, a) |
13 | , reverseM ==> return . reverse | 14 | , reverseM ==> return . reverse |
14 | , shiftR ==> \(a, b, c) -> return (c, a, b) | 15 | , 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 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | module Shared | 2 | module Shared |
3 | (echoM, unitM, swapM, reverseM, shiftR | 3 | (echoM, echoBytes, unitM, swapM, reverseM, shiftR |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Data.ByteString (ByteString) | ||
6 | import Remote.KRPC | 7 | import Remote.KRPC |
7 | 8 | ||
8 | unitM :: Method () () | 9 | unitM :: Method () () |
@@ -11,6 +12,9 @@ unitM = method "unit" [] [] | |||
11 | echoM :: Method Int Int | 12 | echoM :: Method Int Int |
12 | echoM = method "echo" ["x"] ["x"] | 13 | echoM = method "echo" ["x"] ["x"] |
13 | 14 | ||
15 | echoBytes :: Method ByteString ByteString | ||
16 | echoBytes = method "echoBytes" ["x"] ["x"] | ||
17 | |||
14 | reverseM :: Method [Int] [Int] | 18 | reverseM :: Method [Int] [Int] |
15 | reverseM = method "reverse" ["xs"] ["ys"] | 19 | reverseM = method "reverse" ["xs"] ["ys"] |
16 | 20 | ||
@@ -46,13 +46,13 @@ library | |||
46 | executable exsample-client | 46 | executable exsample-client |
47 | main-is: Client.hs | 47 | main-is: Client.hs |
48 | other-modules: Shared | 48 | other-modules: Shared |
49 | build-depends: base == 4.*, krpc | 49 | build-depends: base == 4.*, krpc, bytestring |
50 | hs-source-dirs: examples | 50 | hs-source-dirs: examples |
51 | 51 | ||
52 | executable exsample-server | 52 | executable exsample-server |
53 | main-is: Server.hs | 53 | main-is: Server.hs |
54 | other-modules: Shared | 54 | other-modules: Shared |
55 | build-depends: base == 4.*, krpc | 55 | build-depends: base == 4.*, krpc, bytestring |
56 | hs-source-dirs: examples | 56 | hs-source-dirs: examples |
57 | 57 | ||
58 | 58 | ||
@@ -60,13 +60,13 @@ executable exsample-server | |||
60 | 60 | ||
61 | executable bench-server | 61 | executable bench-server |
62 | main-is: Server.hs | 62 | main-is: Server.hs |
63 | build-depends: base == 4.*, krpc | 63 | build-depends: base == 4.*, krpc, bytestring |
64 | hs-source-dirs: bench | 64 | hs-source-dirs: bench |
65 | ghc-options: -O2 | 65 | ghc-options: -O2 -fforce-recomp |
66 | 66 | ||
67 | benchmark bench-client | 67 | benchmark bench-client |
68 | type: exitcode-stdio-1.0 | 68 | type: exitcode-stdio-1.0 |
69 | main-is: Main.hs | 69 | main-is: Main.hs |
70 | hs-source-dirs: bench | 70 | hs-source-dirs: bench |
71 | build-depends: base == 4.5.*, krpc, criterion | 71 | build-depends: base == 4.5.*, krpc, criterion, bytestring |
72 | ghc-options: -O2 \ No newline at end of file | 72 | 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 @@ | |||
6 | -- Portability : portable | 6 | -- Portability : portable |
7 | -- | 7 | -- |
8 | -- This module provides straightforward implementation of KRPC | 8 | -- This module provides straightforward implementation of KRPC |
9 | -- protocol. In many situations Network.KRPC should be prefered | 9 | -- protocol. In many situations 'Network.KRPC' should be prefered |
10 | -- since it gives more safe, convenient and high level api. | 10 | -- since it gives more safe, convenient and high level api. |
11 | -- | 11 | -- |
12 | -- > See http://www.bittorrent.org/beps/bep_0005.html#krpc-protocol | 12 | -- > See http://www.bittorrent.org/beps/bep_0005.html#krpc-protocol |
@@ -176,7 +176,7 @@ withRemote = bracket (liftIO (socket AF_INET Datagram defaultProtocol)) | |||
176 | 176 | ||
177 | 177 | ||
178 | maxMsgSize :: Int | 178 | maxMsgSize :: Int |
179 | maxMsgSize = 16 * 1024 | 179 | maxMsgSize = 512 |
180 | {-# INLINE maxMsgSize #-} | 180 | {-# INLINE maxMsgSize #-} |
181 | 181 | ||
182 | 182 | ||