module System.IO.Uniform.Std (
StdIO(StdIO)
) where
import System.IO.Uniform
import System.IO.Uniform.External
import Foreign
import Foreign.C.Error
import qualified Data.ByteString as BS
instance UniformIO StdIO where
uRead _ n = do
allocaArray n (
\b -> do
count <- c_recvStd b (fromIntegral n)
if count < 0
then throwErrno "could not read"
else BS.packCStringLen (b, fromIntegral count)
)
uPut _ t = do
BS.useAsCStringLen t (
\(str, n) -> do
count <- c_sendStd str $ fromIntegral n
if count < 0
then throwErrno "could not write"
else return ()
)
uClose _ = return ()
startTls _ a = return a
isSecure _ = True