@@ -7,6 +7,10 @@ import qualified System.Posix.Internals
77
88#if !defined(mingw32_HOST_OS)
99import Network.Socket.Cbits
10+ #else
11+ # if defined(__IO_MANAGER_WINIO__)
12+ import GHC.IO.SubSystem ((<!>) )
13+ # endif
1014#endif
1115import Network.Socket.Imports
1216
@@ -15,6 +19,7 @@ import Network.Socket.Imports
1519setNonBlockIfNeeded :: CSocket -> IO ()
1620setNonBlockIfNeeded fd =
1721 System.Posix.Internals. setNonBlockingFD (fromIntegral fd) True
22+
1823-- TODO: remove fromIntegral for WinIO
1924
2025-- | Set the close_on_exec flag on Unix.
@@ -48,13 +53,20 @@ getCloseOnExec fd = do
4853#endif
4954
5055-- | Get the nonblocking flag.
51- -- On Windows, this function always returns 'False'.
56+ -- On Windows, this function always returns 'False' when using MIO but
57+ -- returns `True` when using WinIO. Technically on Windows whether the
58+ -- the socket blocks or not is not determined by the socket itself but
59+ -- by the operations used on the socket. Becuase we will always use
60+ -- overlapping I/O when WinIO is enabled we return `True` here.
5261--
5362-- Since 2.7.0.0.
5463getNonBlock :: CSocket -> IO Bool
5564#if defined(mingw32_HOST_OS)
56- -- | TODO: Query socket for async flag
65+ # if defined(__IO_MANAGER_WINIO__)
66+ getNonBlock _ = return False <!> return True
67+ # else
5768getNonBlock _ = return False
69+ # endif
5870#else
5971getNonBlock fd = do
6072 flags <- c_fcntl_read fd fGetFl 0
0 commit comments