@@ -7,7 +7,7 @@ import Streamly.Network.Socket
7import Streamly.Internal.Network.Socket (handleWithM)
7import Streamly.Internal.Network.Socket (handleWithM)
8import Network.Socket as Socket
8import Network.Socket as Socket
9import Network.Socket.ByteString as Socket
9import Network.Socket.ByteString as Socket
10−import Streamly.Internal.Data.Parser.ParserD as PD
10+import Streamly.Internal.Data.Parser as P
11import Codec.Winery
11import Codec.Winery
12import Codec.Winery.Internal (varInt, decodeVarInt, getBytes)
12import Codec.Winery.Internal (varInt, decodeVarInt, getBytes)
13import Codec.Winery.Class (mkExtractor)
13import Codec.Winery.Class (mkExtractor)
@@ -37,7 +37,7 @@ import Foreign.ForeignPtr (plusForeignPtr)
37import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
37import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
38import GHC.Ptr (plusPtr)
38import GHC.Ptr (plusPtr)
40−import Debug.Trace
40+--import Debug.Trace
42data ClientHelloMessage = ClientHelloMessage Int Int
42data ClientHelloMessage = ClientHelloMessage Int Int
43 deriving Generic
43 deriving Generic
@@ -105,13 +105,13 @@ localHostAddr = (127,0,0,1)
105messageBoundaryP :: Parser IO Word8 BS.ByteString
105messageBoundaryP :: Parser IO Word8 BS.ByteString
106messageBoundaryP = do
106messageBoundaryP = do
107 let x = FL.toList
107 let x = FL.toList
108− w4x8 <- PD.take 4 x
108+ w4x8 <- P.take 4 x
109− traceShowM ("w4x8"::String, w4x8)
109+ --traceShowM ("w4x8"::String, w4x8)
110 let c = fromIntegral (BO.word32 (BS.pack w4x8))
110 let c = fromIntegral (BO.word32 (BS.pack w4x8))
111− traceShowM ("c"::String, c)
111+ --traceShowM ("c"::String, c)
112− vals <- PD.take c x
112+ vals <- P.take c x
113 let bytes = BS.pack vals
113 let bytes = BS.pack vals
114− traceShowM ("parsedBytes"::String, c, BS.length bytes, bytes)
114+ --traceShowM ("parsedBytes"::String, c, BS.length bytes, bytes)
115 pure bytes
115 pure bytes
117type NewConnectionHandler msg = IO (Maybe msg)
117type NewConnectionHandler msg = IO (Maybe msg)
@@ -186,22 +186,20 @@ drainSocketMessages sock msgHandler = do
186 print err
186 print err
187 Right val ->
187 Right val ->
188 msgHandler val --add response function
188 msgHandler val --add response function
189− S.drain $ serially $ S.parseManyD messageBoundaryP sockStream & S.mapM handler
189+ S.drain $ serially $ S.parseMany messageBoundaryP sockStream & S.mapM handler
191--send length-tagged bytestring, perhaps should be in network byte order?
191--send length-tagged bytestring, perhaps should be in network byte order?
192sendMessage :: Serialise a => Message a -> Socket -> IO ()
192sendMessage :: Serialise a => Message a -> Socket -> IO ()
193sendMessage msg socket' = do
193sendMessage msg socket' = do
194− let -- byteArray = toArraySlow fullbytes
194+ let
195− --dbgByteString = BS.pack (SA.toList byteArray)
196 msgbytes = serialise msg
195 msgbytes = serialise msg
197 fullbytes = lenbytes <> msgbytes
196 fullbytes = lenbytes <> msgbytes
198 len = BS.length msgbytes
197 len = BS.length msgbytes
199 lenbytes = BO.bytestring32 (fromIntegral len)
198 lenbytes = BO.bytestring32 (fromIntegral len)
200− --when (dbgByteString /= msgbytes) (error "mismatch!")
202 byteCount <- Socket.send socket' fullbytes
200 byteCount <- Socket.send socket' fullbytes
203 when (byteCount /= BS.length fullbytes) (error "bytes sent mismatch")
201 when (byteCount /= BS.length fullbytes) (error "bytes sent mismatch")
204− traceShowM ("sent bytes:" :: String, byteCount, fullbytes)
202+ --traceShowM ("sent bytes:" :: String, byteCount, fullbytes)
@@ -219,6 +217,6 @@ toArrayS (BSI.PS fp off len) = SA.Array nfp endPtr
219 endPtr = unsafeForeignPtrToPtr nfp `plusPtr` len `plusPtr` 1 -- ? why +1?
217 endPtr = unsafeForeignPtrToPtr nfp `plusPtr` len `plusPtr` 1 -- ? why +1?
221toArraySlow :: BS.ByteString -> SA.Array Word8
219toArraySlow :: BS.ByteString -> SA.Array Word8
222−toArraySlow bs = traceShow ("arr" :: String, SA.length arr) arr
220+toArraySlow bs = arr
224 arr = SA.fromList (BS.unpack bs)
222 arr = SA.fromList (BS.unpack bs)