on master help sign in
Disable windows raw fd IO code
commit6688d0e4c991ebc6d1fe94c767376d4a4ae73886 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 16 Jun 2019, 21:01 (7 years ago) parent909d218
4 files changed+60−17
src/Streamly/FileSystem/FD.hs+18−10 src/Streamly/FileSystem/FDIO.hs+29−6 src/Streamly/FileSystem/IOVec.hsc+6−1 src/Streamly/Mem/Array/Types.hs+7
src/Streamly/FileSystem/FD.hs+18−10
@@ -139,10 +139,14 @@ import qualified Streamly.FileSystem.FDIO as RawIO
139139
140140import Streamly.Mem.Array.Types (Array(..))
141141import Streamly.Streams.Serial (SerialT)
142+import Streamly.Streams.StreamK.Type (IsStream, mkStream)
143+import Streamly.Mem.Array.Types (byteLength, defaultChunkSize)
144+
145+#if !defined(mingw32_HOST_OS)
146+import Streamly.Mem.Array.Types (groupIOVecsOf)
142147import Streamly.Streams.StreamD (toStreamD)
143148import Streamly.Streams.StreamD.Type (fromStreamD)
144−import Streamly.Streams.StreamK.Type (IsStream, mkStream)
145−import Streamly.Mem.Array.Types (byteLength, defaultChunkSize, groupIOVecsOf)
149+#endif
146150-- import Streamly.Fold (Fold)
147151-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
148152
@@ -249,6 +253,7 @@ writeArray (Handle fd) arr = withForeignPtr (aStart arr) $ \p -> do
249253 where
250254 aLen = byteLength arr
251255
256+#if !defined(mingw32_HOST_OS)
252257-- | Write an array of 'IOVec' to a file handle.
253258--
254259-- @since 0.7.0
@@ -258,6 +263,7 @@ writeIOVec _ iov | A.length iov == 0 = return ()
258263writeIOVec (Handle fd) iov =
259264 withForeignPtr (aStart iov) $ \p ->
260265 RawIO.writevAll fd p (A.length iov)
266+#endif
261267
262268-------------------------------------------------------------------------------
263269-- Stream of Arrays IO
@@ -344,14 +350,6 @@ read = A.flattenArrays . readArrays
344350writeArrays :: (MonadIO m, Storable a) => Handle -> SerialT m (Array a) -> m ()
345351writeArrays h m = S.mapM_ (liftIO . writeArray h) m
346352
347−-- XXX this is incomplete
348−-- | Write a stream of 'IOVec' arrays to a handle.
349−--
350−-- @since 0.7.0
351−{-# INLINE writev #-}
352−writev :: MonadIO m => Handle -> SerialT m (Array RawIO.IOVec) -> m ()
353−writev h m = S.mapM_ (liftIO . writeIOVec h) m
354−
355353-- | Write a stream of arrays to a handle after coalescing them in chunks of
356354-- specified size. The chunk size is only a maximum and the actual writes could
357355-- be smaller than that as we do not split the arrays to fit them to the
@@ -363,6 +361,15 @@ writeArraysPackedUpto :: (MonadIO m, Storable a)
363361 => Int -> Handle -> SerialT m (Array a) -> m ()
364362writeArraysPackedUpto n h xs = writeArrays h $ A.packArraysChunksOf n xs
365363
364+#if !defined(mingw32_HOST_OS)
365+-- XXX this is incomplete
366+-- | Write a stream of 'IOVec' arrays to a handle.
367+--
368+-- @since 0.7.0
369+{-# INLINE writev #-}
370+writev :: MonadIO m => Handle -> SerialT m (Array RawIO.IOVec) -> m ()
371+writev h m = S.mapM_ (liftIO . writeIOVec h) m
372+
366373-- XXX this is incomplete
367374-- | Write a stream of arrays to a handle after grouping them in 'IOVec' arrays
368375-- of up to a maximum total size. Writes are performed using gather IO via
@@ -375,6 +382,7 @@ _writevArraysPackedUpto :: MonadIO m
375382 => Int -> Handle -> SerialT m (Array a) -> m ()
376383_writevArraysPackedUpto n h xs =
377384 writev h $ fromStreamD $ groupIOVecsOf n 512 (toStreamD xs)
385+#endif
378386
379387-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
380388--
src/Streamly/FileSystem/FDIO.hs+29−6
@@ -28,21 +28,25 @@ module Streamly.FileSystem.FDIO
2828 )
2929where
3030
31+#if !defined(mingw32_HOST_OS)
3132import Control.Concurrent (threadWaitWrite)
3233import Control.Monad (when)
3334import Data.Int (Int64)
34−import Data.Word (Word8)
3535import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
36−import Foreign.C.Types (CSize(..), CInt(..))
3736#if __GLASGOW_HASKELL__ >= 802
3837import Foreign.C.Types (CBool(..))
3938#endif
40−import Foreign.Ptr (plusPtr, Ptr)
4139import System.Posix.Internals (c_write, c_safe_write)
40+import Streamly.FileSystem.IOVec (c_writev, c_safe_writev)
41+#endif
42+
43+import Foreign.C.Types (CSize(..), CInt(..))
44+import Data.Word (Word8)
45+import Foreign.Ptr (plusPtr, Ptr)
4246
4347import GHC.IO.FD (FD(..))
4448
45−import Streamly.FileSystem.IOVec (IOVec(..), c_writev, c_safe_writev)
49+import Streamly.FileSystem.IOVec (IOVec(..))
4650
4751-------------------------------------------------------------------------------
4852-- IO Routines
@@ -54,13 +58,13 @@ import Streamly.FileSystem.IOVec (IOVec(..), c_writev, c_safe_writev)
5458-- Write without blocking the underlying OS thread
5559-------------------------------------------------------------------------------
5660
61+#if !defined(mingw32_HOST_OS)
62+
5763foreign import ccall unsafe "rtsSupportsBoundThreads" threaded :: Bool
5864
5965isNonBlocking :: FD -> Bool
6066isNonBlocking fd = fdIsNonBlocking fd /= 0
6167
62−#if !defined(mingw32_HOST_OS)
63−
6468-- "poll"s the fd for data to become available or timeout
6569-- See cbits/inputReady.c in base package
6670#if __GLASGOW_HASKELL__ >= 804
@@ -110,6 +114,25 @@ writevNonBlocking loc !fd !iov !cnt
110114 safe_write = do_write (c_safe_writev (fdFD fd) iov (fromIntegral cnt))
111115
112116#else
117+writeNonBlocking :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO CInt
118+writeNonBlocking = undefined
119+
120+writevNonBlocking :: String -> FD -> Ptr IOVec -> Int -> IO CInt
121+writevNonBlocking = undefined
122+#endif
123+
124+-- Windows code is disabled for now
125+#if 0
126+
127+#if defined(mingw32_HOST_OS)
128+# if defined(i386_HOST_ARCH)
129+# define WINDOWS_CCONV stdcall
130+# elif defined(x86_64_HOST_ARCH)
131+# define WINDOWS_CCONV ccall
132+# else
133+# error Unknown mingw32 arch
134+# endif
135+#endif
113136
114137foreign import WINDOWS_CCONV safe "recv"
115138 c_safe_recv :: CInt -> Ptr Word8 -> CInt -> CInt{-flags-} -> IO CInt
src/Streamly/FileSystem/IOVec.hsc+6−1
@@ -25,8 +25,10 @@ where
2525import Data.Word (Word8, Word64)
2626import Foreign.C.Types (CInt(..))
2727import Foreign.Ptr (Ptr)
28−import Foreign.Storable (Storable(..))
2928import System.Posix.Types (CSsize(..))
29+#if !defined(mingw32_HOST_OS)
30+import Foreign.Storable (Storable(..))
31+#endif
3032
3133-------------------------------------------------------------------------------
3234-- IOVec
@@ -65,6 +67,9 @@ foreign import capi safe "sys/uio.h writev"
6567 c_safe_writev :: CInt -> Ptr IOVec -> CInt -> IO CSsize
6668
6769#else
70+c_writev :: CInt -> Ptr IOVec -> CInt -> IO CSsize
6871c_writev = error "writev not implemented for windows"
72+
73+c_safe_writev :: CInt -> Ptr IOVec -> CInt -> IO CSsize
6974c_safe_writev = error "writev not implemented for windows"
7075#endif
src/Streamly/Mem/Array/Types.hs+7
@@ -39,7 +39,9 @@ module Streamly.Mem.Array.Types
3939 , flattenArrays
4040 , flattenArraysRev
4141 , packArraysChunksOf
42+#if !defined(mingw32_HOST_OS)
4243 , groupIOVecsOf
44+#endif
4345 , splitOn
4446
4547 -- * Elimination
@@ -97,7 +99,10 @@ import GHC.Ptr (Ptr(..))
9799
98100import Streamly.Fold.Types (Fold(..))
99101import Streamly.SVar (adaptState)
102+
103+#if !defined(mingw32_HOST_OS)
100104import Streamly.FileSystem.FDIO (IOVec(..))
105+#endif
101106
102107import qualified Streamly.Streams.StreamD.Type as D
103108import qualified Streamly.Streams.StreamK as K
@@ -923,6 +928,7 @@ packArraysChunksOf n (D.Stream step state) =
923928
924929 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
925930
931+#if !defined(mingw32_HOST_OS)
926932data GatherState s arr
927933 = GatherInitial s
928934 | GatherBuffering s arr Int
@@ -990,6 +996,7 @@ groupIOVecsOf n maxIOVLen (D.Stream step state) =
990996 step' _ GatherFinish = return D.Stop
991997
992998 step' _ (GatherYielding iov next) = return $ D.Yield iov next
999+#endif
9931000
9941001-- | Create two slices of an array without copying the original array. The
9951002-- specified index @i@ is the first index of the second slice.