]> gitweb @ CieloNegro.org - EsounD.git/blobdiff - Sound/EsounD/Internals.hs
Sound.EsounD.Internals
[EsounD.git] / Sound / EsounD / Internals.hs
diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs
new file mode 100644 (file)
index 0000000..987dd1e
--- /dev/null
@@ -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