-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpipe_echo_server.ml
More file actions
27 lines (23 loc) · 829 Bytes
/
pipe_echo_server.ml
File metadata and controls
27 lines (23 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let () =
let server = Luv.Pipe.init () |> Result.get_ok in
ignore (Luv.Pipe.bind server "echo-pipe");
Luv.Stream.listen server begin function
| Error e ->
Printf.eprintf "Listen error: %s\n" (Luv.Error.strerror e)
| Ok () ->
let client = Luv.Pipe.init () |> Result.get_ok in
match Luv.Stream.accept ~server ~client with
| Error _ ->
Luv.Handle.close client ignore
| Ok () ->
Luv.Stream.read_start client begin function
| Error `EOF ->
Luv.Handle.close client ignore
| Error e ->
Printf.eprintf "Read error: %s\n" (Luv.Error.strerror e);
Luv.Handle.close client ignore
| Ok buffer ->
Luv.Stream.write client [buffer] (fun _ -> ignore)
end
end;
ignore (Luv.Loop.run () : bool)