File: SendFile.hs

package info (click to toggle)
haskell-warp 3.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 300 kB
  • ctags: 2
  • sloc: haskell: 2,890; makefile: 8
file content (29 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE CPP #-}

module Network.Wai.Handler.Warp.SendFile where

import Data.ByteString (ByteString)
import Network.Sendfile
import Network.Socket (Socket)
import qualified Network.Wai.Handler.Warp.FdCache as F
import Network.Wai.Handler.Warp.Types

defaultSendFile :: Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO ()
defaultSendFile s path off len act hdr = sendfileWithHeader s path (PartOfFile off len) act hdr


#if SENDFILEFD
setSendFile :: Connection -> Maybe F.MutableFdCache -> Connection
setSendFile conn Nothing    = conn
setSendFile conn (Just fdcs) = case connSendFileOverride conn of
    NotOverride -> conn
    Override s  -> conn { connSendFile = sendFile fdcs s }

sendFile :: F.MutableFdCache -> Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO ()
sendFile fdcs s path off len act hdr = do
    (fd, fresher) <- F.getFd fdcs path
    sendfileFdWithHeader s fd (PartOfFile off len) (act>>fresher) hdr
#else
setSendFile :: Connection -> Maybe F.MutableFdCache -> Connection
setSendFile conn _ = conn
#endif