on master help sign in
cabal.project+1−1
since splitsnapshots
unifiedsplit
@@ -3,4 +3,4 @@ packages: .
3source-repository-package
3source-repository-package
4 type: git
4 type: git
5 location: https://github.com/composewell/streamly.git
5 location: https://github.com/composewell/streamly.git
6− tag: ac3af8749194f1788704dda8667d0b3807075cc2
6+ tag: 4e48b52e8709390a47e99c107ebed2d1c9420076
curryer.cabal → curryer-rpc.cabalrenamed+8−7
@@ -1,4 +1,4 @@
1−Name: curryer
1+Name: curryer-rpc
2Version: 0.1
2Version: 0.1
3License: PublicDomain
3License: PublicDomain
4Build-Type: Simple
4Build-Type: Simple
@@ -11,7 +11,7 @@ Maintainer: agentm@themactionfaction.com
11Cabal-Version: >= 1.10
11Cabal-Version: >= 1.10
12Synopsis: Fast, Haskell RPC
12Synopsis: Fast, Haskell RPC
13Description: Haskell-to-Haskell RPC using Winery serialization.
13Description: Haskell-to-Haskell RPC using Winery serialization.
14−Extra-Source-Files: Changelog.markdown README.markdown
14+Extra-Source-Files: Changelog.markdown README.markdown cabal.project
15
15
16Source-Repository head
16Source-Repository head
17 Type: git
17 Type: git
@@ -51,7 +51,7 @@ Test-Suite test
51 build-depends: tasty
51 build-depends: tasty
52 , tasty-hunit
52 , tasty-hunit
53 , base
53 , base
54− , curryer
54+ , curryer-rpc
55 , winery
55 , winery
56 , network
56 , network
57 , async
57 , async
@@ -61,21 +61,22 @@ Test-Suite test
61Benchmark perf
61Benchmark perf
62 Default-Language: Haskell2010
62 Default-Language: Haskell2010
63 Default-Extensions: OverloadedStrings
63 Default-Extensions: OverloadedStrings
64− Build-Depends: base, criterion, curryer, network, winery, async, bytestring
64+ Build-Depends: base, criterion, curryer-rpc, network, winery, async, bytestring
65
65
66 Main-Is: Basic.hs
66 Main-Is: Basic.hs
67 Type: exitcode-stdio-1.0
67 Type: exitcode-stdio-1.0
68− GHC-Options: -Wall -threaded -rtsopts -fprof-auto
68+ GHC-Options: -Wall -threaded -rtsopts
69+ -- -fprof-auto
69 HS-Source-Dirs: ./bench
70 HS-Source-Dirs: ./bench
70
71
71Executable SimpleKeyValueServer
72Executable SimpleKeyValueServer
72− Build-Depends: stm-containers, stm, base, curryer, winery
73+ Build-Depends: stm-containers, stm, base, curryer-rpc, winery
73 Main-Is: examples/SimpleKeyValueServer.hs
74 Main-Is: examples/SimpleKeyValueServer.hs
74 GHC-Options: -Wall -threaded
75 GHC-Options: -Wall -threaded
75 Default-Language: Haskell2010
76 Default-Language: Haskell2010
76
77
77Executable SimpleKeyValueClient
78Executable SimpleKeyValueClient
78− Build-Depends: stm, base, curryer, winery, optparse-generic
79+ Build-Depends: stm, base, curryer-rpc, winery, optparse-generic
79 Main-Is: examples/SimpleKeyValueClient.hs
80 Main-Is: examples/SimpleKeyValueClient.hs
80 GHC-Options: -Wall -threaded
81 GHC-Options: -Wall -threaded
81 Default-Language: Haskell2010
82 Default-Language: Haskell2010
src/Network/RPC/Curryer/Server.hs+15−9
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DerivingVia, DeriveGeneric, RankNTypes, ScopedTypeVariables, MultiParamTypeClasses, OverloadedStrings, GeneralizedNewtypeDeriving, CPP, ExistentialQuantification, StandaloneDeriving, GADTs #-}
1+{-# LANGUAGE DerivingVia, DeriveGeneric, RankNTypes, ScopedTypeVariables, MultiParamTypeClasses, OverloadedStrings, GeneralizedNewtypeDeriving, CPP, ExistentialQuantification, StandaloneDeriving, GADTs, RecordWildCards #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3{- HLINT ignore "Use lambda-case" -}
3{- HLINT ignore "Use lambda-case" -}
4module Network.RPC.Curryer.Server where
4module Network.RPC.Curryer.Server where
@@ -35,13 +35,13 @@ import Data.Hashable
35import System.Timeout
35import System.Timeout
36import qualified Network.ByteOrder as BO
36import qualified Network.ByteOrder as BO
37
37
38+
38-- for toArrayS conversion
39-- for toArrayS conversion
39−{-import qualified Data.ByteString.Internal as BSI
40+import qualified Data.ByteString.Internal as BSI
40−import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as SA
41+import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as Arr
41−import Foreign.ForeignPtr (plusForeignPtr)
42import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
42import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
43−import GHC.Ptr (plusPtr)
43+import GHC.Ptr (minusPtr)
44−-}
44+
45-- define CURRYER_SHOW_BYTES 1
45-- define CURRYER_SHOW_BYTES 1
46#if CURRYER_SHOW_BYTES == 1
46#if CURRYER_SHOW_BYTES == 1
47import Debug.Trace
47import Debug.Trace
@@ -159,8 +159,7 @@ localHostAddr = (127,0,0,1)
159-- Each message is length-prefixed by a 32-bit unsigned length.
159-- Each message is length-prefixed by a 32-bit unsigned length.
160envelopeP :: Parser IO Word8 Envelope
160envelopeP :: Parser IO Word8 Envelope
161envelopeP = do
161envelopeP = do
162− let s = FL.toList
163− msgTypeP = (P.satisfy (== 0) *>
162+ let msgTypeP = (P.satisfy (== 0) *>
164 (RequestMessage . fromIntegral <$> word32P)) `P.alt`
163 (RequestMessage . fromIntegral <$> word32P)) `P.alt`
165 (P.satisfy (== 1) $> ResponseMessage) `P.alt`
164 (P.satisfy (== 1) $> ResponseMessage) `P.alt`
166 (P.satisfy (== 2) $> TimeoutResponseMessage) `P.alt`
165 (P.satisfy (== 2) $> TimeoutResponseMessage) `P.alt`
@@ -171,7 +170,7 @@ envelopeP = do
171 if c == 0 then
170 if c == 0 then
172 pure BS.empty
171 pure BS.empty
173 else
172 else
174− BS.pack <$> P.takeEQ c s
173+ fromArray <$> P.takeEQ c (Arr.writeN c)
175 Envelope <$> fingerprintP <*> msgTypeP <*> uuidP <*> lenPrefixedByteStringP
174 Envelope <$> fingerprintP <*> msgTypeP <*> uuidP <*> lenPrefixedByteStringP
176
175
177encodeEnvelope :: Envelope -> BS.ByteString
176encodeEnvelope :: Envelope -> BS.ByteString
@@ -334,3 +333,10 @@ sendEnvelope envelope sockLock = do
334fingerprint :: Typeable a => a -> Fingerprint
333fingerprint :: Typeable a => a -> Fingerprint
335fingerprint = typeRepFingerprint . typeOf
334fingerprint = typeRepFingerprint . typeOf
336
335
336+fromArray :: Arr.Array Word8 -> BSI.ByteString
337+fromArray Arr.Array {..}
338+ | aLen == 0 = mempty
339+ | otherwise = BSI.PS aStart 0 aLen
340+ where
341+ aStartPtr = unsafeForeignPtrToPtr aStart
342+ aLen = aEnd `minusPtr` aStartPtr