select-0.2.1: Give the select(2) POSIX function a simple STM interface

Safe HaskellSafe-Infered

System.Posix.IO.Select.STM

Description

Treat the POSIX select(2) function as a TMVar CInt.

Synopsis

Documentation

select :: [Fd] -> [Fd] -> [Fd] -> Timeout -> IO (TMVar CInt)Source

This version of select immediately returns and makes the return value of the select(2) call available as a TMVar CInt. See select for argument information.

selectOrTakeTMVar :: [Fd] -> [Fd] -> [Fd] -> Timeout -> TMVar a -> IO (Either CInt a)Source

The parameters are the same as for select, except for the addition of a TMVar. The function returns as soon as either the select(2) has completed, or the TMVar is full.

The return value is either the return value of select(2), or the content of the TMVar. If the TMVar becomes available first, then the select(2) call may hang around forever or until it times out (as specified by the Timeout parameter). If the select(2) returns before the TMVar is available, the TMVar is guaranteed to be left in place.

See also selectOrReadTChan and selectOrElse. Note that selectOrTakeTMVar and the former are special cases of the latter.

(Incidentally, selectOrTakeTMVar is the task I really wanted to accomplish, and solving it just turned into this little library).

selectOrElse :: [Fd] -> [Fd] -> [Fd] -> Timeout -> STM a -> IO (Either CInt a)Source

Analogous to selectOrTakeTMVar, except with a general STM action in place of taking a TMVar.

selectOrElse' :: STM a -> [Fd] -> [Fd] -> [Fd] -> Timeout -> IO (Either a CInt)Source

A version of selectOrElse that prefers the STM operation to select when both are available.

selectOrReadTChan :: [Fd] -> [Fd] -> [Fd] -> Timeout -> TChan a -> IO (Either CInt a)Source

Special case of selectOrElse where the STM action is reading a TChan.

data Timeout Source

A timeout of Never tells select(2) to never time out, while Time s us sets the timeout parameters to s seconds and us microseconds.