on master help sign in
make TCP client read an "unfold"
2080f85Harendra Kumar
src/Streamly/Internal/Network/Inet/TCP.hs+13−3
@@ -38,11 +38,12 @@ module Streamly.Internal.Network.Inet.TCP
38
38
39 -- ** Unfolds
39 -- ** Unfolds
40 , withServerAddr
40 , withServerAddr
41+ , read
41
42
42 -- ** Streams
43 -- ** Streams
43 , withConnection
44 , withConnection
44 -- *** Source
45 -- *** Source
45− , read
46+ , toStream
46 -- , readUtf8
47 -- , readUtf8
47 -- , readLines
48 -- , readLines
48 -- , readFrames
49 -- , readFrames
@@ -109,6 +110,7 @@ import Streamly.Streams.StreamK.Type (IsStream)
109
110
110import qualified Network.Socket as Net
111import qualified Network.Socket as Net
111import qualified Streamly.Internal.Data.Unfold as UF
112import qualified Streamly.Internal.Data.Unfold as UF
113+import qualified Streamly.Internal.Memory.Array as A
112import qualified Streamly.Internal.Memory.ArrayStream as AS
114import qualified Streamly.Internal.Memory.ArrayStream as AS
113import qualified Streamly.Internal.Data.Fold.Types as FL
115import qualified Streamly.Internal.Data.Fold.Types as FL
114import qualified Streamly.Prelude as S
116import qualified Streamly.Prelude as S
@@ -279,9 +281,17 @@ withConnection addr port =
279--
281--
280-- @since 0.7.0
282-- @since 0.7.0
281{-# INLINE read #-}
283{-# INLINE read #-}
284+read :: (MonadCatch m, MonadIO m)
285+ => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Word8
286+read = UF.concat (withServerAddr ISK.readArrays) A.read
287+
288+-- | Read a stream from the supplied IPv4 host address and port number.
289+--
290+-- @since 0.7.0
291+{-# INLINE toStream #-}
282−read :: (IsStream t, MonadCatch m, MonadIO m)
292+toStream :: (IsStream t, MonadCatch m, MonadIO m)
283 => (Word8, Word8, Word8, Word8) -> PortNumber -> t m Word8
293 => (Word8, Word8, Word8, Word8) -> PortNumber -> t m Word8
284−read addr port = AS.concat $ withConnection addr port ISK.toStreamArrays
294+toStream addr port = AS.concat $ withConnection addr port ISK.toStreamArrays
285
295
286-------------------------------------------------------------------------------
296-------------------------------------------------------------------------------
287-- Writing
297-- Writing