packages feed

signal (empty) → 0.1.0.0

raw patch · 5 files changed

+129/−0 lines, 5 filesdep +basedep +signaldep +unixsetup-changed

Dependencies added: base, signal, unix

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Piotr Mlodawski++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ signal.cabal view
@@ -0,0 +1,34 @@+name:                signal+version:             0.1.0.0+license:             MIT+license-file:        LICENSE+author:              Piotr Mlodawski+maintainer:          remdezx+github@gmail.com+homepage:            http://github.com/pmlodawski/signal+bug-reports:         http://github.com/pmlodawski/signal/issues+category:            System+build-type:          Simple+cabal-version:       >=1.10+synopsis:            Signal handling, multiplatform way+description:+    This simple library allows you to handle os signals on both Linux and Windows.++library+    hs-source-dirs:      src+    default-language:    Haskell2010+    exposed-modules:     System.Signal+    -- other-modules:+    -- other-extensions:+    build-depends:       base >=4.7 && <4.8+    if ! os(windows)+        build-depends:   unix++executable test+    default-language:    Haskell2010+    build-depends:       base >=4.7 && <4.8,+                         signal+    main-is:             test/Main.hs++source-repository head+    type:     git+    location: http://github.com/pmlodawski/signal.git
+ src/System/Signal.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE CPP #-}++module System.Signal where++import Foreign.C.Types (CInt)+import GHC.Conc        (Signal)+#ifdef mingw32_HOST_OS+import Control.Exception.Base (assert)+import Foreign+#else+import           Control.Monad        (void)+import qualified System.Posix.Signals as Posix+#endif+++-- | SIGABRT - Abnormal termination+sigABRT :: Signal+sigABRT = 6++-- | SIGFPE - Floating-point error+sigFPE :: Signal+sigFPE = 8++-- SIGILL - Illegal instruction+sigILL :: Signal+sigILL = 4++-- SIGINT - CTRL+C signal+sigINT :: Signal+sigINT = 2++-- SIGSEGV - Illegal storage access+sigSEGV :: Signal+sigSEGV = 11++-- SIGTERM - Termination request+sigTERM :: Signal+sigTERM = 15++type Handler = Signal -> IO ()++installHandler :: Signal -> Handler -> IO ()+#ifdef mingw32_HOST_OS+foreign import ccall "wrapper"+    genHandler:: Handler -> IO (FunPtr Handler)++foreign import ccall safe "signal.h signal"+    install:: Signal -> FunPtr Handler -> IO Signal++installHandler signal handler = do+    result <- install signal =<< genHandler handler+    return $ assert (result == 0) ()+#else+installHandler signal handler = void $ Posix.installHandler signal (Posix.CatchInfo (handler . Posix.siginfoSignal)) Nothing+#endif
+ test/Main.hs view
@@ -0,0 +1,18 @@+module Main where++import Control.Concurrent+import System.Signal++++main :: IO ()+main = do+    installHandler sigINT (\x -> putStrLn $ "catch " ++ (show x))+    installHandler sigTERM (\x -> putStrLn $ "catch " ++ (show x))+    loop 0++loop :: Int -> IO ()+loop i = do+    print i+    threadDelay 1000000 {- µs -}+    loop (i + 1)