on master help sign in
Hide writev, fix fdready for ghc-8.2 and lower
fb8e1d7Harendra Kumar
src/Streamly/FileSystem/FD.hs+9−5
@@ -96,8 +96,10 @@ module Streamly.FileSystem.FD
96 -- , writeArray
96 -- , writeArray
97 , writeArrays
97 , writeArrays
98 , writeArraysPackedUpto
98 , writeArraysPackedUpto
99+
100+ -- XXX these are incomplete
99− , writev
101+ -- , writev
100− , writevArraysPackedUpto
102+ -- , writevArraysPackedUpto
101
103
102 -- -- * Random Access (Seek)
104 -- -- * Random Access (Seek)
103 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
105 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -342,6 +344,7 @@ read = A.flattenArrays . readArrays
342writeArrays :: (MonadIO m, Storable a) => Handle -> SerialT m (Array a) -> m ()
344writeArrays :: (MonadIO m, Storable a) => Handle -> SerialT m (Array a) -> m ()
343writeArrays h m = S.mapM_ (liftIO . writeArray h) m
345writeArrays h m = S.mapM_ (liftIO . writeArray h) m
344
346
347+-- XXX this is incomplete
345-- | Write a stream of 'IOVec' arrays to a handle.
348-- | Write a stream of 'IOVec' arrays to a handle.
346--
349--
347-- @since 0.7.0
350-- @since 0.7.0
@@ -360,16 +363,17 @@ writeArraysPackedUpto :: (MonadIO m, Storable a)
360 => Int -> Handle -> SerialT m (Array a) -> m ()
363 => Int -> Handle -> SerialT m (Array a) -> m ()
361writeArraysPackedUpto n h xs = writeArrays h $ A.packArraysChunksOf n xs
364writeArraysPackedUpto n h xs = writeArrays h $ A.packArraysChunksOf n xs
362
365
366+-- XXX this is incomplete
363-- | Write a stream of arrays to a handle after grouping them in 'IOVec' arrays
367-- | Write a stream of arrays to a handle after grouping them in 'IOVec' arrays
364-- of up to a maximum total size. Writes are performed using gather IO via
368-- of up to a maximum total size. Writes are performed using gather IO via
365-- @writev@ system call. The maximum number of entries in each 'IOVec' group
369-- @writev@ system call. The maximum number of entries in each 'IOVec' group
366-- limited to 512.
370-- limited to 512.
367--
371--
368-- @since 0.7.0
372-- @since 0.7.0
369−{-# INLINE writevArraysPackedUpto #-}
373+{-# INLINE _writevArraysPackedUpto #-}
370−writevArraysPackedUpto :: MonadIO m
374+_writevArraysPackedUpto :: MonadIO m
371 => Int -> Handle -> SerialT m (Array a) -> m ()
375 => Int -> Handle -> SerialT m (Array a) -> m ()
372−writevArraysPackedUpto n h xs =
376+_writevArraysPackedUpto n h xs =
373 writev h $ fromStreamD $ groupIOVecsOf n 512 (toStreamD xs)
377 writev h $ fromStreamD $ groupIOVecsOf n 512 (toStreamD xs)
374
378
375-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
379-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
src/Streamly/FileSystem/FDIO.hs+11−2
@@ -33,7 +33,10 @@ import Control.Monad (when)
33import Data.Int (Int64)
33import Data.Int (Int64)
34import Data.Word (Word8)
34import Data.Word (Word8)
35import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
35import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
36−import Foreign.C.Types (CSize(..), CInt(..), CBool(..))
36+import Foreign.C.Types (CSize(..), CInt(..))
37+#if __GLASGOW_HASKELL__ >= 802
38+import Foreign.C.Types (CBool(..))
39+#endif
37import Foreign.Ptr (plusPtr, Ptr)
40import Foreign.Ptr (plusPtr, Ptr)
38import System.Posix.Internals (c_write, c_safe_write)
41import System.Posix.Internals (c_write, c_safe_write)
39
42
@@ -60,8 +63,13 @@ isNonBlocking fd = fdIsNonBlocking fd /= 0
60
63
61-- "poll"s the fd for data to become available or timeout
64-- "poll"s the fd for data to become available or timeout
62-- See cbits/inputReady.c in base package
65-- See cbits/inputReady.c in base package
66+#if __GLASGOW_HASKELL__ >= 804
63foreign import ccall unsafe "fdReady"
67foreign import ccall unsafe "fdReady"
64− unsafe_fdReady :: CInt -> CBool -> Int64 -> CBool -> IO CInt
68+ unsafe_fdReady :: CInt -> CBool -> Int64 -> CBool -> IO CInt
69+#else
70+foreign import ccall safe "fdReady"
71+ unsafe_fdReady :: CInt -> CInt -> CInt -> CInt -> IO CInt
72+#endif
65
73
66writeNonBlocking :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO CInt
74writeNonBlocking :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO CInt
67writeNonBlocking loc !fd !buf !off !len
75writeNonBlocking loc !fd !buf !off !len
@@ -183,6 +191,7 @@ writeAll fd ptr bytes = do
183writev :: FD -> Ptr IOVec -> Int -> IO CInt
191writev :: FD -> Ptr IOVec -> Int -> IO CInt
184writev = writevNonBlocking "Streamly.FileSystem.FDIO"
192writev = writevNonBlocking "Streamly.FileSystem.FDIO"
185
193
194+-- XXX incomplete
186-- | Keep writing an iovec in a loop until all the iovec entries are written.
195-- | Keep writing an iovec in a loop until all the iovec entries are written.
187writevAll :: FD -> Ptr IOVec -> Int -> IO ()
196writevAll :: FD -> Ptr IOVec -> Int -> IO ()
188writevAll fd iovec count = do
197writevAll fd iovec count = do
streamly.cabal+9−9
@@ -261,7 +261,7 @@ library
261
261
262 build-depends: base >= 4.8 && < 5
262 build-depends: base >= 4.8 && < 5
263 , ghc-prim >= 0.2 && < 0.6
263 , ghc-prim >= 0.2 && < 0.6
264− , deepseq >= 1.4.2 && < 1.5
264+ , deepseq >= 1.4.1 && < 1.5
265 , containers >= 0.5 && < 0.7
265 , containers >= 0.5 && < 0.7
266 , heaps >= 0.3 && < 0.4
266 , heaps >= 0.3 && < 0.4
267
267
@@ -533,7 +533,7 @@ benchmark linear
533 build-depends:
533 build-depends:
534 streamly
534 streamly
535 , base >= 4.8 && < 5
535 , base >= 4.8 && < 5
536− , deepseq >= 1.4.2 && < 1.5
536+ , deepseq >= 1.4.1 && < 1.5
537 , random >= 1.0 && < 2.0
537 , random >= 1.0 && < 2.0
538 , gauge >= 0.2.4 && < 0.3
538 , gauge >= 0.2.4 && < 0.3
539 if impl(ghc < 8.0)
539 if impl(ghc < 8.0)
@@ -568,7 +568,7 @@ benchmark linear-async
568 build-depends:
568 build-depends:
569 streamly
569 streamly
570 , base >= 4.8 && < 5
570 , base >= 4.8 && < 5
571− , deepseq >= 1.4.2 && < 1.5
571+ , deepseq >= 1.4.1 && < 1.5
572 , random >= 1.0 && < 2.0
572 , random >= 1.0 && < 2.0
573 , gauge >= 0.2.4 && < 0.3
573 , gauge >= 0.2.4 && < 0.3
574 if impl(ghc < 8.0)
574 if impl(ghc < 8.0)
@@ -602,7 +602,7 @@ benchmark linear-rate
602 build-depends:
602 build-depends:
603 streamly
603 streamly
604 , base >= 4.8 && < 5
604 , base >= 4.8 && < 5
605− , deepseq >= 1.4.2 && < 1.5
605+ , deepseq >= 1.4.1 && < 1.5
606 , random >= 1.0 && < 2.0
606 , random >= 1.0 && < 2.0
607 , gauge >= 0.2.4 && < 0.3
607 , gauge >= 0.2.4 && < 0.3
608 if impl(ghc < 8.0)
608 if impl(ghc < 8.0)
@@ -637,7 +637,7 @@ benchmark nested
637 build-depends:
637 build-depends:
638 streamly
638 streamly
639 , base >= 4.8 && < 5
639 , base >= 4.8 && < 5
640− , deepseq >= 1.4.2 && < 1.5
640+ , deepseq >= 1.4.1 && < 1.5
641 , random >= 1.0 && < 2.0
641 , random >= 1.0 && < 2.0
642 , gauge >= 0.2.4 && < 0.3
642 , gauge >= 0.2.4 && < 0.3
643 if impl(ghc < 8.0)
643 if impl(ghc < 8.0)
@@ -672,7 +672,7 @@ benchmark array
672 build-depends:
672 build-depends:
673 streamly
673 streamly
674 , base >= 4.8 && < 5
674 , base >= 4.8 && < 5
675− , deepseq >= 1.4.2 && < 1.5
675+ , deepseq >= 1.4.1 && < 1.5
676 , random >= 1.0 && < 2.0
676 , random >= 1.0 && < 2.0
677 , gauge >= 0.2.4 && < 0.3
677 , gauge >= 0.2.4 && < 0.3
678 if impl(ghc < 8.0)
678 if impl(ghc < 8.0)
@@ -708,7 +708,7 @@ benchmark fileio
708 , base >= 4.8 && < 5
708 , base >= 4.8 && < 5
709 , gauge >= 0.2.4 && < 0.3
709 , gauge >= 0.2.4 && < 0.3
710 , typed-process >= 0.2.3 && < 0.3
710 , typed-process >= 0.2.3 && < 0.3
711− , deepseq >= 1.4.2 && < 1.5
711+ , deepseq >= 1.4.1 && < 1.5
712
712
713-------------------------------------------------------------------------------
713-------------------------------------------------------------------------------
714-- Internal benchmarks for unexposed modules
714-- Internal benchmarks for unexposed modules
@@ -765,7 +765,7 @@ benchmark base
765 buildable: True
765 buildable: True
766 build-depends:
766 build-depends:
767 base >= 4.8 && < 5
767 base >= 4.8 && < 5
768− , deepseq >= 1.4.2 && < 1.5
768+ , deepseq >= 1.4.1 && < 1.5
769 , random >= 1.0 && < 2.0
769 , random >= 1.0 && < 2.0
770 , gauge >= 0.2.4 && < 0.3
770 , gauge >= 0.2.4 && < 0.3
771
771
@@ -820,7 +820,7 @@ executable nano-bench
820 , gauge >= 0.2.4 && < 0.3
820 , gauge >= 0.2.4 && < 0.3
821 , ghc-prim >= 0.2 && < 0.6
821 , ghc-prim >= 0.2 && < 0.6
822 , containers >= 0.5 && < 0.7
822 , containers >= 0.5 && < 0.7
823− , deepseq >= 1.4.2 && < 1.5
823+ , deepseq >= 1.4.1 && < 1.5
824 , heaps >= 0.3 && < 0.4
824 , heaps >= 0.3 && < 0.4
825 , random >= 1.0 && < 2.0
825 , random >= 1.0 && < 2.0
826
826