|
| 1 | +(* Isolate the AF_UNIX bind EOPNOTSUPP on Windows: test each step conduit does. *) |
| 2 | +let attempt name f = |
| 3 | + match f () with |
| 4 | + | () -> Printf.printf " %-42s OK\n%!" name |
| 5 | + | exception Unix.Unix_error (e, fn, _) -> |
| 6 | + Printf.printf " %-42s FAIL %s (in %s)\n%!" name (Unix.error_message e) fn |
| 7 | + | exception e -> Printf.printf " %-42s FAIL %s\n%!" name (Printexc.to_string e) |
| 8 | + |
| 9 | +let fresh p = (try Sys.remove p with _ -> ()); p |
| 10 | +let mk () = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 |
| 11 | +let prot fd f = Fun.protect ~finally:(fun () -> try Unix.close fd with _ -> ()) f |
| 12 | + |
| 13 | +let () = |
| 14 | + Printf.printf "AF_UNIX diag: win32=%b ocaml=%s\n%!" Sys.win32 Sys.ocaml_version; |
| 15 | + attempt "socket PF_UNIX SOCK_STREAM" (fun () -> Unix.close (mk ())); |
| 16 | + attempt "bind rel (no setsockopt)" (fun () -> |
| 17 | + let fd = mk () in prot fd (fun () -> |
| 18 | + Unix.bind fd (Unix.ADDR_UNIX (fresh "d_rel.sock")))); |
| 19 | + attempt "setsockopt SO_REUSEADDR" (fun () -> |
| 20 | + let fd = mk () in prot fd (fun () -> Unix.setsockopt fd Unix.SO_REUSEADDR true)); |
| 21 | + attempt "bind AFTER SO_REUSEADDR (conduit seq)" (fun () -> |
| 22 | + let fd = mk () in prot fd (fun () -> |
| 23 | + Unix.setsockopt fd Unix.SO_REUSEADDR true; |
| 24 | + Unix.bind fd (Unix.ADDR_UNIX (fresh "d_reuse.sock")))); |
| 25 | + attempt "bind abs path" (fun () -> |
| 26 | + let fd = mk () in prot fd (fun () -> |
| 27 | + Unix.bind fd (Unix.ADDR_UNIX (fresh (Filename.concat (Sys.getcwd ()) "d_abs.sock"))))); |
| 28 | + attempt "bind + listen rel" (fun () -> |
| 29 | + let fd = mk () in prot fd (fun () -> |
| 30 | + Unix.bind fd (Unix.ADDR_UNIX (fresh "d_lst.sock")); |
| 31 | + Unix.listen fd 5)) |
0 commit comments