@@ -17,7 +17,6 @@ import qualified Data.Conduit.List as CL
1717import Data.Conduit.Network (bindPort)
1818import Network (sClose, Socket)
1919import qualified Network.HTTP.Types as H
20−import Network.Sendfile
2120import Network.Socket (accept, SockAddr)
2221import qualified Network.Socket.ByteString as Sock
2322import Network.Wai
@@ -28,6 +27,7 @@ import Network.Wai.Handler.Warp.Response
2827import Network.Wai.Handler.Warp.Settings
2928import qualified Network.Wai.Handler.Warp.Timeout as T
3029import Network.Wai.Handler.Warp.Types
30+import Network.Wai.Handler.Warp.SendFile
3131
3232#if WINDOWS
3333import qualified Control.Concurrent.MVar as MV
@@ -49,23 +49,12 @@ socketConnection s = do
4949 return Connection {
5050 connSendMany = Sock.sendMany s
5151 , connSendAll = Sock.sendAll s
52− , connSendFile = sendFile s
52+ , connSendFile = defaultSendFile s
5353 , connClose = sClose s >> freeRecvBuffer buf
5454 , connRecv = receive s buf bytesPerRead
55+ , connSendFileOverride = Override s
5556 }
5657
57−sendFile :: Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO ()
58−#if SENDFILEFD
59−sendFile s path off len act hdr cleaner = case fdCacher cleaner of
60− Nothing -> sendfileWithHeader s path (PartOfFile off len) act hdr
61− Just fdc -> do
62− (fd, fresher) <- F.getFd fdc path
63− sendfileFdWithHeader s fd (PartOfFile off len) (act>>fresher) hdr
64−#else
65−sendFile s path off len act hdr _ =
66− sendfileWithHeader s path (PartOfFile off len) act hdr
67−#endif
68−
6958#if __GLASGOW_HASKELL__ < 702
7059allowInterrupt :: IO ()
7160allowInterrupt = unblock $ return ()
@@ -178,12 +167,13 @@ runSettingsConnectionMaker set getConnMaker app = do
178167 -- We grab the connection before registering timeouts since the
179168 -- timeouts will be useless during connection creation, due to the
180169 -- fact that async exceptions are still masked.
181− bracket mkConn connClose $ \conn ->
170+ bracket mkConn connClose $ \conn' ->
182171
183172 -- We need to register a timeout handler for this thread, and
184173 -- cancel that handler as soon as we exit.
185174 bracket (T.registerKillThread tm) T.cancel $ \th ->
186175 let cleaner = Cleaner th fc
176+ conn = setSendFile conn' fc
187177 -- We now have fully registered a connection close handler
188178 -- in the case of all exceptions, so it is safe to one
189179 -- again allow async exceptions.