HandlePair.hs 774 B

1234567891011121314151617181920212223242526272829303132
  1. {- |
  2. IO into a pair of Haskell handles, like the ones
  3. created with stdin and stdout of a forked process.
  4. -}
  5. module System.IO.Uniform.HandlePair (
  6. HandlePair,
  7. fromHandles
  8. ) where
  9. import System.IO (Handle, hClose)
  10. import System.IO.Uniform
  11. import qualified Data.ByteString as BS
  12. data HandlePair = HandlePair Handle Handle
  13. {- |
  14. > fromHandles inputHandler outputHandler
  15. Creates a uniform io target from a pair of handlers.
  16. -}
  17. fromHandles :: Handle -> Handle -> HandlePair
  18. fromHandles = HandlePair
  19. -- | UniformIO that reads from stdin and writes to stdout.
  20. instance UniformIO HandlePair where
  21. uRead (HandlePair i _) = BS.hGetSome i
  22. uPut (HandlePair _ o) = BS.hPut o
  23. uClose (HandlePair i o) = do
  24. hClose i
  25. hClose o
  26. startTls _ = return
  27. isSecure _ = True