Skip to content

Commit 167b7c3

Browse files
committed
DIAGNOSTIC: isolate AF_UNIX bind EOPNOTSUPP on Windows (throwaway)
1 parent e3363f7 commit 167b7c3

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
- afunix-diag
78
pull_request:
89
schedule:
910
# Prime the caches every Monday
@@ -53,6 +54,10 @@ jobs:
5354

5455
- run: opam exec -- make all
5556

57+
- name: AF_UNIX diagnostic
58+
if: always() && matrix.os == 'windows-latest'
59+
run: opam exec -- dune exec afunix_diag/afunix_diag.exe
60+
5661
- name: Run the test suite
5762
timeout-minutes: 5
5863
run: opam exec -- dune runtest

afunix_diag/afunix_diag.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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))

afunix_diag/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(executable
2+
(name afunix_diag)
3+
(libraries unix))

afunix_diag/dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 3.18)

0 commit comments

Comments
 (0)