select-0.4: example/FdSetExample.hs
module Main where
import Prelude hiding (elem)
import System.Posix.IO
import System.Posix.IO.Select.FdSet.Unsafe
import System.Posix.IO.Select.Types
flags :: OpenFileFlags
flags = OpenFileFlags { append = False, exclusive = False, noctty = False, nonBlock = True, trunc = False }
main :: IO ()
main = openFd "fifo" ReadOnly Nothing flags >>= \fd ->
openFd "fifo2" ReadOnly Nothing flags >>= \fd2 ->
openFd "fifo3" ReadOnly Nothing flags >>= \fd3 ->
openFd "fifo4" ReadOnly Nothing flags >>= \fd4 ->
putStrLn "Making" >>
let
set = fromList [fd, fd3]
set2 = insert fd4 set
set3 = fromList [fd, fd3]
set4 = remove fd4 (remove fd3 (remove fd2 (remove fd set3)))
in
print (fd `elem` set) >>
print (fd2 `elem` set) >>
print (fd3 `elem` set) >>
print (fd4 `elem` set) >>
print [fd, fd3] >>
print (unsafeToList set) >>
print (fd `elem` set2) >>
print (fd2 `elem` set2) >>
print (fd3 `elem` set2) >>
print (fd4 `elem` set2) >>
print (fd `elem` set3) >>
print (fd2 `elem` set3) >>
print (fd3 `elem` set3) >>
print (fd4 `elem` set3) >>
print (fd `elem` set4) >>
print (fd2 `elem` set4) >>
print (fd3 `elem` set4) >>
print (fd4 `elem` set4)