@@ -1,7 +1,7 @@
11{-# LANGUAGE CPP, ForeignFunctionInterface #-}
22
33module Network.Wai.Handler.Warp.SendFile (
4− defaultSendFile
4+ sendFile
55 , readSendFile
66 , packHeader -- for testing
77 ) where
@@ -32,9 +32,12 @@ import System.Posix.Types
3232
3333----------------------------------------------------------------
3434
35−defaultSendFile :: Socket -> Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
35+-- | Function to send a file based on sendfiel() for Linux\/Mac\/FreeBSD.
36+-- This makes use of the file descriptor cache.
37+-- For other OSes, this is identical to 'readSendFile'.
38+sendFile :: Socket -> Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
3639#ifdef SENDFILEFD
37−defaultSendFile s _ _ _ fid off len act hdr = case mfid of
40+sendFile s _ _ _ fid off len act hdr = case mfid of
3841 -- settingsFdCacheDuration is 0
3942 Nothing -> sendfileWithHeader s path (PartOfFile off len) act hdr
4043 Just fd -> sendfileFdWithHeader s fd (PartOfFile off len) act hdr
@@ -42,7 +45,7 @@ defaultSendFile s _ _ _ fid off len act hdr = case mfid of
4245 mfid = fileIdFd fid
4346 path = fileIdPath fid
4447#else
45−defaultSendFile _ = readSendFile
48+sendFile _ = readSendFile
4649#endif
4750
4851----------------------------------------------------------------
@@ -74,6 +77,9 @@ mini i n
7477 | fromIntegral i < n = i
7578 | otherwise = fromIntegral n
7679
80+-- | Function to send a file based on pread()\/send() for Unix.
81+-- This makes use of the file descriptor cache.
82+-- For Windows, this is emulated by 'Handle'.
7783#ifdef WINDOWS
7884readSendFile :: Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
7985readSendFile buf siz send fid off0 len0 hook headers = do