Eio
Thomas Gazagnaire reported that Eio sometimes fails to respond to Unix signals. This was actually a known problem in OCaml, which I reported in 2024 (and was apparently already known before that):
- Signal handler doesn't run if signal received at the wrong time #13189
Thomas made a PR that fixed the immediate problem for SIGCHLD on eio_posix,
which I generalised to work for all signals and also on eio_linux:
- Add
Eio_unix.set_signal#956.
It does mean that you have to remember to call Eio_unix.set_signal rather than Sys.set_signal
though, so I hope this can be fixed upstream one day.
A nice blog post on sandboxing mentioned
that you should ideally use MSG_DONTWAIT with sockets received from another process,
because the other process might change whether it is blocking or not.
This doesn't matter for eio_linux, where everything is asynchronous anyway, but it sounded
like a good idea for eio_posix.
eio_posix used the same code to handle sockets and regular files, but I needed to implement
read as recvmsg for sockets (only), so the first step was to split that up:
- Split up file and socket flows #950.
Then I could change the sockets code to be non-blocking in all cases:
- eio_posix: use
MSG_DONTWAITfor sockets #951.
That failed on macos, which it turns out doesn't support MSG_DONTWAIT for sending, so I needed
to disable the test for that, which required detecting macos, which Sys.os_type can't do.
So I added support for that, using uname:
- Add
Eio_unix.System_info#952.
Anil then extended it to work on Windows too.
While splitting files and sockets, I needed to share eio_posix's implementation of copy
between them. Normally, a copy reads from the source into a buffer and then writes the buffer to
the sink, but if a source already has the data in a buffer internally then it's more efficient
to use that directly. There's nothing specific to eio_posix about this logic, so I moved
it into the default fallback copy simple_copy:
- Use
Read_source_bufferoptimisation inFlow.Pi.simple_copy#954.
However, that led to the question of how to test it. Eio_mock has a mock flow that can be
configured to test copying, but I wanted to test the real code, not the mock.
That led to creating two new wrappers (Eio_mock.Flow.limit_reads to control how much can
be read at once, and Eio_mock.Flow.trace_reads to report on what's happening), which
allow testing a real flow rather than just the mock.
Trying to run dune utop I hit the Dune links against wrong cstubs in byte mode bug again,
and trying to work around that I noticed that some of the file tests fail when
run in the opam sandbox (which blocks all chown operations, even if they
don't actually change the owner):
- Skip
chowntests if opam sandbox blocks them #955.
One of the Windows PRs needed to make 5.4 the minimum OCaml version for eio_windows,
and I took the opportunity to make it the default everywhere:
- Bump minimum OCaml version to 5.4 and identify thread pool #949.
I continued reviewing and merging various other PRs: