diff options
author | Alina Banerjee <alina@glitchgirl.us> | 2021-07-19 03:59:12 +0000 |
---|---|---|
committer | Alina Banerjee <alina@glitchgirl.us> | 2021-07-19 22:38:29 +0000 |
commit | c708b969bafb403d482565601f8d0ed963e54a3c (patch) | |
tree | 81ea1c9f198a34af8807b2765311d54293b4648b /utils/benchmarks/events/EventUtil.hs | |
parent | de9fedc380d22ff6db3e4c7540af07b99d26fbd9 (diff) | |
download | haskell-wip/fix-8045.tar.gz |
Move event benchmarks to utils/benchmarks/events/wip/fix-8045
Diffstat (limited to 'utils/benchmarks/events/EventUtil.hs')
-rw-r--r-- | utils/benchmarks/events/EventUtil.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/utils/benchmarks/events/EventUtil.hs b/utils/benchmarks/events/EventUtil.hs new file mode 100644 index 0000000000..0fbdb9280a --- /dev/null +++ b/utils/benchmarks/events/EventUtil.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE CPP #-} + +module EventUtil + ( + setNonBlocking + , throwErrnoIfMinus1Retry_mayBlock + , throwErrnoIfMinus1Retry_repeatOnBlock + ) where + +import Foreign.C.Error (eINTR, eWOULDBLOCK, eAGAIN, getErrno, throwErrno) +import Foreign.C.Types (CInt) +import Prelude hiding (repeat) +import System.Posix.Internals (setNonBlockingFD) +import System.Posix.Types (Fd) + +{-# SPECIALISE + throwErrnoIfMinus1Retry_mayBlock + :: String -> IO CInt -> IO CInt -> IO CInt #-} +throwErrnoIfMinus1Retry_mayBlock :: (Eq a, Num a) => String -> + IO a -> IO a -> IO a +throwErrnoIfMinus1Retry_mayBlock name on_block act = do + res <- act + if res == -1 + then do + err <- getErrno + if err == eINTR + then throwErrnoIfMinus1Retry_mayBlock name on_block act + else if err == eWOULDBLOCK || err == eAGAIN + then on_block + else throwErrno name + else return res + +throwErrnoIfMinus1Retry_repeatOnBlock :: (Eq a, Num a) => String -> + IO b -> IO a -> IO a +throwErrnoIfMinus1Retry_repeatOnBlock name on_block act = + throwErrnoIfMinus1Retry_mayBlock name (on_block >> repeat) act + where repeat = throwErrnoIfMinus1Retry_repeatOnBlock name on_block act + +setNonBlocking :: Fd -> IO () +setNonBlocking fd = +#if __GLASGOW_HASKELL__ > 611 + setNonBlockingFD (fromIntegral fd) True +#else + setNonBlockingFD (fromIntegral fd) +#endif |