on master help sign in
Merge pull request #204 from joeyh/master

avoid using c_recv on Windows

commit3b1a4186f5c0793e8e51b67185464fd03ff1f6a5 authorKazu Yamamoto <kazu@iij.ad.jp> dateSun 8 Dec 2013, 12:40 (13 years ago) parent14a1e1663ec4da
1 file changed+13−2
warp/Network/Wai/Handler/Warp/Recv.hs+13−2
warp/Network/Wai/Handler/Warp/Recv.hs+13−2
@@ -1,6 +1,5 @@
11{-# LANGUAGE ForeignFunctionInterface #-}
2−
3−-- fixme: windows support
2+{-# LANGUAGE CPP #-}
43
54module Network.Wai.Handler.Warp.Recv (
65 receive
@@ -20,6 +19,10 @@ import Network.Socket (Socket, fdSocket)
2019import System.Posix.Types (Fd(..))
2120import Network.Wai.Handler.Warp.Buffer
2221
22+#ifdef mingw32_HOST_OS
23+import GHC.IO.FD (FD(..), readRawBufferPtr)
24+#endif
25+
2326----------------------------------------------------------------
2427
2528receive :: Socket -> Buffer -> Int -> IO ByteString
@@ -37,9 +40,17 @@ receive sock buf size = do
3740 buf' = castPtr buf
3841 size' = fromIntegral size
3942
43+#ifdef mingw32_HOST_OS
44+receiveloop :: CInt -> Ptr Word8 -> CSize -> IO CInt
45+#else
4046receiveloop :: CInt -> Ptr CChar -> CSize -> IO CInt
47+#endif
4148receiveloop sock buf size = do
49+#ifdef mingw32_HOST_OS
50+ bytes <- fmap fromIntegral $ readRawBufferPtr "recv" (FD sock 1) buf 0 size
51+#else
4252 bytes <- c_recv sock buf size 0
53+#endif
4354 if bytes == -1 then do
4455 errno <- getErrno
4556 if errno == eAGAIN then do