simple-sendfile 0.2.31 → 0.2.32
raw patch · 3 files changed
+38/−39 lines, 3 filesdep +easy-filedep ~network
Dependencies added: easy-file
Dependency ranges changed: network
Files
- Network/Sendfile/Linux.hsc +3/−12
- simple-sendfile.cabal +8/−8
- test/SendfileSpec.hs +27/−19
Network/Sendfile/Linux.hsc view
@@ -1,6 +1,8 @@ {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE CPP #-} +#define _FILE_OFFSET_BITS 64+ module Network.Sendfile.Linux ( sendfile , sendfile'@@ -34,9 +36,6 @@ #include <sys/sendfile.h> #include <sys/socket.h> -isLargeOffset :: Bool-isLargeOffset = sizeOf (0 :: COff) == 8- isLargeSize :: Bool isLargeSize = sizeOf (0 :: CSize) == 8 @@ -142,15 +141,7 @@ -- Dst Src in order. take care foreign import ccall unsafe "sendfile"- c_sendfile32 :: Fd -> Fd -> Ptr COff -> CSize -> IO CSsize--foreign import ccall unsafe "sendfile64"- c_sendfile64 :: Fd -> Fd -> Ptr COff -> CSize -> IO CSsize--c_sendfile :: Fd -> Fd -> Ptr COff -> CSize -> IO CSsize-c_sendfile- | isLargeOffset = c_sendfile64- | otherwise = c_sendfile32+ c_sendfile :: Fd -> Fd -> Ptr COff -> CSize -> IO CSsize ----------------------------------------------------------------
simple-sendfile.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: simple-sendfile-version: 0.2.31+version: 0.2.32 license: BSD3 license-file: LICENSE maintainer: Kazu Yamamoto <kazu@iij.ad.jp>@@ -17,13 +17,13 @@ source-repository head type: git- location: git://github.com/kazu-yamamoto/simple-sendfile+ location: https://github.com/kazu-yamamoto/simple-sendfile flag allow-bsd description: Allow use of BSD sendfile (disable on GNU/kFreeBSD) flag fallback- description: Use counduit instead of sendfile()+ description: Use conduit instead of sendfile() default: False library@@ -33,7 +33,7 @@ ghc-options: -Wall build-depends: base >=4.8 && <5,- network,+ network >=3.1.4, bytestring if (os(freebsd) && flag(allow-bsd) && !flag(fallback))@@ -77,15 +77,15 @@ default-language: Haskell2010 ghc-options: -Wall build-depends:- base, HUnit,+ base, bytestring, conduit, conduit-extra,- resourcet, directory,+ easy-file >= 0.2.4, hspec >=1.3, network, process,- simple-sendfile,- unix+ resourcet,+ simple-sendfile
test/SendfileSpec.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} @@ -8,6 +9,7 @@ import Control.Monad import Control.Monad.Trans.Resource (MonadResource, runResourceT) import Data.ByteString.Char8 as BS+import qualified Data.ByteString.Lazy as BL import Data.Conduit import Data.Conduit.Binary as CB import Data.Conduit.List as CL@@ -16,11 +18,9 @@ import Network.Sendfile import Network.Socket import System.Directory-import System.Exit import System.IO-import System.Posix.Files-import System.Process import System.Timeout+import System.EasyFile import Test.Hspec ----------------------------------------------------------------@@ -29,28 +29,34 @@ spec = do describe "sendfile" $ do it "sends an entire file" $ do- sendFile EntireFile `shouldReturn` ExitSuccess+ sendFile EntireFile `shouldReturn` True it "sends a part of file" $ do- sendFile (PartOfFile 2000 1000000) `shouldReturn` ExitSuccess+ sendFile (PartOfFile 2000 1000000) `shouldReturn` True it "terminates even if length is over" $ do shouldTerminate $ sendIllegal (PartOfFile 2000 5000000) it "terminates even if offset is over" $ do shouldTerminate $ sendIllegal (PartOfFile 5000000 6000000)+ -- On Windows, setFileSize throws an exception due to the+ -- access permission. The test case will be finished but it is+ -- not a right test. it "terminates even if the file is truncated" $ do shouldTerminate truncateFile describe "sendfileWithHeader" $ do it "sends an header and an entire file" $ do- sendFileH EntireFile `shouldReturn` ExitSuccess+ sendFileH EntireFile `shouldReturn` True it "sends an header and a part of file" $ do- sendFileH (PartOfFile 2000 1000000) `shouldReturn` ExitSuccess+ sendFileH (PartOfFile 2000 1000000) `shouldReturn` True it "sends a large header and an entire file" $ do- sendFileHLarge EntireFile `shouldReturn` ExitSuccess+ sendFileHLarge EntireFile `shouldReturn` True it "sends a large header and a part of file" $ do- sendFileHLarge (PartOfFile 2000 1000000) `shouldReturn` ExitSuccess+ sendFileHLarge (PartOfFile 2000 1000000) `shouldReturn` True it "terminates even if length is over" $ do shouldTerminate $ sendIllegalH (PartOfFile 2000 5000000) it "terminates even if offset is over" $ do shouldTerminate $ sendIllegalH (PartOfFile 5000000 6000000)+ -- On Windows, setFileSize throws an exception due to the+ -- access permission. The test case will be finished but it is+ -- not a right test. it "terminates even if the file is truncated" $ do shouldTerminate truncateFileH where@@ -59,10 +65,10 @@ ---------------------------------------------------------------- -sendFile :: FileRange -> IO ExitCode+sendFile :: FileRange -> IO Bool sendFile range = sendFileCore range [] -sendFileH :: FileRange -> IO ExitCode+sendFileH :: FileRange -> IO Bool sendFileH range = sendFileCore range headers where headers = [@@ -74,7 +80,7 @@ , "\n" ] -sendFileHLarge :: FileRange -> IO ExitCode+sendFileHLarge :: FileRange -> IO Bool sendFileHLarge range = sendFileCore range headers where headers = [@@ -86,7 +92,7 @@ , "\n" ] -sendFileCore :: FileRange -> [ByteString] -> IO ExitCode+sendFileCore :: FileRange -> [ByteString] -> IO Bool sendFileCore range headers = bracket setup teardown $ \(s2,_) -> do #if MIN_VERSION_conduit(1,3,0) runResourceT $ runConduit (sourceSocket s2 .| sinkFile outputFile)@@ -94,7 +100,9 @@ runResourceT $ sourceSocket s2 $$ sinkFile outputFile #endif runResourceT $ copyfile range- system $ "cmp -s " ++ outputFile ++ " " ++ expectedFile+ !f1 <- BL.readFile outputFile+ !f2 <- BL.readFile expectedFile+ return $! (f1 == f2) where copyfile EntireFile = do -- of course, we can use <> here@@ -133,8 +141,8 @@ killThread tid removeFileIfExists outputFile removeFileIfExists expectedFile- inputFile = "test/inputFile"- outputFile = "test/outputFile"+ inputFile = "test/inputFile"+ outputFile = "test/outputFile" expectedFile = "test/expectedFile" ----------------------------------------------------------------@@ -176,7 +184,7 @@ close s2 killThread tid removeFileIfExists outputFile- inputFile = "test/inputFile"+ inputFile = "test/inputFile" outputFile = "test/outputFile" ----------------------------------------------------------------@@ -229,8 +237,8 @@ killThread tid removeFileIfExists tempFile removeFileIfExists outputFile- inputFile = "test/inputFile"- tempFile = "test/tempFile"+ inputFile = "test/inputFile"+ tempFile = "test/tempFile" outputFile = "test/outputFile" range = EntireFile