sockets-0.4.0.0: High-level network sockets

Safe HaskellNone
LanguageHaskell2010

Socket.EventManager

Contents

Synopsis

Manager

manager :: Manager Source #

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.

reader :: Manager -> Fd -> IO (TVar Token) Source #

writer :: Manager -> Fd -> IO (TVar Token) Source #

Transactional Variables

unready Source #

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.

wait :: TVar Token -> IO Token Source #

Wait until the token indicates readiness. Keep in mind that false positives are possible. When a false positive happens, use unready and then wait again. Keep doing this until the file descriptor is actually ready for reads/writes.

unreadyAndWait Source #

Arguments

:: Token

Token provided by previous call to wait

-> TVar Token

Transactional variable for readiness

-> IO Token

New token

persistentUnreadyAndWait Source #

Arguments

:: Token

Token provided by previous call to wait

-> TVar Token

Transactional variable for readiness

-> IO Token

New token

persistentUnready Source #

Arguments

:: Token

Token provided by previous call to wait

-> TVar Token

Transactional variable for readiness

-> IO () 

interruptibleWait Source #

Arguments

:: TVar Bool

Interrupt

-> TVar Token 
-> IO Token