on master help sign in
rename readRequestsOf to readWithBufferOf etc.
commit6d0c0e95f07a82234422225f71ce3c4b7761bc84 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 6 Nov 2019, 19:16 (7 years ago) parent70bbd5c
10 files changed+152−170
examples/EchoServer.hs+1−1 examples/FileIOExamples.hs+3−3 examples/HandleIO.hs+2−2 examples/WordCount.hs+1−1 src/Streamly/Benchmark/FileIO/Array.hs+10−10 src/Streamly/FileSystem/Handle.hs+3−3 src/Streamly/Internal/FileSystem/File.hs+22−41 src/Streamly/Internal/FileSystem/Handle.hs+69−68 src/Streamly/Internal/Network/Socket.hs+38−38 src/Streamly/Network/Socket.hs+3−3
examples/EchoServer.hs+1−1
@@ -15,5 +15,5 @@ main = S.drain
1515 where
1616 echo sk =
1717 S.fold (writeChunks sk)
18− $ S.unfold readChunksRequestsOf (32768, sk)
18+ $ S.unfold readChunksWithBufferOf (32768, sk)
1919 useWith f sk = finally (liftIO (Net.close sk)) (f sk)
examples/FileIOExamples.hs+3−3
@@ -10,17 +10,17 @@ import System.Environment (getArgs)
1010cat :: FilePath -> IO ()
1111cat src =
1212 File.writeChunks "/dev/stdout"
13− $ File.toChunksRequestsOf (256*1024) src
13+ $ File.toChunksWithBufferOf (256*1024) src
1414
1515cp :: FilePath -> FilePath -> IO ()
1616cp src dst =
1717 File.writeChunks dst
18− $ File.toChunksRequestsOf (256*1024) src
18+ $ File.toChunksWithBufferOf (256*1024) src
1919
2020append :: FilePath -> FilePath -> IO ()
2121append src dst =
2222 File.appendChunks dst
23− $ File.toChunksRequestsOf (256*1024) src
23+ $ File.toChunksWithBufferOf (256*1024) src
2424
2525ord' :: Num a => Char -> a
2626ord' = (fromIntegral . ord)
examples/HandleIO.hs+2−2
@@ -15,14 +15,14 @@ import System.IO (IOMode(..), hSeek, SeekMode(..))
1515cat :: FH.Handle -> IO ()
1616cat src =
1717 S.fold (FH.writeChunks FH.stdout)
18− $ IFH.toChunksRequestsOf (256*1024) src
18+ $ IFH.toChunksWithBufferOf (256*1024) src
1919-- byte stream version
2020-- cat src = S.fold (FH.write FH.stdout) $ FH.read src
2121
2222cp :: FH.Handle -> FH.Handle -> IO ()
2323cp src dst =
2424 S.fold (FH.writeChunks dst)
25− $ IFH.toChunksRequestsOf (256*1024) src
25+ $ IFH.toChunksWithBufferOf (256*1024) src
2626-- byte stream version
2727-- cp src dst = S.fold (FH.write dst) $ FH.read src
2828
examples/WordCount.hs+1−1
@@ -608,7 +608,7 @@ wc_mwl_parallel src n = do
608608 $ S.aheadly
609609 $ S.maxThreads numCapabilities
610610 $ S.mapM (countArray)
611− $ S.unfold FH.readChunksRequestsOf (n, src)
611+ $ S.unfold FH.readChunksWithBufferOf (n, src)
612612
613613-------------------------------------------------------------------------------
614614-- Main
src/Streamly/Benchmark/FileIO/Array.hs+10−10
@@ -124,7 +124,7 @@ inspect $ 'sumBytes `hasNoType` ''Step
124124{-# INLINE cat #-}
125125cat :: Handle -> Handle -> IO ()
126126cat devNull inh =
127− S.fold (IFH.writeChunks devNull) $ IFH.toChunksRequestsOf (256*1024) inh
127+ S.fold (IFH.writeChunks devNull) $ IFH.toChunksWithBufferOf (256*1024) inh
128128
129129#ifdef INSPECTION
130130inspect $ hasNoTypeClasses 'cat
@@ -136,7 +136,7 @@ inspect $ 'cat `hasNoType` ''Step
136136catBracket :: Handle -> Handle -> IO ()
137137catBracket devNull inh =
138138 let readEx = IUF.bracket return (\_ -> hClose inh)
139− (IUF.supplyFirst FH.readChunksRequestsOf (256*1024))
139+ (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
140140 in IUF.fold readEx (IFH.writeChunks devNull) inh
141141
142142#ifdef INSPECTION
@@ -149,7 +149,7 @@ inspect $ hasNoTypeClasses 'catBracket
149149catBracketStream :: Handle -> Handle -> IO ()
150150catBracketStream devNull inh =
151151 let readEx = S.bracket (return ()) (\_ -> hClose inh)
152− (\_ -> IFH.toChunksRequestsOf (256*1024) inh)
152+ (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
153153 in S.fold (IFH.writeChunks devNull) $ readEx
154154
155155#ifdef INSPECTION
@@ -162,7 +162,7 @@ inspect $ hasNoTypeClasses 'catBracketStream
162162catOnException :: Handle -> Handle -> IO ()
163163catOnException devNull inh =
164164 let readEx = IUF.onException (\_ -> hClose inh)
165− (IUF.supplyFirst FH.readChunksRequestsOf (256*1024))
165+ (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
166166 in IUF.fold readEx (IFH.writeChunks devNull) inh
167167
168168#ifdef INSPECTION
@@ -186,10 +186,10 @@ inspect $ 'copy `hasNoType` ''Step
186186{-# INLINE linesUnlinesCopy #-}
187187linesUnlinesCopy :: Handle -> Handle -> IO ()
188188linesUnlinesCopy inh outh =
189− S.fold (IFH.writeRequestsOf (1024*1024) outh)
189+ S.fold (IFH.writeWithBufferOf (1024*1024) outh)
190190 $ AS.interposeSuffix 10
191191 $ AS.splitOnSuffix 10
192− $ IFH.toChunksRequestsOf (1024*1024) inh
192+ $ IFH.toChunksWithBufferOf (1024*1024) inh
193193
194194#ifdef INSPECTION
195195inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
@@ -200,11 +200,11 @@ inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
200200{-# INLINE wordsUnwordsCopy #-}
201201wordsUnwordsCopy :: Handle -> Handle -> IO ()
202202wordsUnwordsCopy inh outh =
203− S.fold (IFH.writeRequestsOf (1024*1024) outh)
203+ S.fold (IFH.writeWithBufferOf (1024*1024) outh)
204204 $ AS.interpose 32
205205 -- XXX this is not correct word splitting combinator
206206 $ AS.splitOn 32
207− $ IFH.toChunksRequestsOf (1024*1024) inh
207+ $ IFH.toChunksWithBufferOf (1024*1024) inh
208208
209209#ifdef INSPECTION
210210inspect $ hasNoTypeClassesExcept 'wordsUnwordsCopy [''Storable]
@@ -216,7 +216,7 @@ decodeUtf8Lenient :: Handle -> IO ()
216216decodeUtf8Lenient inh =
217217 S.drain
218218 $ IUS.decodeUtf8ArraysLenient
219− $ IFH.toChunksRequestsOf (1024*1024) inh
219+ $ IFH.toChunksWithBufferOf (1024*1024) inh
220220
221221#ifdef INSPECTION
222222inspect $ hasNoTypeClasses 'decodeUtf8Lenient
@@ -232,7 +232,7 @@ copyCodecUtf8Lenient inh outh =
232232 S.fold (FH.write outh)
233233 $ SS.encodeUtf8
234234 $ IUS.decodeUtf8ArraysLenient
235− $ IFH.toChunksRequestsOf (1024*1024) inh
235+ $ IFH.toChunksWithBufferOf (1024*1024) inh
236236
237237#ifdef INSPECTION
238238inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
src/Streamly/FileSystem/Handle.hs+3−3
@@ -72,9 +72,9 @@ module Streamly.FileSystem.Handle
7272 -- encountered.
7373
7474 read
75− , readRequestsOf
75+ , readWithBufferOf
7676 , readChunks
77− , readChunksRequestsOf
77+ , readChunksWithBufferOf
7878
7979 -- ** Write to Handle
8080 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
@@ -83,7 +83,7 @@ module Streamly.FileSystem.Handle
8383 -- of the handle.
8484
8585 , write
86− , writeRequestsOf
86+ , writeWithBufferOf
8787 , writeChunks
8888 )
8989where
src/Streamly/Internal/FileSystem/File.hs+22−41
@@ -58,13 +58,13 @@ module Streamly.Internal.FileSystem.File
5858 -- , readUtf8
5959 -- , readLines
6060 -- , readFrames
61− -- , readByChunks
61+ -- , readChunks
6262
6363 -- -- * Array Read
6464 -- , readArrayOf
6565
66− , toChunksRequestsOf
67− -- , toChunksRequestsOf
66+ , toChunksWithBufferOf
67+ -- , toChunksWithBufferOf
6868 , toChunks
6969
7070 -- ** Write To File
@@ -72,7 +72,7 @@ module Streamly.Internal.FileSystem.File
7272 -- , writeUtf8
7373 -- , writeUtf8ByLines
7474 -- , writeByFrames
75− , writeRequestsOf
75+ , writeWithBufferOf
7676
7777 -- -- * Array Write
7878 , writeArray
@@ -80,29 +80,10 @@ module Streamly.Internal.FileSystem.File
8080
8181 -- ** Append To File
8282 , append
83− , appendRequestsOf
83+ , appendWithBufferOf
8484 -- , appendShared
8585 , appendArray
8686 , appendChunks
87−
88− -- -- * Random Access (Seek)
89− -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
90− -- files that have random access or seek capability. This type of devices
91− -- include disks, files, memory devices and exclude terminals, pipes,
92− -- sockets and fifos.
93− --
94− -- , readIndex
95− -- , readSlice
96− -- , readSliceRev
97− -- , readAt -- read from a given position to th end of file
98− -- , readSliceArrayUpto
99− -- , readSliceArrayOf
100−
101− -- , writeIndex
102− -- , writeSlice
103− -- , writeSliceRev
104− -- , writeAt -- start writing at the given position
105− -- , writeSliceArray
10687 )
10788where
10889
@@ -182,14 +163,14 @@ appendArray file arr = SIO.withFile file AppendMode (\h -> FH.writeArray h arr)
182163-- Stream of Arrays IO
183164-------------------------------------------------------------------------------
184165
185−-- | @toChunksRequestsOf size file@ reads a stream of arrays from file @file@.
166+-- | @toChunksWithBufferOf size file@ reads a stream of arrays from file @file@.
186167-- The maximum size of a single array is specified by @size@. The actual size
187168-- read may be less than or equal to @size@.
188−{-# INLINABLE toChunksRequestsOf #-}
189−toChunksRequestsOf :: (IsStream t, MonadCatch m, MonadIO m)
169+{-# INLINABLE toChunksWithBufferOf #-}
170+toChunksWithBufferOf :: (IsStream t, MonadCatch m, MonadIO m)
190171 => Int -> FilePath -> t m (Array Word8)
191−toChunksRequestsOf size file =
192− withFile file ReadMode (FH.toChunksRequestsOf size)
172+toChunksWithBufferOf size file =
173+ withFile file ReadMode (FH.toChunksWithBufferOf size)
193174
194175-- XXX read 'Array a' instead of Word8
195176--
@@ -197,13 +178,13 @@ toChunksRequestsOf size file =
197178-- The maximum size of a single array is limited to @defaultChunkSize@. The
198179-- actual size read may be less than @defaultChunkSize@.
199180--
200−-- > toChunks = toChunksRequestsOf defaultChunkSize
181+-- > toChunks = toChunksWithBufferOf defaultChunkSize
201182--
202183-- @since 0.7.0
203184{-# INLINE toChunks #-}
204185toChunks :: (IsStream t, MonadCatch m, MonadIO m)
205186 => FilePath -> t m (Array Word8)
206−toChunks = toChunksRequestsOf defaultChunkSize
187+toChunks = toChunksWithBufferOf defaultChunkSize
207188
208189-------------------------------------------------------------------------------
209190-- Read File to Stream
@@ -220,7 +201,7 @@ toChunks = toChunksRequestsOf defaultChunkSize
220201--
221202{-# INLINE readInChunksOf #-}
222203readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
223−readInChunksOf chunkSize h = A.flattenArrays $ toChunksRequestsOf chunkSize h
204+readInChunksOf chunkSize h = A.flattenArrays $ toChunksWithBufferOf chunkSize h
224205-}
225206
226207-- TODO
@@ -287,12 +268,12 @@ writeChunks = writeChunksMode WriteMode
287268-- input elements.
288269--
289270-- @since 0.7.0
290−{-# INLINE writeRequestsOf #-}
291−writeRequestsOf :: (MonadAsync m, MonadCatch m)
271+{-# INLINE writeWithBufferOf #-}
272+writeWithBufferOf :: (MonadAsync m, MonadCatch m)
292273 => Int -> FilePath -> SerialT m Word8 -> m ()
293−writeRequestsOf n file xs = writeChunks file $ AS.arraysOf n xs
274+writeWithBufferOf n file xs = writeChunks file $ AS.arraysOf n xs
294275
295−-- > write = 'writeRequestsOf' defaultChunkSize
276+-- > write = 'writeWithBufferOf' defaultChunkSize
296277--
297278-- | Write a byte stream to a file. Combines the bytes in chunks of size
298279-- up to 'A.defaultChunkSize' before writing. If the file exists it is
@@ -302,7 +283,7 @@ writeRequestsOf n file xs = writeChunks file $ AS.arraysOf n xs
302283-- @since 0.7.0
303284{-# INLINE write #-}
304285write :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
305−write = writeRequestsOf defaultChunkSize
286+write = writeWithBufferOf defaultChunkSize
306287
307288{-
308289{-# INLINE write #-}
@@ -323,10 +304,10 @@ appendChunks = writeChunksMode AppendMode
323304-- input elements.
324305--
325306-- @since 0.7.0
326−{-# INLINE appendRequestsOf #-}
327−appendRequestsOf :: (MonadAsync m, MonadCatch m)
307+{-# INLINE appendWithBufferOf #-}
308+appendWithBufferOf :: (MonadAsync m, MonadCatch m)
328309 => Int -> FilePath -> SerialT m Word8 -> m ()
329−appendRequestsOf n file xs = appendChunks file $ AS.arraysOf n xs
310+appendWithBufferOf n file xs = appendChunks file $ AS.arraysOf n xs
330311
331312-- | Append a byte stream to a file. Combines the bytes in chunks of size up to
332313-- 'A.defaultChunkSize' before writing. If the file exists then the new data
@@ -336,7 +317,7 @@ appendRequestsOf n file xs = appendChunks file $ AS.arraysOf n xs
336317-- @since 0.7.0
337318{-# INLINE append #-}
338319append :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
339−append = appendRequestsOf defaultChunkSize
320+append = appendWithBufferOf defaultChunkSize
340321
341322{-
342323-- | Like 'append' but the file is not locked for exclusive writes.
src/Streamly/Internal/FileSystem/Handle.hs+69−68
@@ -22,18 +22,18 @@ module Streamly.Internal.FileSystem.Handle
2222 -- , readUtf8
2323 -- , readLines
2424 -- , readFrames
25− , readRequestsOf
25+ , readWithBufferOf
2626
2727 , toStream
28− , toStreamRequestsOf
28+ , toStreamWithBufferOf
2929
3030 -- -- * Array Read
3131 -- , readArrayUpto
3232 -- , readArrayOf
3333 , readChunks
34− , readChunksRequestsOf
34+ , readChunksWithBufferOf
3535
36− , toChunksRequestsOf
36+ , toChunksWithBufferOf
3737 , toChunks
3838
3939 -- ** Write to Handle
@@ -42,20 +42,20 @@ module Streamly.Internal.FileSystem.Handle
4242 -- , writeUtf8
4343 -- , writeUtf8ByLines
4444 -- , writeByFrames
45− , writeRequestsOf
45+ , writeWithBufferOf
4646
4747 -- Byte stream write (Streams)
4848 , fromStream
49− , fromStreamInChunksOf
49+ , fromStreamWithBufferOf
5050
5151 -- -- * Array Write
5252 , writeArray
5353 , writeChunks
54− , writeChunksRequestsOf
54+ , writeChunksWithBufferOf
5555
5656 -- -- * Array stream Write
57− , fromStreamArrays
58− , fromStreamArraysInChunksOf
57+ , fromChunks
58+ , fromChunksWithBufferOf
5959
6060 -- -- * Random Access (Seek)
6161 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -79,8 +79,8 @@ module Streamly.Internal.FileSystem.Handle
7979
8080 -- , readChunksFrom
8181 -- , readChunksFromTo
82− -- , readChunksFromToRequestsOf
83− -- , readChunksFromThenToRequestsOf
82+ -- , readChunksFromToWithBufferOf
83+ -- , readChunksFromThenToWithBufferOf
8484
8585 -- , writeIndex
8686 -- , writeFrom -- start writing at the given position
@@ -92,8 +92,8 @@ module Streamly.Internal.FileSystem.Handle
9292 --
9393 -- , writeChunksFrom
9494 -- , writeChunksFromTo
95− -- , writeChunksFromToRequestsOf
96− -- , writeChunksFromThenToRequestsOf
95+ -- , writeChunksFromToWithBufferOf
96+ -- , writeChunksFromThenToWithBufferOf
9797 )
9898where
9999
@@ -164,13 +164,13 @@ readArrayUpto size h = do
164164-- Stream of Arrays IO
165165-------------------------------------------------------------------------------
166166
167−-- | @toChunksRequestsOf size h@ reads a stream of arrays from file handle @h@.
167+-- | @toChunksWithBufferOf size h@ reads a stream of arrays from file handle @h@.
168168-- The maximum size of a single array is specified by @size@. The actual size
169169-- read may be less than or equal to @size@.
170−{-# INLINABLE _toChunksRequestsOf #-}
171−_toChunksRequestsOf :: (IsStream t, MonadIO m)
170+{-# INLINABLE _toChunksWithBufferOf #-}
171+_toChunksWithBufferOf :: (IsStream t, MonadIO m)
172172 => Int -> Handle -> t m (Array Word8)
173−_toChunksRequestsOf size h = go
173+_toChunksWithBufferOf size h = go
174174 where
175175 -- XXX use cons/nil instead
176176 go = mkStream $ \_ yld _ stp -> do
@@ -179,14 +179,14 @@ _toChunksRequestsOf size h = go
179179 then stp
180180 else yld arr go
181181
182−-- | @toChunksRequestsOf size handle@ reads a stream of arrays from the file
182+-- | @toChunksWithBufferOf size handle@ reads a stream of arrays from the file
183183-- handle @handle@. The maximum size of a single array is limited to @size@.
184184-- The actual size read may be less than or equal to @size@.
185185--
186186-- @since 0.7.0
187−{-# INLINE_NORMAL toChunksRequestsOf #-}
188−toChunksRequestsOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
189−toChunksRequestsOf size h = D.fromStreamD (D.Stream step ())
187+{-# INLINE_NORMAL toChunksWithBufferOf #-}
188+toChunksWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
189+toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
190190 where
191191 {-# INLINE_LATE step #-}
192192 step _ _ = do
@@ -196,14 +196,15 @@ toChunksRequestsOf size h = D.fromStreamD (D.Stream step ())
196196 0 -> D.Stop
197197 _ -> D.Yield arr ()
198198
199−-- | Unfold the tuple @(size, handle)@ into a stream of 'Word8' arrays. The
200−-- stream consists of arrays representing chunks of data read from the handle.
201−-- The size of an array in the stream is less than or equal to @size@.
199+-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
200+-- Read requests to the IO device are performed using a buffer of size
201+-- @bufsize@. The size of an array in the resulting stream is always less than
202+-- or equal to @bufsize@.
202203--
203204-- @since 0.7.0
204−{-# INLINE_NORMAL readChunksRequestsOf #-}
205−readChunksRequestsOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
206−readChunksRequestsOf = Unfold step return
205+{-# INLINE_NORMAL readChunksWithBufferOf #-}
206+readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
207+readChunksWithBufferOf = Unfold step return
207208 where
208209 {-# INLINE_LATE step #-}
209210 step (size, h) = do
@@ -220,12 +221,12 @@ readChunksRequestsOf = Unfold step return
220221-- @defaultChunkSize@. The actual size read may be less than or equal to
221222-- @defaultChunkSize@.
222223--
223−-- > toChunks = toChunksRequestsOf defaultChunkSize
224+-- > toChunks = toChunksWithBufferOf defaultChunkSize
224225--
225226-- @since 0.7.0
226227{-# INLINE toChunks #-}
227228toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
228−toChunks = toChunksRequestsOf defaultChunkSize
229+toChunks = toChunksWithBufferOf defaultChunkSize
229230
230231-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
231232-- device are performed using a buffer of size
@@ -236,7 +237,7 @@ toChunks = toChunksRequestsOf defaultChunkSize
236237-- @since 0.7.0
237238{-# INLINE readChunks #-}
238239readChunks :: MonadIO m => Unfold m Handle (Array Word8)
239−readChunks = UF.supplyFirst readChunksRequestsOf defaultChunkSize
240+readChunks = UF.supplyFirst readChunksWithBufferOf defaultChunkSize
240241
241242-------------------------------------------------------------------------------
242243-- Read File to Stream
@@ -246,21 +247,21 @@ readChunks = UF.supplyFirst readChunksRequestsOf defaultChunkSize
246247-- read requests at the same time. For serial case we can use async IO. We can
247248-- also control the read throughput in mbps or IOPS.
248249
249−-- | Unfolds the tuple @(chunksize, handle)@ into a byte stream, read requests
250−-- to the IO device are performed using buffers of @chunkSize@.
250+-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
251+-- to the IO device are performed using buffers of @bufsize@.
251252--
252253-- @since 0.7.0
253−{-# INLINE readRequestsOf #-}
254−readRequestsOf :: MonadIO m => Unfold m (Int, Handle) Word8
255−readRequestsOf = UF.concat readChunksRequestsOf A.read
254+{-# INLINE readWithBufferOf #-}
255+readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
256+readWithBufferOf = UF.concat readChunksWithBufferOf A.read
256257
257−-- | @toStreamRequestsOf chunkSize handle@ reads a byte stream from a file
258−-- handle, reads are performed in chunks of up to @chunkSize@.
258+-- | @toStreamWithBufferOf bufsize handle@ reads a byte stream from a file
259+-- handle, reads are performed in chunks of up to @bufsize@.
259260--
260261-- /Internal/
261−{-# INLINE toStreamRequestsOf #-}
262−toStreamRequestsOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
263−toStreamRequestsOf chunkSize h = AS.concat $ toChunksRequestsOf chunkSize h
262+{-# INLINE toStreamWithBufferOf #-}
263+toStreamWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
264+toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
264265
265266-- TODO
266267-- Generate a stream of elements of the given type from a file 'Handle'.
@@ -273,7 +274,7 @@ toStreamRequestsOf chunkSize h = AS.concat $ toChunksRequestsOf chunkSize h
273274-- @since 0.7.0
274275{-# INLINE read #-}
275276read :: MonadIO m => Unfold m Handle Word8
276−read = UF.supplyFirst readRequestsOf defaultChunkSize
277+read = UF.supplyFirst readWithBufferOf defaultChunkSize
277278
278279-- | Generate a byte stream from a file 'Handle'.
279280--
@@ -313,33 +314,33 @@ writeArray h Array{..} = withForeignPtr aStart $ \p -> hPutBuf h p aLen
313314-- | Write a stream of arrays to a handle.
314315--
315316-- @since 0.7.0
316−{-# INLINE fromStreamArrays #-}
317−fromStreamArrays :: (MonadIO m, Storable a)
317+{-# INLINE fromChunks #-}
318+fromChunks :: (MonadIO m, Storable a)
318319 => Handle -> SerialT m (Array a) -> m ()
319−fromStreamArrays h m = S.mapM_ (liftIO . writeArray h) m
320+fromChunks h m = S.mapM_ (liftIO . writeArray h) m
320321
321−-- | @fromStreamArraysInChunksOf chunkSize handle stream@ writes a stream of arrays
322−-- to @handle@ after coalescing the adjacent arrays in chunks of @chunkSize@.
322+-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
323+-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
323324-- The chunk size is only a maximum and the actual writes could be smaller as
324325-- we do not split the arrays to fit exactly to the specified size.
325326--
326327-- @since 0.7.0
327−{-# INLINE fromStreamArraysInChunksOf #-}
328−fromStreamArraysInChunksOf :: (MonadIO m, Storable a)
328+{-# INLINE fromChunksWithBufferOf #-}
329+fromChunksWithBufferOf :: (MonadIO m, Storable a)
329330 => Int -> Handle -> SerialT m (Array a) -> m ()
330−fromStreamArraysInChunksOf n h xs = fromStreamArrays h $ AS.compact n xs
331+fromChunksWithBufferOf n h xs = fromChunks h $ AS.compact n xs
331332
332−-- | @fromStreamInChunksOf chunkSize handle stream@ writes @stream@ to @handle@ in
333−-- chunks of @chunkSize@. A write is performed to the IO device as soon as we
333+-- | @fromStreamWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
334+-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
334335-- collect the required input size.
335336--
336337-- @since 0.7.0
337−{-# INLINE fromStreamInChunksOf #-}
338−fromStreamInChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
339−fromStreamInChunksOf n h m = fromStreamArrays h $ S.arraysOf n m
340−-- fromStreamInChunksOf n h m = fromStreamArrays h $ AS.arraysOf n m
338+{-# INLINE fromStreamWithBufferOf #-}
339+fromStreamWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
340+fromStreamWithBufferOf n h m = fromChunks h $ S.arraysOf n m
341+-- fromStreamWithBufferOf n h m = fromChunks h $ AS.arraysOf n m
341342
342−-- > write = 'writeRequestsOf' A.defaultChunkSize
343+-- > write = 'writeWithBufferOf' A.defaultChunkSize
343344--
344345-- | Write a byte stream to a file handle. Accumulates the input in chunks of
345346-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing.
@@ -350,7 +351,7 @@ fromStreamInChunksOf n h m = fromStreamArrays h $ S.arraysOf n m
350351-- @since 0.7.0
351352{-# INLINE fromStream #-}
352353fromStream :: MonadIO m => Handle -> SerialT m Word8 -> m ()
353−fromStream = fromStreamInChunksOf defaultChunkSize
354+fromStream = fromStreamWithBufferOf defaultChunkSize
354355
355356-- | Write a stream of arrays to a handle. Each array in the stream is written
356357-- to the device as a separate IO request.
@@ -360,17 +361,17 @@ fromStream = fromStreamInChunksOf defaultChunkSize
360361writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
361362writeChunks h = FL.drainBy (liftIO . writeArray h)
362363
363−-- | @writeChunksRequestsOf chunkSize handle@ writes a stream of arrays
364−-- to @handle@ after coalescing the adjacent arrays in chunks of @chunkSize@.
364+-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
365+-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
365366-- We never split an array, if a single array is bigger than the specified size
366367-- it emitted as it is. Multiple arrays are coalesed as long as the total size
367368-- remains below the specified size.
368369--
369370-- @since 0.7.0
370−{-# INLINE writeChunksRequestsOf #-}
371−writeChunksRequestsOf :: (MonadIO m, Storable a)
371+{-# INLINE writeChunksWithBufferOf #-}
372+writeChunksWithBufferOf :: (MonadIO m, Storable a)
372373 => Int -> Handle -> Fold m (Array a) ()
373−writeChunksRequestsOf n h = lpackArraysChunksOf n (writeChunks h)
374+writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
374375
375376-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
376377--
@@ -380,16 +381,16 @@ writeChunksRequestsOf n h = lpackArraysChunksOf n (writeChunks h)
380381-- do not want buffering to occur at GHC level as well. Same thing applies to
381382-- writes as well.
382383
383−-- | @writeRequestsOf reqSize handle@ writes the input stream to @handle@.
384+-- | @writeWithBufferOf reqSize handle@ writes the input stream to @handle@.
384385-- Bytes in the input stream are collected into a buffer until we have a chunk
385386-- of @reqSize@ and then written to the IO device.
386387--
387388-- @since 0.7.0
388−{-# INLINE writeRequestsOf #-}
389−writeRequestsOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
390−writeRequestsOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
389+{-# INLINE writeWithBufferOf #-}
390+writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
391+writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
391392
392−-- > write = 'writeRequestsOf' A.defaultChunkSize
393+-- > write = 'writeWithBufferOf' A.defaultChunkSize
393394--
394395-- | Write a byte stream to a file handle. Accumulates the input in chunks of
395396-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing
@@ -398,7 +399,7 @@ writeRequestsOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
398399-- @since 0.7.0
399400{-# INLINE write #-}
400401write :: MonadIO m => Handle -> Fold m Word8 ()
401−write = writeRequestsOf defaultChunkSize
402+write = writeWithBufferOf defaultChunkSize
402403
403404{-
404405{-# INLINE write #-}
src/Streamly/Internal/Network/Socket.hs+38−38
@@ -29,7 +29,7 @@ module Streamly.Internal.Network.Socket
2929
3030 -- * Read from connection
3131 , read
32− , readRequestsOf
32+ , readWithBufferOf
3333 -- , readUtf8
3434 -- , readLines
3535 -- , readFrames
@@ -41,10 +41,10 @@ module Streamly.Internal.Network.Socket
4141 -- , readArrayOf
4242
4343 -- , readChunksUpto
44− , readChunksRequestsOf
44+ , readChunksWithBufferOf
4545 , readChunks
4646
47− , toChunksRequestsOf
47+ , toChunksWithBufferOf
4848 , toChunks
4949
5050 -- * Write to connection
@@ -52,7 +52,7 @@ module Streamly.Internal.Network.Socket
5252 -- , writeUtf8
5353 -- , writeUtf8ByLines
5454 -- , writeByFrames
55− , writeRequestsOf
55+ , writeWithBufferOf
5656
5757 -- -- * Array Write
5858 , writeArray
@@ -295,14 +295,14 @@ readChunksUptoWith f size h = go
295295 then stp
296296 else yld arr go
297297
298−-- | @toChunksRequestsOf size h@ reads a stream of arrays from file handle @h@.
298+-- | @toChunksWithBufferOf size h@ reads a stream of arrays from file handle @h@.
299299-- The maximum size of a single array is limited to @size@.
300300-- 'fromHandleArraysUpto' ignores the prevailing 'TextEncoding' and 'NewlineMode'
301301-- on the 'Handle'.
302−{-# INLINABLE toChunksRequestsOf #-}
303−toChunksRequestsOf :: (IsStream t, MonadIO m)
302+{-# INLINABLE toChunksWithBufferOf #-}
303+toChunksWithBufferOf :: (IsStream t, MonadIO m)
304304 => Int -> Socket -> t m (Array Word8)
305−toChunksRequestsOf = readChunksUptoWith readArrayOf
305+toChunksWithBufferOf = readChunksUptoWith readArrayOf
306306
307307-- XXX read 'Array a' instead of Word8
308308--
@@ -312,17 +312,17 @@ toChunksRequestsOf = readChunksUptoWith readArrayOf
312312-- @since 0.7.0
313313{-# INLINE toChunks #-}
314314toChunks :: (IsStream t, MonadIO m) => Socket -> t m (Array Word8)
315−toChunks = toChunksRequestsOf A.defaultChunkSize
315+toChunks = toChunksWithBufferOf A.defaultChunkSize
316316
317−-- | Unfold the tuple @(size, socket)@ into a stream of 'Word8' arrays. The
318−-- stream consists of arrays representing chunks of data read from the socket.
319−-- The size of an array in the resulting stream is less than or equal to
320−-- @size@.
317+-- | Unfold the tuple @(bufsize, socket)@ into a stream of 'Word8' arrays.
318+-- Read requests to the socket are performed using a buffer of size @bufsize@.
319+-- The size of an array in the resulting stream is always less than or equal to
320+-- @bufsize@.
321321--
322322-- @since 0.7.0
323−{-# INLINE_NORMAL readChunksRequestsOf #-}
324−readChunksRequestsOf :: MonadIO m => Unfold m (Int, Socket) (Array Word8)
325−readChunksRequestsOf = Unfold step return
323+{-# INLINE_NORMAL readChunksWithBufferOf #-}
324+readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Socket) (Array Word8)
325+readChunksWithBufferOf = Unfold step return
326326 where
327327 {-# INLINE_LATE step #-}
328328 step (size, h) = do
@@ -341,7 +341,7 @@ readChunksRequestsOf = Unfold step return
341341-- @since 0.7.0
342342{-# INLINE readChunks #-}
343343readChunks :: MonadIO m => Unfold m Socket (Array Word8)
344−readChunks = UF.supplyFirst readChunksRequestsOf A.defaultChunkSize
344+readChunks = UF.supplyFirst readChunksWithBufferOf A.defaultChunkSize
345345
346346-------------------------------------------------------------------------------
347347-- Read File to Stream
@@ -352,13 +352,13 @@ readChunks = UF.supplyFirst readChunksRequestsOf A.defaultChunkSize
352352-- also control the read throughput in mbps or IOPS.
353353
354354{-
355−-- | @readRequestsOf chunkSize handle@ reads a byte stream from a file
356−-- handle, reads are performed in chunks of up to @chunkSize@. The stream ends
355+-- | @readWithBufferOf bufsize handle@ reads a byte stream from a file
356+-- handle, reads are performed in chunks of up to @bufsize@. The stream ends
357357-- as soon as EOF is encountered.
358358--
359−{-# INLINE readRequestsOf #-}
360−readRequestsOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
361−readRequestsOf chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
359+{-# INLINE readWithBufferOf #-}
360+readWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
361+readWithBufferOf chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
362362-}
363363
364364-- TODO
@@ -373,13 +373,13 @@ readRequestsOf chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
373373toStream :: (IsStream t, MonadIO m) => Socket -> t m Word8
374374toStream = AS.concat . toChunks
375375
376−-- | Unfolds the tuple @(chunksize, socket)@ into a byte stream, read requests
377−-- to the socket are performed using buffers of @chunkSize@.
376+-- | Unfolds the tuple @(bufsize, socket)@ into a byte stream, read requests
377+-- to the socket are performed using buffers of @bufsize@.
378378--
379379-- @since 0.7.0
380−{-# INLINE readRequestsOf #-}
381−readRequestsOf :: MonadIO m => Unfold m (Int, Socket) Word8
382−readRequestsOf = UF.concat readChunksRequestsOf A.read
380+{-# INLINE readWithBufferOf #-}
381+readWithBufferOf :: MonadIO m => Unfold m (Int, Socket) Word8
382+readWithBufferOf = UF.concat readChunksWithBufferOf A.read
383383
384384-- | Unfolds a 'Socket' into a byte stream. IO requests to the socket are
385385-- performed in sizes of
@@ -388,7 +388,7 @@ readRequestsOf = UF.concat readChunksRequestsOf A.read
388388-- @since 0.7.0
389389{-# INLINE read #-}
390390read :: MonadIO m => Unfold m Socket Word8
391−read = UF.supplyFirst readRequestsOf A.defaultChunkSize
391+read = UF.supplyFirst readWithBufferOf A.defaultChunkSize
392392
393393-------------------------------------------------------------------------------
394394-- Writing
@@ -423,19 +423,19 @@ writeChunks h = FL.drainBy (liftIO . writeArray h)
423423-- input elements.
424424--
425425-- @since 0.7.0
426−{-# INLINE writeRequestsOfS #-}
427−writeRequestsOfS :: MonadIO m => Int -> Socket -> SerialT m Word8 -> m ()
428−writeRequestsOfS n h m = writeChunksS h $ AS.arraysOf n m
426+{-# INLINE writeWithBufferOfS #-}
427+writeWithBufferOfS :: MonadIO m => Int -> Socket -> SerialT m Word8 -> m ()
428+writeWithBufferOfS n h m = writeChunksS h $ AS.arraysOf n m
429429
430430-- | Write a byte stream to a socket. Accumulates the input in chunks of
431431-- specified number of bytes before writing.
432432--
433433-- @since 0.7.0
434−{-# INLINE writeRequestsOf #-}
435−writeRequestsOf :: MonadIO m => Int -> Socket -> Fold m Word8 ()
436−writeRequestsOf n h = FL.lchunksOf n (A.writeNUnsafe n) (writeChunks h)
434+{-# INLINE writeWithBufferOf #-}
435+writeWithBufferOf :: MonadIO m => Int -> Socket -> Fold m Word8 ()
436+writeWithBufferOf n h = FL.lchunksOf n (A.writeNUnsafe n) (writeChunks h)
437437
438−-- > write = 'writeRequestsOf' A.defaultChunkSize
438+-- > write = 'writeWithBufferOf' A.defaultChunkSize
439439--
440440-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
441441-- up to 'A.defaultChunkSize' before writing. Note that the write behavior
@@ -444,19 +444,19 @@ writeRequestsOf n h = FL.lchunksOf n (A.writeNUnsafe n) (writeChunks h)
444444-- @since 0.7.0
445445{-# INLINE _writeS #-}
446446_writeS :: MonadIO m => Socket -> SerialT m Word8 -> m ()
447−_writeS = writeRequestsOfS A.defaultChunkSize
447+_writeS = writeWithBufferOfS A.defaultChunkSize
448448
449449-- | Write a byte stream to a socket. Accumulates the input in chunks of
450450-- up to 'A.defaultChunkSize' bytes before writing.
451451--
452452-- @
453−-- write = 'writeRequestsOf' 'A.defaultChunkSize'
453+-- write = 'writeWithBufferOf' 'A.defaultChunkSize'
454454-- @
455455--
456456-- @since 0.7.0
457457{-# INLINE write #-}
458458write :: MonadIO m => Socket -> Fold m Word8 ()
459−write = writeRequestsOf A.defaultChunkSize
459+write = writeWithBufferOf A.defaultChunkSize
460460
461461{-
462462{-# INLINE write #-}
src/Streamly/Network/Socket.hs+3−3
@@ -42,13 +42,13 @@ module Streamly.Network.Socket
4242
4343 -- * Read
4444 , read
45− , readRequestsOf
45+ , readWithBufferOf
4646 , readChunks
47− , readChunksRequestsOf
47+ , readChunksWithBufferOf
4848
4949 -- * Write
5050 , write
51− , writeRequestsOf
51+ , writeWithBufferOf
5252 , writeChunks
5353 )
5454where