packages feed

select 0.2 → 0.2.1

raw patch · 5 files changed

+27/−8 lines, 5 files

Files

example/Example.hs view
@@ -27,12 +27,16 @@     openFd "fifo3" ReadOnly Nothing flags >>= \fd3 ->      openFd "fifo4" ReadOnly Nothing flags >>= \fd4 ->      putStrLn "The file was opened, so let the waiting game begin!" >>-    --selectOrReadTChan [fd,fd2,fd3,fd4] [] [] (Time 15 0) c >>= \ret ->-    selectOrTakeTMVar [fd,fd2,fd3,fd4] [] [] (Time 15 0) t >>= \ret ->+    -- selectOrTakeTMVar [fd,fd2,fd3,fd4] [] [] (Time 15 0) t >>= \ret ->+    --     case ret of+    --       Left 0 -> putStrLn "select() timed out on the files."+    --       Left x -> putStrLn "There's data in one of the files!"+    --       Right s -> putStrLn $ "Oh no, the interruptor is here: " ++ s+    selectOrElse' (readTChan c) [fd,fd2,fd3,fd4] [] [] (Time 15 0) >>= \ret ->         case ret of-          Left 0 -> putStrLn "select() timed out on the files."-          Left x -> putStrLn "There's data in one of the files!"-          Right s -> putStrLn $ "Oh no, the interruptor is here: " ++ s+          Right 0 -> putStrLn "select() timed out on the files."+          Right x -> putStrLn "There's data in one of the files!"+          Left s -> putStrLn $ "Oh no, the interruptor is here: " ++ s     interruptor :: TMVar String -> IO () interruptor t = threadDelay (10 * 1000000) >>
select.cabal view
@@ -1,5 +1,5 @@ Name:                select-Version:             0.2+Version:             0.2.1 Synopsis:            Give the select(2) POSIX function a simple STM interface Homepage:            http://nonempty.org/software/haskell-select License:             BSD3
src/Control/Concurrent/STM/RunOrElse.hs view
@@ -1,4 +1,4 @@-module Control.Concurrent.STM.RunOrElse(runOrElse, runOrTakeTMVar) where+module Control.Concurrent.STM.RunOrElse(runOrElse, runOrElse', runOrTakeTMVar) where  import Control.Applicative import Control.Concurrent.STM@@ -16,6 +16,12 @@ runOrElse :: IO a -> STM b -> IO (Either a b) runOrElse action stm = run action >>= \tm ->                        atomically ((Left <$> takeTMVar tm) `orElse` (Right <$> stm))++-- | A version of 'runOrElse' that prefers the STM operation to the IO+-- action.+runOrElse' :: STM a -> IO b -> IO (Either a b)+runOrElse' stm action = run action >>= \tm ->+                        atomically ((Left <$> stm) `orElse` (Right <$> takeTMVar tm))  -- | This version of 'Control.Concurrent.STM.TMVarIO.run' takes an -- additional 'TMVar', and returns its content /or/ the result of the
src/System/Posix/IO/Select/STM.hs view
@@ -1,6 +1,6 @@ -- | Treat the POSIX @select(2)@ function as a 'TMVar' 'CInt'. -module System.Posix.IO.Select.STM (select, selectOrTakeTMVar, selectOrElse, selectOrReadTChan, Timeout(Never, Time)) where+module System.Posix.IO.Select.STM (select, selectOrTakeTMVar, selectOrElse, selectOrElse', selectOrReadTChan, Timeout(Never, Time)) where  import System.Posix.IO.Select.Types import qualified System.Posix.IO.Select as S@@ -39,6 +39,11 @@ -- action in place of taking a 'TMVar'. selectOrElse :: [Fd] -> [Fd] -> [Fd] -> Timeout -> STM a -> IO (Either CInt a) selectOrElse readFds writeFds exceptFds timeout stm = ROE.runOrElse (S.select readFds writeFds exceptFds timeout) stm++-- | A version of 'selectOrElse' that prefers the STM operation to+-- 'select' when both are available.+selectOrElse' :: STM a -> [Fd] -> [Fd] -> [Fd] -> Timeout -> IO (Either a CInt)+selectOrElse' stm readFds writeFds exceptFds timeout = ROE.runOrElse' stm (S.select readFds writeFds exceptFds timeout)  -- | Special case of 'selectOrElse' where the STM action is reading a -- 'TChan'.
src/System/Posix/IO/Select/select_wrapper.c view
@@ -3,6 +3,8 @@ #include <sys/select.h> #ifndef NDEBUG #include <stdio.h>+#include <errno.h>+#include <string.h> #endif  #include "select_wrapper.h"@@ -63,6 +65,8 @@    #ifndef NDEBUG   printf("select_wrapper.c: Returning %d.\n", ret);+  if (ret == -1)+    printf("select_wrapper.c: Error code %d: %s\n", errno, strerror(errno));   #endif    return ret;