-- | Treat the POSIX @select(2)@ function as an 'MVar' 'CInt'.

module System.Posix.IO.Select.MVar (select, Timeout(Never, Time)) where

import System.Posix.IO.Select.Types
import qualified System.Posix.IO.Select as S
import Foreign.C.Types
import Control.Concurrent.MVar
import qualified Control.Concurrent.MVarIO as MIO
import System.Posix.Types

-- | This version of 'S.select' immediately returns and makes the
-- return value of the @select(2)@ call available as an 'MVar'
-- 'CInt'. See 'S.select' for argument information.
select :: [Fd] -> [Fd] -> [Fd] -> Timeout -> IO (MVar CInt)
select readFds writeFds exceptFds timeout = MIO.run (S.select readFds writeFds exceptFds timeout)