0 | module System.UV.Pipe
 1 |
 2 | import Data.Buffer.Indexed
 3 |
 4 | import IO.Async.Event
 5 | import System.UV.File
 6 | import System.UV.Loop
 7 | import System.UV.Pointer
 8 | import System.UV.Stream
 9 | import System.UV.Raw.Stream
10 | import System.UV.Util
11 | import System.UV.Raw.Handle
12 | import System.UV.Raw.Pipe
13 |
14 | %default total
15 |
16 | export %inline
17 | (cc : CloseCB) => Resource (Ptr Pipe) where
18 |   release h = uv_close h cc
19 |
20 | parameters {auto l : UVLoop}
21 |            {auto has : Has UVError es}
22 |
23 |   export
24 |   mkPipe : Bool -> Async es (Ptr Pipe)
25 |   mkPipe b = mallocPtr Pipe >>= uvAct (\x => uv_pipe_init l.loop x b)
26 |
27 |   export
28 |   pipeOpen : File -> Async es (Ptr Pipe)
29 |   pipeOpen f = do
30 |     pp <- mkPipe False
31 |     uv $ uv_pipe_open pp f.file
32 |     pure pp
33 |
34 |   export %inline
35 |   stdinOpen : Async es (Ptr Pipe)
36 |   stdinOpen = pipeOpen stdin
37 |
38 |   export
39 |   streamStdin :
40 |        AllocCB
41 |     -> (Buffer (ReadRes ByteString) -> Async es a)
42 |     -> Async es a
43 |   streamStdin ac run = use1 stdinOpen $ \h => read ac h run
44 |