module SendFile.Internal (
sendFile,
sendFileMode
) where
import Data.ByteString.Char8
import Prelude hiding (readFile)
import System.IO (Handle(..), hFlush)
import Foreign.C
import GHC.IOBase (haFD)
import GHC.Handle (withHandle_)
sendFileMode :: String
sendFileMode = "LINUX_SENDFILE"
sendFile :: Handle -> FilePath -> IO ()
sendFile outh infp = do
hFlush outh
withHandle_ "sendFile" outh $ \outh' -> do
withCString infp $ \in_fp -> do
let out_fd = haFD outh'
err <- c_sendfile_linux out_fd in_fp
if err == 0
then return ()
else fail ("errno " ++ show err)
foreign import ccall
c_sendfile_linux :: CInt -> CString -> IO Int