on master help sign in
thowing errno for pread. (#499)
commitde13d97b0f3d9be1fd443a5707f2cd5967978ef1 authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 12 Jan 2016, 13:16 (11 years ago) parent6b968d7
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