on master help sign in
avoid using c_recv on Windows

Instead, copy how the network package does it on Windows, using readRawBufferPtr. Fixes https://github.com/yesodweb/wai/issues/202

commit63ec4daa07185797b8ca12faa142016648ec656f authorJoey Hess <joey@kitenet.net> dateSun 8 Dec 2013, 16:15 (13 years ago) parent14a1e16
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