on master help sign in
Merge branch 'master' of github.com:yesodweb/wai
commit2451e664dc565920ecd7e493bf2b5d8ca15d116e authorMichael Snoyman <michael@snoyman.com> dateTue 12 Jan 2016, 13:22 (11 years ago) parenta46f52ade13d97
1 file changed+6−4
warp/Network/Wai/Handler/Warp/SendFile.hs+6−4
warp/Network/Wai/Handler/Warp/SendFile.hs+6−4
@@ -9,7 +9,7 @@ module Network.Wai.Handler.Warp.SendFile (
99#endif
1010 ) where
1111
12−import Control.Monad (void)
12+import Control.Monad (void, when)
1313import Data.ByteString (ByteString)
1414import qualified Data.ByteString as BS
1515import Network.Socket (Socket)
@@ -17,7 +17,6 @@ import Network.Wai.Handler.Warp.Buffer
1717import Network.Wai.Handler.Warp.Types
1818
1919#ifdef WINDOWS
20−import Control.Monad (when)
2120import Data.ByteString.Internal (ByteString(..))
2221import Foreign.ForeignPtr (newForeignPtr_)
2322import Foreign.Ptr (plusPtr)
@@ -27,6 +26,7 @@ import qualified System.IO as IO
2726import Control.Applicative ((<$>))
2827# endif
2928import Control.Exception
29+import Foreign.C.Error (throwErrno)
3030import Foreign.C.Types
3131import Foreign.Ptr (Ptr, castPtr, plusPtr)
3232import Network.Sendfile
@@ -143,8 +143,10 @@ readSendFile buf siz send fid off0 len0 hook headers =
143143 loop fd (len - n') (off + n')
144144
145145positionRead :: Fd -> Buffer -> BufSize -> Integer -> IO Int
146−positionRead fd buf siz off =
147− fromIntegral <$> c_pread fd (castPtr buf) (fromIntegral siz) (fromIntegral off)
146+positionRead fd buf siz off = do
147+ bytes <- fromIntegral <$> c_pread fd (castPtr buf) (fromIntegral siz) (fromIntegral off)
148+ when (bytes < 0) $ throwErrno "positionRead"
149+ return bytes
148150
149151foreign import ccall unsafe "pread"
150152 c_pread :: Fd -> Ptr CChar -> ByteCount -> FileOffset -> IO CSsize