HandlePair.hs 849 B

123456789101112131415161718192021222324252627282930313233343536
  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. {- |
  13. A pair of handles, the first for input,
  14. and the second for output.
  15. -}
  16. data HandlePair = HandlePair Handle Handle
  17. {- |
  18. > fromHandles inputHandler outputHandler
  19. Creates a uniform io target from a pair of handlers.
  20. -}
  21. fromHandles :: Handle -> Handle -> HandlePair
  22. fromHandles = HandlePair
  23. -- | UniformIO that reads from stdin and writes to stdout.
  24. instance UniformIO HandlePair where
  25. uRead (HandlePair i _) = BS.hGetSome i
  26. uPut (HandlePair _ o) = BS.hPut o
  27. uClose (HandlePair i o) = do
  28. hClose i
  29. hClose o
  30. startTls _ = return
  31. isSecure _ = True