Skip to content

Attempt to work around Unix.socketpair issue on Win32 #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib/picos_io/picos_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,29 @@ module Unix = struct
Fd.create (Unix.socket ?cloexec socket_domain socket_type protocol)

(* https://pubs.opengroup.org/onlinepubs/9699919799/functions/socketpair.html *)
let socketpair ?cloexec socket_domain socket_type mystery =
let fst, snd = Unix.socketpair ?cloexec socket_domain socket_type mystery in
(Fd.create fst, Fd.create snd)
let socketpair =
if Sys.win32 then
(* This is a workaround for [Unix.socketpair] on Win32 to avoid CI
failures. We should be able to remove this once the root issue is
fixed. *)
let rec socketpair_win32 ?cloexec socket_domain socket_type mystery
retries =
match Unix.socketpair ?cloexec socket_domain socket_type mystery with
| sockets -> sockets
| exception Unix.Unix_error (EADDRINUSE, _, _) when 0 < retries ->
socketpair_win32 ?cloexec socket_domain socket_type mystery
(retries - 1)
in
fun ?cloexec socket_domain socket_type mystery ->
let fst, snd =
socketpair_win32 ?cloexec socket_domain socket_type mystery 5
in
(Fd.create fst, Fd.create snd)
else fun ?cloexec socket_domain socket_type mystery ->
let fst, snd =
Unix.socketpair ?cloexec socket_domain socket_type mystery
in
(Fd.create fst, Fd.create snd)

(* https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html *)
let accept ?cloexec fd =
Expand Down
Loading