X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=EsounD.git;a=blobdiff_plain;f=Sound%2FEsounD%2FInternals.hs;h=f4b067f0903cf30fc9a23b62ccb13dee41c5e4fe;hp=fcaff1e5e88d84d5c887bf0a45e3d34f93b1e865;hb=808cc2f4700bc0b2f77cee443dd237d415b4d5d7;hpb=4570a37d1fc8f21a4ee1221c6ed289d281f1b005 diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs index fcaff1e..f4b067f 100644 --- a/Sound/EsounD/Internals.hs +++ b/Sound/EsounD/Internals.hs @@ -13,18 +13,22 @@ module Sound.EsounD.Internals , interleave , deinterleave + , toLSV , wrapSocket , closeSocket , withCStrOrNull + , failOnError ) where import Bindings.EsounD import Data.Int +import Data.StorableVector as S import Data.StorableVector.Lazy as L import Foreign.C.String import Foreign.C.Types import Foreign.Ptr import Foreign.Storable +import Prelude.Unicode import System.IO import System.Posix.IO import System.Posix.Types @@ -79,6 +83,9 @@ deinterleave v (L.cons lFr l', L.cons rFr r') -- Utility functions +toLSV ∷ Storable α ⇒ S.Vector α → L.Vector α +toLSV v = L.fromChunks [v] + wrapSocket ∷ String → CInt → IO Handle wrapSocket e (-1) = fail e wrapSocket _ fd = fdToHandle (Fd fd) @@ -91,3 +98,8 @@ closeSocket h = do (Fd fd) ← handleToFd h withCStrOrNull ∷ Maybe String → (CString → IO a) → IO a withCStrOrNull Nothing f = f nullPtr withCStrOrNull (Just s) f = withCString s f + +failOnError ∷ Monad m ⇒ String → CInt → m () +failOnError msg rv + | rv ≤ 0 = fail msg + | otherwise = return ()