File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 1
1
(tests
2
- (names basic domainworkers movingpromises)
2
+ (names basic domainworkers movingpromises unixpipe )
3
3
(libraries lwt lwt.unix))
Original file line number Diff line number Diff line change
1
+ open Lwt.Syntax
2
+
3
+ let checks = Atomic. make 0
4
+
5
+ let () = Lwt_unix. init_domain ()
6
+
7
+ let write w s =
8
+ let b = Bytes. unsafe_of_string s in
9
+ let * l = Lwt_unix. write w b 0 (Bytes. length b) in
10
+ assert (l = Bytes. length b);
11
+ Lwt. return_unit
12
+
13
+ let read r n =
14
+ let b = Bytes. create n in
15
+ let * l = Lwt_unix. read r b 0 n in
16
+ assert (l = n);
17
+ Lwt. return (Bytes. unsafe_to_string b)
18
+
19
+ let rec run data w r =
20
+ let * () = Lwt. pause () in
21
+ match data with
22
+ | [] -> Lwt. return_unit
23
+ | datum ::data ->
24
+ let * () = write w datum in
25
+ let * readed = read r (String. length datum) in
26
+ assert (datum = readed);
27
+ Atomic. incr checks;
28
+ run data w r
29
+
30
+ let run_in_domain data w r = Domain. spawn (fun () -> Lwt_main. run (run data w r))
31
+
32
+ let (a_from_b, b_to_a) = Lwt_unix. pipe ()
33
+ let (b_from_a, a_to_b) = Lwt_unix. pipe ()
34
+ let data = [ " aaa" ; " bbbb" ; " alhskjdflkhjasdflkhjhjklasfdlhjksadxf" ]
35
+
36
+ let a2b = run_in_domain data a_to_b a_from_b
37
+ let b2a = run_in_domain data b_to_a b_from_a
38
+
39
+ let () = Domain. join a2b
40
+ let () = Domain. join b2a
41
+ let () =
42
+ if Atomic. get checks = 2 * List. length data then begin
43
+ Printf. printf " unixpipe: ✓\n " ;
44
+ exit 0
45
+ end else begin
46
+ Printf. printf " unixpipe: ×\n " ;
47
+ exit 1
48
+ end
You can’t perform that action at this time.
0 commit comments