Skip to content

Add experimental WinIO support#611

Open
mrkline wants to merge 1 commit intohaskell:masterfrom
mrkline:winio
Open

Add experimental WinIO support#611
mrkline wants to merge 1 commit intohaskell:masterfrom
mrkline:winio

Conversation

@mrkline
Copy link
Copy Markdown

@mrkline mrkline commented Apr 5, 2026

Another attempt at #364, #509, #602 with the following design choices:

  1. On Windows systems, Socket becomes an Either over the existing "Posix" socket implemntation and a Windows equivalent using its SOCKET type.

  2. On Posix systems, or without enabling the WinIO manager with --io-manager=native, the current behavior is unchanged.

  3. With the WinIO manager, a greenfield implementation around the relevant syscalls is used, using IO Completion Ports (AKA "Overlapped IO") through GHC's withOverlapped

For the places we need to mux between the two
(Network.Socket.Syscall, Network.Socket.Buffer, etc.) the existing implementation is moved into a Posix.hsc and the WinIO one is defined in WinIO.hsc.

There's certainly some cleanup and style improvements that could be done, but it passes all existing tests, and hopefully provides a clean separation between the existing code (which can stay unchanged) and direct use of Windows syscalls through withOverlapped.

@mrkline mrkline force-pushed the winio branch 3 times, most recently from 17a28d6 to 84f1b1d Compare April 5, 2026 09:38
Another attempt at haskell#364, haskell#509, haskell#602 with the following design choices:

1. On Windows systems, `Socket` becomes an `Either` over the existing
   "Posix" socket implemntation and a Windows equivalent using its
   `SOCKET` type.

2. On Posix systems, or without enabling the WinIO manager with
   `--io-manager=native`, the current behavior is unchanged.

3. *With* the WinIO manager, a greenfield implementation around the
   relevant syscalls is used, using IO Completion Ports
   (AKA "Overlapped IO") through GHC's `withOverlapped`

For the places we need to mux between the two
(`Network.Socket.Syscall`, `Network.Socket.Buffer`, etc.)
the existing implementation is moved into a `Posix.hsc`
and the WinIO one is defined in `WinIO.hsc`.

There's certainly some cleanup and style improvements that could be
done, but it passes all existing tests, and hopefully provides a clean
separation between the existing code (which can stay unchanged) and
direct use of Windows syscalls through `withOverlapped`.
Comment on lines +90 to +95
-- On Windows with the WinIO (IOCP) I/O manager, GHC's withOverlappedEx
-- converts async exceptions (including the one thrown by timeout) into a
-- synchronous IOException via `throwWinErr ... 0`
-- ("The operation completed successfully").
-- `timeout` does not recognise this IOException as
-- its own exception, so it escapes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably something worth discussing with GHC folks - the WinIO withOverlapped code eats async exceptions and turns them into IOExceptions, which breaks the assumptions of timeout and others I'm sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant