1234567891011121314151617181920212223242526272829303132 |
- 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
- -- | UniformIO that reads from stdin and writes to stdout.
- 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
|