packages feed

systemd 1.2.0 → 2.0.0

raw patch · 4 files changed

+24/−57 lines, 4 filesdep ~network

Dependency ranges changed: network

Files

README.md view
@@ -1,4 +1,4 @@-#Haskell implementation for systemd+# Haskell implementation for systemd  Systemd offers some functionnalities to developpers for creating daemons process 
System/Systemd/Daemon.hs view
@@ -72,7 +72,7 @@                              ) where  -import           Control.Applicative+import           Control.Exception         (bracket) import           Control.Monad import           Control.Monad.IO.Class    (liftIO) import           Control.Monad.Trans.Maybe@@ -82,15 +82,16 @@  import           Foreign.C.Error           (Errno (..)) import           Foreign.C.Types           (CInt (..))+import           Foreign.Marshal           (free, mallocBytes) import           Foreign.Ptr import           System.Posix.Env import           System.Posix.Process import           System.Posix.Types        (CPid (..))  import           Data.ByteString.Unsafe    (unsafeUseAsCStringLen)-import           Network.Socket            hiding (recv, recvFrom, send, sendTo)+import           Network.Socket+import           Network.Socket.Address    hiding (recvFrom, sendTo) import           Network.Socket.ByteString-import           Network.Socket.Internal   (withSockAddr)   @@ -248,56 +249,20 @@     return $ zip sockets listenFDNames'    where makeSocket :: CInt -> MaybeT IO Socket-        makeSocket fd = do-          fam  <- socketFamily fd-          typ  <- socketType fd-          stat <- socketStatus fd-          liftIO $ do+        makeSocket fd = liftIO $ do             setNonBlockIfNeeded fd-            mkSocket fd fam typ defaultProtocol stat--socketFamily :: CInt -> MaybeT IO Family-socketFamily fd = do-    familyInt <- liftIO $ c_socket_family fd-    guard $ familyInt >= 0-    return $ unpackFamily familyInt--socketType :: CInt -> MaybeT IO SocketType-socketType fd = do-    typeInt <- liftIO $ c_socket_type fd-    case typeInt of-        0 -> return NoSocketType-        1 -> return Stream-        2 -> return Datagram-        3 -> return Raw-        4 -> return RDM-        5 -> return SeqPacket-        _ -> mzero--socketStatus :: CInt -> MaybeT IO SocketStatus-socketStatus fd = do-    listeningInt <- liftIO $ c_socket_listening fd-    case listeningInt of-      0 -> return Bound-      1 -> return Listening-      _ -> mzero-+            mkSocket fd  sendBufWithFdTo :: Socket -> BC.ByteString -> SockAddr -> Socket -> IO Int sendBufWithFdTo sock state addr sockToSend =   unsafeUseAsCStringLen state $ \(ptr, nbytes) ->-    withSockAddr addr $ \p_addr sz ->-      fromIntegral <$> c_sd_notify_with_fd (fdSocket sock) ptr (fromIntegral nbytes)-                                           p_addr (fromIntegral sz) (fdSocket sockToSend)--foreign import ccall unsafe "socket_family"-  c_socket_family :: CInt -> IO CInt--foreign import ccall unsafe "socket_type"-  c_socket_type :: CInt -> IO CInt--foreign import ccall unsafe "socket_listening"-  c_socket_listening :: CInt -> IO CInt+    bracket addrPointer free $ \p_addr -> do+      fd <- fdSocket sock+      fdToSend <- fdSocket sockToSend+      fromIntegral <$> c_sd_notify_with_fd fd ptr (fromIntegral nbytes)+                                           p_addr (fromIntegral addrSize) fdToSend+  where addrSize = sizeOfSocketAddress addr+        addrPointer = mallocBytes addrSize >>= (\ptr -> pokeSocketAddress ptr addr >> pure ptr)  foreign import ccall unsafe "sd_notify_with_fd"   c_sd_notify_with_fd :: CInt -> Ptr a -> CInt -> Ptr b -> CInt -> CInt -> IO CInt
systemd.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                systemd-version:             1.2.0+version:             2.0.0 synopsis:            Systemd facilities (Socket activation, Notify) description:         A module for Systemd facilities. homepage:            https://github.com/erebe/systemd@@ -15,7 +15,7 @@ build-type:          Simple extra-source-files:  README.md stability:           stable-cabal-version:       >=1.10+cabal-version:       >=2.0 source-repository head     type: git     location: https://github.com/erebe/systemd@@ -27,7 +27,7 @@   build-depends:       base == 4.* ,                        unix >= 2.5,                        transformers >= 0.3,-                       network >= 2.6.3.2,+                       network ^>=3.1.0.0,                        bytestring >= 0.10    default-language:    Haskell2010@@ -37,7 +37,7 @@    type:                exitcode-stdio-1.0    main-is:             Main.hs    build-depends:       base == 4.*,-                        network >= 2.6.3.2,+                        network ^>=3.1.0.0,                         unix >= 2.5,                         systemd    default-language:    Haskell2010
test/Main.hs view
@@ -2,15 +2,15 @@ import System.Systemd.Daemon import Control.Monad import Control.Concurrent-import Network +import Network.Socket import System.IO import Data.Char import System.Posix.Env as Ev   apF :: Show w => w -> IO ()-apF = appendFile "/home/erebe/log" . (++ "\n") . show+apF = appendFile "/tmp/log" . (++ "\n") . show  test :: IO () test = do@@ -24,8 +24,10 @@   apF "totot"    threadDelay $ 1000000 * 20-  s <- listenOn (PortNumber 1213)-  s' <- listenOn (PortNumber 1214)+  s <- socket AF_INET Stream defaultProtocol+  s' <- socket AF_INET Stream defaultProtocol+  listen s 1213+  listen s' 1214    x <- storeFd s   apF x