| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Socket.EventManager
Synopsis
- manager :: Manager
- register :: Manager -> Fd -> IO ()
- reader :: Manager -> Fd -> IO (TVar Token)
- writer :: Manager -> Fd -> IO (TVar Token)
- data Token
- unready :: Token -> TVar Token -> IO ()
- wait :: TVar Token -> IO Token
- unreadyAndWait :: Token -> TVar Token -> IO Token
- persistentUnreadyAndWait :: Token -> TVar Token -> IO Token
- persistentUnready :: Token -> TVar Token -> IO ()
- interruptibleWait :: TVar Bool -> TVar Token -> IO Token
- interruptibleWaitCounting :: TVar Int -> TVar Bool -> TVar Token -> IO Token
- isInterrupt :: Token -> Bool
Manager
Registration
register :: Manager -> Fd -> IO () Source #
Register interest in reads and writes. After registering a socket,
use reader and writer to get access to the transactional variables
that describe the readiness of their corresponding channels. When
possible, register a file descriptor before doing whatever thing
may cause it to become ready. This is currently not important for
correctness (since the read and write channel optimistically start
out as ready). However, future optimizations may introduce
registration functions that let users specify if the channels
should start as ready or not ready.
Precondition: There is no existing registration for this file descriptor.
Transactional Variables
Arguments
| :: Token | Token provided by previous call to wait |
| -> TVar Token | Transactional variable for readiness |
| -> IO () |
Why does unready need the previous token value. At first glance,
it seems that it would suffice to simply set something to false
and be done with it. However, this runs into a subtle race condition.
What if an epoll_wait worker thread discovered that the file
descriptor was ready for reads right before unready was called?
We take the old token value so that we can check to see if anything
has changed since we last checked in. If that's the case, this
function aborts, leaving whatever the most recent call to
epoll_wait had done in tact.
isInterrupt :: Token -> Bool Source #