18 Commits

Author SHA1 Message Date
Thomas Leonard
e189fc4004 Merge fibreslib into eio
It was a bit confusing having two different API libraries. Instead of
opening `Fibreslib`, it is now suggested to open `Eio.Std`, which
exports fewer things.
2021-06-09 09:50:44 +01:00
Thomas Leonard
68706ce68e Allow cancelling await_readable and await_writable 2021-06-08 15:44:07 +01:00
Thomas Leonard
7f7832a4c9 Allow cancelling connect 2021-06-08 15:32:11 +01:00
Thomas Leonard
2341c788a3 Allow cancelling accept, read and write operations 2021-06-08 15:03:14 +01:00
Thomas Leonard
d1f3fb0757 Update to new uring API 2021-06-07 12:59:31 +01:00
Thomas Leonard
6b840376c2 Performance improvements
Process completed events using `Uring.peek` before submitting.
Otherwise, we call submit once for every operation, defeating the
purpose of uring.

Also, slightly optimise `Eunix.free`.

Using `wrk -c 1000 -d 5s`, this increases performance from 277.30MB/s to
414.12MB/s.
2021-06-03 09:47:37 +01:00
Thomas Leonard
dc8e85e761 Use uring for accept 2021-06-02 15:25:52 +01:00
Thomas Leonard
301fc215ff Add Switch.on_release to auto-close FDs
This allows attaching resources, such as file descriptors, to switches.
When the switch is finished, you can be sure the resources have been
freed.

This also fixes some FD leaks in the tests and README that this uncovered.
2021-06-01 09:48:05 +01:00
Thomas Leonard
165fd43ebc Allow getting Eunix FD from Eio flows 2021-05-28 11:53:23 +01:00
Thomas Leonard
12ea0b3b7b Add shutdown, allow closing listening sockets, add cstruct_source 2021-05-28 11:45:41 +01:00
Thomas Leonard
97606e8132 Add network API to Eio 2021-05-27 10:19:00 +01:00
Thomas Leonard
a9d6e5b837 Track whether FDs are seekable or not
`io_uring`'s rules seem to be:
- For files, we must pass -1 to use the current offset
- For pipes, we can pass either -1 or 0
- For sockets, we must pass 0
2021-05-26 11:31:14 +01:00
Thomas Leonard
33a5318b72 Add Eio.Flow API
This allows other combinations, such as bidirectional flows and closable
flows.
2021-05-26 11:02:51 +01:00
Thomas Leonard
72440f5df5 Provide more specific types in stdenv
If a program uses Eunix directly, allow it to see the full types.
2021-05-25 11:14:29 +01:00
Thomas Leonard
a067efb56f Handle multiple exceptions in switches
If multiple threads fail, report all the exceptions. OCaml doesn't
provide a way to add context exceptions, so we have to introduce a new
exception type for this.

Also, `Switch.check` now wraps the exception in `Cancelled`. This allows
a thread to distinguish e.g. an `End_of_file` in its own operations
from being cancelled due to another thread hitting `End_of_file`.

Finally, `Fibre.fork_ignore ~sw` now copes with `sw` being off at the
start. It continues execution in the main thread, but does not run the
child. This is similar to the behaviour when `sw` is turned off
immediately after forking.
2021-05-25 10:17:24 +01:00
Thomas Leonard
bda673cfe8 Use splice to copy if possible 2021-05-24 17:29:00 +01:00
Thomas Leonard
9545060824 Detect deadlocks
Previously, the scheduler returned whenever there were no pending
events. This could be because the main function had finished, but it
could also happen if the system was deadlocked.

Now, the scheduler raises an exception if it finishes while the main
thread is still running, which should make the problem clearer.
2021-05-14 13:40:57 +01:00
Thomas Leonard
4df62a5a78 Rename lib_eioio to lib_eunix
This now matches the name in the dune file.
2021-05-14 13:11:33 +01:00