| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hmssql.Connection.Backend.WinIO
Description
Shared Memory and Named Pipes through GHC's native I/O manager (WinIO):
each operation on a pipe is an overlapped ReadFile, WriteFile or
ConnectNamedPipe made with GHC.Event.Windows.withOverlapped, on a
handle associated with the manager's completion port. It is used when
nativeIO holds, with or without -threaded, and then TCP goes through
network's own calls; otherwise the pipes go through
Hmssql.Connection.Backend.Windows, whose foreign calls and errors this
module shares. On other platforms this module is empty.
The manager does what that module does by hand. An asynchronous
exception interrupts a pending operation, which the manager then cancels
with CancelIoEx and waits for, uninterruptibly, so the buffer is never
freed while the kernel may still write to it. A completion is processed
by the manager's thread, or without -threaded by the scheduler, so no
operation needs an event, a helper thread or a worker of its own, and a
pipe opened without -threaded needs no asyncDoProc.
Closing is as on the other path: a flag that later operations check,
then CancelIoEx on the whole handle, then a wait for the operations in
progress. An operation that becomes pending checks the flag once more,
in its start callback, and cancels itself if the flag is set by then, so
a close that comes between an operation's first check and its start is
not lost. pioStopReceiving only sets the flag: the manager allocates
each operation's OVERLAPPED, so there is no address to cancel the
receive alone by, and hmssql kills the reader thread right after it,
which cancels the receive inside the manager.