on master help sign in
Rename readChunk/writeChunk to getChunk/putChunk
2ea9fb0Harendra Kumar
src/Streamly/Internal/Network/Socket.hs+14−14
@@ -25,7 +25,7 @@ module Streamly.Internal.Network.Socket
25 , connectFrom
25 , connectFrom
26
26
27 -- * Read from connection
27 -- * Read from connection
28− , readChunk
28+ , getChunk
29
29
30 -- ** Streams
30 -- ** Streams
31 , read
31 , read
@@ -40,7 +40,7 @@ module Streamly.Internal.Network.Socket
40 , chunkReaderWith
40 , chunkReaderWith
41
41
42 -- * Write to connection
42 -- * Write to connection
43− , writeChunk
43+ , putChunk
44
44
45 -- ** Folds
45 -- ** Folds
46 , write
46 , write
@@ -278,10 +278,10 @@ readArrayUptoWith f size h = do
278-- becomes available. If data is available then it immediately returns that
278-- becomes available. If data is available then it immediately returns that
279-- data without blocking.
279-- data without blocking.
280--
280--
281−-- @since 0.8.0
281+-- @since 0.9.0
282−{-# INLINABLE readChunk #-}
282+{-# INLINABLE getChunk #-}
283−readChunk :: Int -> Socket -> IO (Array Word8)
283+getChunk :: Int -> Socket -> IO (Array Word8)
284−readChunk = readArrayUptoWith recvBuf
284+getChunk = readArrayUptoWith recvBuf
285
285
286-------------------------------------------------------------------------------
286-------------------------------------------------------------------------------
287-- Array IO (output)
287-- Array IO (output)
@@ -321,10 +321,10 @@ writeArrayWith f h arr = A.asPtrUnsafe arr $ \ptr -> f h (castPtr ptr) aLen
321
321
322-- | Write an Array to a file handle.
322-- | Write an Array to a file handle.
323--
323--
324−-- @since 0.8.0
324+-- @since 0.9.0
325−{-# INLINABLE writeChunk #-}
325+{-# INLINABLE putChunk #-}
326−writeChunk :: Unboxed a => Socket -> Array a -> IO ()
326+putChunk :: Unboxed a => Socket -> Array a -> IO ()
327−writeChunk = writeArrayWith sendAll
327+putChunk = writeArrayWith sendAll
328
328
329-------------------------------------------------------------------------------
329-------------------------------------------------------------------------------
330-- Stream of Arrays IO
330-- Stream of Arrays IO
@@ -354,7 +354,7 @@ readChunksWith size h = S.fromStreamD (D.Stream step ())
354 where
354 where
355 {-# INLINE_LATE step #-}
355 {-# INLINE_LATE step #-}
356 step _ _ = do
356 step _ _ = do
357− arr <- liftIO $ readChunk size h
357+ arr <- liftIO $ getChunk size h
358 return $
358 return $
359 case A.length arr of
359 case A.length arr of
360 0 -> D.Stop
360 0 -> D.Stop
@@ -382,7 +382,7 @@ chunkReaderWith = Unfold step return
382 where
382 where
383 {-# INLINE_LATE step #-}
383 {-# INLINE_LATE step #-}
384 step (size, h) = do
384 step (size, h) = do
385− arr <- liftIO $ readChunk size h
385+ arr <- liftIO $ getChunk size h
386 return $
386 return $
387 case A.length arr of
387 case A.length arr of
388 0 -> D.Stop
388 0 -> D.Stop
@@ -462,7 +462,7 @@ reader = UF.first defaultChunkSize readerWith
462{-# INLINE putChunks #-}
462{-# INLINE putChunks #-}
463putChunks :: (MonadIO m, Unboxed a)
463putChunks :: (MonadIO m, Unboxed a)
464 => Socket -> Stream m (Array a) -> m ()
464 => Socket -> Stream m (Array a) -> m ()
465−putChunks h = S.fold (FL.drainBy (liftIO . writeChunk h))
465+putChunks h = S.fold (FL.drainBy (liftIO . putChunk h))
466
466
467-- | Write a stream of arrays to a socket. Each array in the stream is written
467-- | Write a stream of arrays to a socket. Each array in the stream is written
468-- to the socket as a separate IO request.
468-- to the socket as a separate IO request.
@@ -470,7 +470,7 @@ putChunks h = S.fold (FL.drainBy (liftIO . writeChunk h))
470-- @since 0.7.0
470-- @since 0.7.0
471{-# INLINE writeChunks #-}
471{-# INLINE writeChunks #-}
472writeChunks :: (MonadIO m, Unboxed a) => Socket -> Fold m (Array a) ()
472writeChunks :: (MonadIO m, Unboxed a) => Socket -> Fold m (Array a) ()
473−writeChunks h = FL.drainBy (liftIO . writeChunk h)
473+writeChunks h = FL.drainBy (liftIO . putChunk h)
474
474
475-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
475-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
476-- @socket@ after coalescing the adjacent arrays in chunks of @bufsize@.
476-- @socket@ after coalescing the adjacent arrays in chunks of @bufsize@.
src/Streamly/Network/Socket.hs+15−2
@@ -101,7 +101,7 @@ module Streamly.Network.Socket
101
101
102 -- * Reads
102 -- * Reads
103 -- ** Singleton
103 -- ** Singleton
104− , readChunk
104+ , getChunk
105
105
106 -- ** Unfolds
106 -- ** Unfolds
107 , reader
107 , reader
@@ -111,7 +111,7 @@ module Streamly.Network.Socket
111
111
112 -- * Writes
112 -- * Writes
113 -- ** Singleton
113 -- ** Singleton
114− , writeChunk
114+ , putChunk
115
115
116 -- ** Folds
116 -- ** Folds
117 , write
117 , write
@@ -124,6 +124,8 @@ module Streamly.Network.Socket
124
124
125 -- * Deprecated
125 -- * Deprecated
126 , accept
126 , accept
127+ , readChunk
128+ , writeChunk
127 , read
129 , read
128 , readWithBufferOf
130 , readWithBufferOf
129 , readChunks
131 , readChunks
@@ -138,6 +140,7 @@ import Data.Word (Word8)
138import Network.Socket (Socket, SockAddr)
140import Network.Socket (Socket, SockAddr)
139import Streamly.Internal.Data.Unfold.Type (Unfold(..))
141import Streamly.Internal.Data.Unfold.Type (Unfold(..))
140import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
142import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
143+import Streamly.Internal.Data.Unboxed (Unbox)
141
144
142import Streamly.Internal.Network.Socket hiding (accept, read, readChunks)
145import Streamly.Internal.Network.Socket hiding (accept, read, readChunks)
143import Prelude hiding (read)
146import Prelude hiding (read)
@@ -147,6 +150,16 @@ import Prelude hiding (read)
147accept :: MonadIO m => Unfold m (Int, SockSpec, SockAddr) Socket
150accept :: MonadIO m => Unfold m (Int, SockSpec, SockAddr) Socket
148accept = acceptor
151accept = acceptor
149
152
153+{-# DEPRECATED readChunk "Please use 'getChunk' instead" #-}
154+{-# INLINABLE readChunk #-}
155+readChunk :: Int -> Socket -> IO (Array Word8)
156+readChunk = getChunk
157+
158+{-# DEPRECATED writeChunk "Please use 'putChunk' instead" #-}
159+{-# INLINABLE writeChunk #-}
160+writeChunk :: Unbox a => Socket -> Array a -> IO ()
161+writeChunk = putChunk
162+
150{-# DEPRECATED read "Please use 'reader' instead" #-}
163{-# DEPRECATED read "Please use 'reader' instead" #-}
151{-# INLINE read #-}
164{-# INLINE read #-}
152read :: MonadIO m => Unfold m Socket Word8
165read :: MonadIO m => Unfold m Socket Word8