Skip to content

WIP : Basic WinIO support #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
ghc: ['8.0', '8.2', '8.4', '8.6', '8.8', '8.10.4']
# ghc: ['8.0', '8.2', '8.4', '8.6', '8.8', '8.10.4', '9.0.1']
ghc: ['9.0.1']
exclude:
- os: windows-latest
ghc: "8.0"
Expand All @@ -38,6 +39,10 @@ jobs:
ghc: "8.6"
- os: macOS-latest
ghc: "8.8"
- os: macOS-latest
ghc: "9.0.1"
#- os: ubuntu-latest
# ghc: "9.0.1"

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 3.2.0.0

* Basic support for WINIO
[#509](https://github.com/haskell/network/pull/509)

## Version 3.1.2.2

* Allow bytestring 0.11
Expand Down
16 changes: 14 additions & 2 deletions Network/Socket/Fcntl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import qualified System.Posix.Internals

#if !defined(mingw32_HOST_OS)
import Network.Socket.Cbits
#else
# if defined(__IO_MANAGER_WINIO__)
import GHC.IO.SubSystem ((<!>))
# endif
#endif
import Network.Socket.Imports

Expand Down Expand Up @@ -46,12 +50,20 @@ getCloseOnExec fd = do
#endif

-- | Get the nonblocking flag.
-- On Windows, this function always returns 'False'.
-- On Windows, this function always returns 'False' when using MIO but
-- returns `True` when using WinIO. Technically on Windows whether the
-- the socket blocks or not is not determined by the socket itself but
-- by the operations used on the socket. Becuase we will always use
-- overlapping I/O when WinIO is enabled we return `True` here.
--
-- Since 2.7.0.0.
getNonBlock :: CInt -> IO Bool
#if defined(mingw32_HOST_OS)
getNonBlock _ = return False
# if defined(__IO_MANAGER_WINIO__)
getNonBlock _ = return False <!> return True
# else
getNonBlock _ = return False
# endif
#else
getNonBlock fd = do
flags <- c_fcntl_read fd fGetFl 0
Expand Down
1 change: 1 addition & 0 deletions Network/Socket/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Network.Socket.Types
-- cooperate with peer's 'gracefulClose', i.e. proper shutdown
-- sequence with appropriate handshakes specified by the protocol.

-- TODO: WinIO doesn't use fd, add support
socketToHandle :: Socket -> IOMode -> IO Handle
socketToHandle s mode = invalidateSocket s err $ \oldfd -> do
h <- fdToHandle' oldfd (Just GHC.IO.Device.Stream) True (show s) mode True{-bin-}
Expand Down
6 changes: 6 additions & 0 deletions cbits/cmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ WSASendMsg (SOCKET s, LPWSAMSG lpMsg, DWORD flags,
DWORD len;
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSASendMsgGUID, sizeof(WSASendMsgGUID), &ptr_SendMsg,
/* Sadly we can't perform this async for now as C code can't wait for
completion events from the Haskell RTS. This needs to be moved to
Haskell on a re-designed async Network. */
sizeof(ptr_SendMsg), &len, NULL, NULL) != 0)
return -1;
}
Expand All @@ -58,6 +61,9 @@ WSARecvMsg (SOCKET s, LPWSAMSG lpMsg, LPDWORD lpdwNumberOfBytesRecvd,
DWORD len;
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSARecvMsgGUID, sizeof(WSARecvMsgGUID), &ptr_RecvMsg,
/* Sadly we can't perform this async for now as C code can't wait for
completion events from the Haskell RTS. This needs to be moved to
Haskell on a re-designed async Network. */
sizeof(ptr_RecvMsg), &len, NULL, NULL) != 0)
return -1;
}
Expand Down
14 changes: 12 additions & 2 deletions network.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.18
name: network
version: 3.1.2.2
version: 3.2.0.0
license: BSD3
license-file: LICENSE
maintainer: Kazu Yamamoto, Evan Borden
Expand Down Expand Up @@ -124,9 +124,14 @@ library
c-sources: cbits/initWinSock.c, cbits/winSockErr.c, cbits/asyncAccept.c
extra-libraries: ws2_32, iphlpapi, mswsock
-- See https://github.com/haskell/network/pull/362
if impl(ghc >= 7.10)
if impl(ghc >= 7.10 && < 9.0)
cpp-options: -D_WIN32_WINNT=0x0600
cc-options: -D_WIN32_WINNT=0x0600
if impl(ghc >= 9.0)
cpp-options: -D_WIN32_WINNT=0x0601
cc-options: -D_WIN32_WINNT=0x0601
build-depends:
Win32 >= 2.12.0.0

test-suite spec
default-language: Haskell2010
Expand All @@ -141,6 +146,11 @@ test-suite spec
Network.Socket.ByteString.LazySpec
type: exitcode-stdio-1.0
ghc-options: -Wall -threaded

-- On GHC's newer than 9 enable native IO managers
if impl(ghc >= 9.0)
ghc-options: -with-rtsopts=--io-manager=native

-- NB: make sure to versions of hspec and hspec-discover
-- that work together; easiest way is to constraint
-- both packages to a small enough version range.
Expand Down