]> gitweb @ CieloNegro.org - EsounD.git/blob - Sound/EsounD/Internals.hs
987dd1e285262891ba79e69a6e985b0c0e7d0bb0
[EsounD.git] / Sound / EsounD / Internals.hs
1 module Sound.EsounD.Internals
2     ( wrapSocket
3     , closeSocket
4     , withCStrOrNull
5     )
6     where
7
8 import Bindings.EsounD
9 import Foreign.C.String
10 import Foreign.C.Types
11 import Foreign.Ptr
12 import System.IO
13 import System.Posix.IO
14 import System.Posix.Types
15
16 wrapSocket :: String -> CInt → IO Handle
17 wrapSocket e (-1) = fail e
18 wrapSocket _ fd   = fdToHandle (Fd fd)
19
20 closeSocket :: Handle → IO ()
21 closeSocket h = do (Fd fd) ← handleToFd h
22                    _       ← c'esd_close (fromIntegral fd)
23                    return ()
24
25 withCStrOrNull :: Maybe String → (CString → IO a) → IO a
26 withCStrOrNull Nothing  f = f nullPtr
27 withCStrOrNull (Just s) f = withCString s f