| Copyright | (c) Tamar Christina 2018 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | stable |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
GHC.Event.Windows
Description
WinIO Windows event manager.
Synopsis
- data Manager
- getSystemManager :: IO Manager
- interruptSystemManager :: IO ()
- wakeupIOManager :: IO ()
- processRemoteCompletion :: IO ()
- associateHandle :: Manager -> HANDLE -> IO ()
- associateHandle' :: HANDLE -> IO ()
- withOverlapped :: String -> HANDLE -> Word64 -> StartIOCallback Int -> CompletionCallback (IOResult a) -> IO (IOResult a)
- withOverlappedEx :: forall a. Manager -> String -> HANDLE -> Bool -> Word64 -> StartIOCallback Int -> CompletionCallback (IOResult a) -> IO (IOResult a)
- type StartCallback a = LPOVERLAPPED -> IO a
- type StartIOCallback a = StartCallback (CbResult a)
- data CbResult a
- type CompletionCallback a = ErrCode -> DWORD -> IO a
- type LPOVERLAPPED = Ptr OVERLAPPED
- type TimeoutCallback = IO ()
- data TimeoutKey
- type Seconds = Double
- registerTimeout :: Manager -> Int -> TimeoutCallback -> IO TimeoutKey
- updateTimeout :: Manager -> TimeoutKey -> Seconds -> IO ()
- unregisterTimeout :: Manager -> TimeoutKey -> IO ()
- withException :: String -> IO (IOResult a) -> IO a
- ioSuccess :: a -> IO (IOResult a)
- ioFailed :: Integral a => a -> IO (IOResult a)
- ioFailedAny :: Integral a => a -> IO (IOResult b)
- getLastError :: IO ErrCode
- data IOResult a
- data HandleData = HandleData {
- tokenKey :: !HandleKey
- tokenEvents :: !EventLifetime
- _handleCallback :: !EventCallback
- data HandleKey
- registerHandle :: Manager -> EventCallback -> HANDLE -> Event -> Lifetime -> IO HandleKey
- unregisterHandle :: Manager -> HandleKey -> IO ()
- module GHC.Event.Windows.ConsoleEvent
Manager
The state object for the I/O manager. This structure is available for both the threaded and the non-threaded RTS.
interruptSystemManager :: IO () Source #
Interrupts an IO manager Wait. This will force the IO manager to process any outstanding events and timers. Also called when console events such as ctrl+c are used to break abort an I/O request.
wakeupIOManager :: IO () Source #
Wake up a single thread from the I/O Manager's worker queue. This will
unblock a thread blocked in processCompletion and allows the I/O manager to
react accordingly to changes in timers or to process console signals.
No-op if the io-manager is already running.
processRemoteCompletion :: IO () Source #
Entry point for the non-threaded I/O manager to be able to process completed completions. It is mostly a wrapper around processCompletion and invoked by the C thread via the scheduler.
Overlapped I/O
associateHandle :: Manager -> HANDLE -> IO () Source #
Associate a HANDLE with the I/O manager's completion port. This must be
done before using the handle with withOverlapped.
associateHandle' :: HANDLE -> IO () Source #
Associate a HANDLE with the current I/O manager's completion port.
This must be done before using the handle with withOverlapped.
Arguments
| :: String | |
| -> HANDLE | |
| -> Word64 | Value to use for the |
| -> StartIOCallback Int | |
| -> CompletionCallback (IOResult a) | |
| -> IO (IOResult a) |
Arguments
| :: forall a. Manager | |
| -> String | Handle name |
| -> HANDLE | Windows handle associated with the operation. |
| -> Bool | |
| -> Word64 | Value to use for the |
| -> StartIOCallback Int | |
| -> CompletionCallback (IOResult a) | |
| -> IO (IOResult a) |
Start an overlapped I/O operation, and wait for its completion. If
withOverlapped is interrupted by an asynchronous exception, the operation
will be canceled using CancelIoEx.
withOverlapped waits for a completion to arrive before returning or
throwing an exception. This means you can use functions like
alloca to allocate buffers for the operation.
type StartCallback a = LPOVERLAPPED -> IO a Source #
Callback that starts the overlapped I/O operation.
It must return successfully if and only if an I/O completion has been
queued. Otherwise, it must throw an exception, which withOverlapped
will rethrow.
type StartIOCallback a = StartCallback (CbResult a) Source #
Specialized callback type for I/O Completion Ports calls using withOverlapped.
CallBack result type to disambiguate between the different states an I/O Completion call could be in.
Constructors
| CbDone (Maybe DWORD) | Request was handled immediately, no queue. |
| CbPending | Queued and to be handled by I/O manager |
| CbIncomplete | I/O request is incomplete but not enqueued, handle it synchronously. |
| CbError a | I/O request abort, return failure immediately |
| CbNone Bool | The caller did not do any checking, the I/O manager will perform additional checks. |
type CompletionCallback a Source #
Called when the completion is delivered.
type LPOVERLAPPED = Ptr OVERLAPPED Source #
Identifies an I/O operation. Used as the LPOVERLAPPED parameter
for overlapped I/O functions (e.g. ReadFile, WSASend).
Timeouts
type TimeoutCallback = IO () Source #
Warning: since the TimeoutCallback is called from the I/O manager, it must
not throw an exception or block for a long period of time. In particular,
be wary of throwTo and killThread:
if the target thread is making a foreign call, these functions will block
until the call completes.
data TimeoutKey Source #
A timeout registration cookie.
Instances
| Eq TimeoutKey Source # | |
Defined in GHC.Event.TimeOut Methods (==) :: TimeoutKey -> TimeoutKey -> Bool Source # (/=) :: TimeoutKey -> TimeoutKey -> Bool Source # | |
| Ord TimeoutKey Source # | |
Defined in GHC.Event.TimeOut Methods compare :: TimeoutKey -> TimeoutKey -> Ordering Source # (<) :: TimeoutKey -> TimeoutKey -> Bool Source # (<=) :: TimeoutKey -> TimeoutKey -> Bool Source # (>) :: TimeoutKey -> TimeoutKey -> Bool Source # (>=) :: TimeoutKey -> TimeoutKey -> Bool Source # max :: TimeoutKey -> TimeoutKey -> TimeoutKey Source # min :: TimeoutKey -> TimeoutKey -> TimeoutKey Source # | |
registerTimeout :: Manager -> Int -> TimeoutCallback -> IO TimeoutKey Source #
Register an action to be performed in the given number of seconds. The
returned TimeoutKey can be used to later un-register or update the timeout.
The timeout is automatically unregistered when it fires.
The TimeoutCallback will not be called more than once.
Be careful not to exceed maxBound :: Int, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.
updateTimeout :: Manager -> TimeoutKey -> Seconds -> IO () Source #
Update an active timeout to fire in the given number of seconds (from the
time updateTimeout is called), instead of when it was going to fire.
This has no effect if the timeout has already fired.
Be careful not to exceed maxBound :: Int, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.
unregisterTimeout :: Manager -> TimeoutKey -> IO () Source #
Unregister an active timeout. This is a harmless no-op if the timeout is already unregistered or has already fired.
Warning: the timeout callback may fire even after
unregisterTimeout completes.
Utilities
withException :: String -> IO (IOResult a) -> IO a Source #
Process an IOResult and throw an exception back to the user if the action has failed, or return the result.
ioFailed :: Integral a => a -> IO (IOResult a) Source #
Signal that the I/O action has failed with the given reason.
ioFailedAny :: Integral a => a -> IO (IOResult b) Source #
Signal that the I/O action has failed with the given reason. Polymorphic in successful result type.
getLastError :: IO ErrCode Source #
Get the last system error produced in the current thread.
I/O Result type
I/O Event notifications
data HandleData Source #
Constructors
| HandleData | |
Fields
| |
A file handle registration cookie.