0 | module System.UV.Raw.Pipe
 1 |
 2 | import System.UV.Raw.Callback
 3 | import System.UV.Raw.Handle
 4 | import System.UV.Raw.Loop
 5 | import System.UV.Raw.Pointer
 6 | import System.UV.Raw.Req
 7 | import System.UV.Raw.Util
 8 |
 9 | %default total
10 |
11 | --------------------------------------------------------------------------------
12 | -- FFI
13 | --------------------------------------------------------------------------------
14 |
15 | %foreign (idris_uv "uv_pipe_init")
16 | prim__uv_pipe_init : Ptr Loop -> Ptr Pipe -> (ipc : Int32) -> PrimIO Int32
17 |
18 | %foreign (idris_uv "uv_pipe_open")
19 | prim__uv_pipe_open : Ptr Pipe -> (file : Int32) -> PrimIO Int32
20 |
21 | %foreign (idris_uv "uv_pipe_bind")
22 | prim__uv_pipe_bind : Ptr Pipe -> String -> PrimIO Int32
23 |
24 | %foreign (idris_uv "uv_pipe_connect")
25 | prim__uv_pipe_connect : Ptr Connect -> Ptr Pipe -> String -> AnyPtr -> PrimIO ()
26 |
27 | %foreign (idris_uv "uv_pipe_getsockname")
28 | prim__uv_pipe_getsockname : Ptr Pipe -> Ptr Char -> Ptr Bits32 -> PrimIO Int32
29 |
30 | %foreign (idris_uv "uv_pipe_getpeername")
31 | prim__uv_pipe_getpeername : Ptr Pipe -> Ptr Char -> Ptr Bits32 -> PrimIO Int32
32 |
33 | --------------------------------------------------------------------------------
34 | -- API
35 | --------------------------------------------------------------------------------
36 |
37 | parameters {auto has : HasIO io}
38 |
39 |   ||| Initialize a pipe handle. The ipc argument is a boolean to indicate
40 |   ||| if this pipe will be used for handle passing between processes
41 |   ||| (which may change the bytes on the wire). Only a connected pipe that will
42 |   ||| be passing the handles should have this flag set, not the listening
43 |   ||| pipe that uv_accept is called on.
44 |   export %inline
45 |   uv_pipe_init : Ptr Loop -> Ptr Pipe -> (ipc : Bool) -> io Int32
46 |   uv_pipe_init l p ipc = primIO $ prim__uv_pipe_init l p (boolToInt32 ipc)
47 |
48 |   ||| Open an existing file descriptor or HANDLE as a pipe.
49 |   |||
50 |   ||| The passed file descriptor or HANDLE is not checked for its type,
51 |   ||| but it's required that it represents a valid pipe.
52 |   export %inline
53 |   uv_pipe_open : Ptr Pipe -> Int32 -> io Int32
54 |   uv_pipe_open p f = primIO $ prim__uv_pipe_open p f
55 |
56 |   ||| Bind the pipe to a file path (Unix) or a name (Windows).
57 |   |||
58 |   ||| Does not support Linux abstract namespace sockets, unlike uv_pipe_bind2().
59 |   |||
60 |   ||| Alias for uv_pipe_bind2(handle, name, strlen(name), 0).
61 |   |||
62 |   ||| NOTE:
63 |   |||    Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,
64 |   |||    typically between 92 and 108 bytes.
65 |   export %inline
66 |   uv_pipe_bind : Ptr Pipe -> String -> io Int32
67 |   uv_pipe_bind p f = primIO $ prim__uv_pipe_bind p f
68 |
69 |
70 |   ||| Connect to the Unix domain socket or the Windows named pipe.
71 |   |||
72 |   ||| Does not support Linux abstract namespace sockets, unlike uv_pipe_connect2().
73 |   |||
74 |   ||| Alias for uv_pipe_connect2(req, handle, name, strlen(name), 0, cb).
75 |   |||
76 |   ||| NOTE:
77 |   |||    Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,
78 |   |||    typically between 92 and 108 bytes.
79 |   export
80 |   uv_pipe_connect :
81 |        Ptr Pipe
82 |     -> String
83 |     -> (Ptr Connect -> Int32 -> IO ())
84 |     -> io ()
85 |   uv_pipe_connect pp name act = do
86 |     pc <- mallocPtr Connect
87 |     cb <- ptrIntCB (\x,y => act x y >> freeReq x)
88 |     uv_req_set_data pc cb
89 |     primIO $ prim__uv_pipe_connect pc pp name cb
90 |