X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=EsounD.git;a=blobdiff_plain;f=Sound%2FEsounD%2FInternals.hs;fp=Sound%2FEsounD%2FInternals.hs;h=987dd1e285262891ba79e69a6e985b0c0e7d0bb0;hp=0000000000000000000000000000000000000000;hb=951367c7c17ddbc417a998fe9a19d6434f63f386;hpb=d0f6d543044bf4e29825087afefe6062a95ca926 diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs new file mode 100644 index 0000000..987dd1e --- /dev/null +++ b/Sound/EsounD/Internals.hs @@ -0,0 +1,27 @@ +module Sound.EsounD.Internals + ( wrapSocket + , closeSocket + , withCStrOrNull + ) + where + +import Bindings.EsounD +import Foreign.C.String +import Foreign.C.Types +import Foreign.Ptr +import System.IO +import System.Posix.IO +import System.Posix.Types + +wrapSocket :: String -> CInt → IO Handle +wrapSocket e (-1) = fail e +wrapSocket _ fd = fdToHandle (Fd fd) + +closeSocket :: Handle → IO () +closeSocket h = do (Fd fd) ← handleToFd h + _ ← c'esd_close (fromIntegral fd) + return () + +withCStrOrNull :: Maybe String → (CString → IO a) → IO a +withCStrOrNull Nothing f = f nullPtr +withCStrOrNull (Just s) f = withCString s f