File: read_write.ml

package info (click to toggle)
ocaml-luv 0.5.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,504 kB
  • sloc: ml: 11,130; makefile: 6,223; sh: 4,592; ansic: 1,517; python: 38
file content (20 lines) | stat: -rw-r--r-- 701 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let () =
  Helpers.with_server_and_client ()
    ~server:begin fun server_pipe accept_pipe ->
      Luv.Stream.read_start accept_pipe begin fun result ->
        result |> ok "read_start" @@ fun b ->
        Printf.printf "%S\n" (Luv.Buffer.to_string b);
        Luv.Handle.close accept_pipe ignore;
        Luv.Handle.close server_pipe ignore
      end
    end
    ~client:begin fun client_pipe ->
      let b1 = Luv.Buffer.from_string "fo" in
      let b2 = Luv.Buffer.from_string "o" in

      Luv.Stream.write client_pipe [b1; b2] begin fun result count ->
        Luv.Handle.close client_pipe ignore;
        result |> ok "write" @@ fun () ->
        Printf.printf "%i\n" count
      end
    end