summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-14 10:27:36 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-14 10:27:36 +0400
commitd0038e9bde22751c9c926796a6c46be62a3cb81b (patch)
treed0955ea60d53d672f10e1e7c3be065a65b4193a6
parenta2bc26abbe6ccea464c04b990f8a4a8fa769ba2a (diff)
~ Minor changes.
-rw-r--r--bench/Main.hs11
-rw-r--r--bench/Server.hs3
-rw-r--r--examples/Client.hs4
-rw-r--r--examples/Server.hs1
-rw-r--r--examples/Shared.hs6
-rw-r--r--krpc.cabal12
-rw-r--r--src/Remote/KRPC/Protocol.hs4
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 #-}
2module Main (main) where 2module Main (main) where
3 3
4import Control.Monad
5import Data.ByteString (ByteString)
6import qualified Data.ByteString as B
4import Criterion.Main 7import Criterion.Main
5import Remote.KRPC 8import Remote.KRPC
6 9
@@ -8,10 +11,12 @@ import Remote.KRPC
8addr :: RemoteAddr 11addr :: RemoteAddr
9addr = (0, 6000) 12addr = (0, 6000)
10 13
11echo :: Method [Int] [Int] 14echo :: Method ByteString ByteString
12echo = method "echo" ["x"] ["x"] 15echo = method "echo" ["x"] ["x"]
13 16
14main :: IO () 17main :: IO ()
15main = defaultMain $ map mkbench [1, 10, 100, 1000] 18main = 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 #-}
2module Main (main) where 2module Main (main) where
3 3
4import Data.ByteString (ByteString)
4import Remote.KRPC 5import Remote.KRPC
5 6
6 7
7echo :: Method [Int] [Int] 8echo :: Method ByteString ByteString
8echo = method "echo" ["x"] ["x"] 9echo = method "echo" ["x"] ["x"]
9 10
10main :: IO () 11main :: 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 #-}
2module Main (main) where 2module Main (main) where
3 3
4import qualified Data.ByteString as B
4import System.Environment 5import System.Environment
5import Remote.KRPC 6import Remote.KRPC
6import Shared 7import 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 ()
9main = server 6000 9main = 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 #-}
2module Shared 2module Shared
3 (echoM, unitM, swapM, reverseM, shiftR 3 (echoM, echoBytes, unitM, swapM, reverseM, shiftR
4 ) where 4 ) where
5 5
6import Data.ByteString (ByteString)
6import Remote.KRPC 7import Remote.KRPC
7 8
8unitM :: Method () () 9unitM :: Method () ()
@@ -11,6 +12,9 @@ unitM = method "unit" [] []
11echoM :: Method Int Int 12echoM :: Method Int Int
12echoM = method "echo" ["x"] ["x"] 13echoM = method "echo" ["x"] ["x"]
13 14
15echoBytes :: Method ByteString ByteString
16echoBytes = method "echoBytes" ["x"] ["x"]
17
14reverseM :: Method [Int] [Int] 18reverseM :: Method [Int] [Int]
15reverseM = method "reverse" ["xs"] ["ys"] 19reverseM = method "reverse" ["xs"] ["ys"]
16 20
diff --git a/krpc.cabal b/krpc.cabal
index e0fdb718..b9bd0f1a 100644
--- a/krpc.cabal
+++ b/krpc.cabal
@@ -46,13 +46,13 @@ library
46executable exsample-client 46executable 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
52executable exsample-server 52executable 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
61executable bench-server 61executable 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
67benchmark bench-client 67benchmark 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
178maxMsgSize :: Int 178maxMsgSize :: Int
179maxMsgSize = 16 * 1024 179maxMsgSize = 512
180{-# INLINE maxMsgSize #-} 180{-# INLINE maxMsgSize #-}
181 181
182 182