lean4-htt/src/runtime
Henrik Böving 406bda8807
feat: implement a Selector for async TCP (#8078)
This PR is a follow up to #8055 and implements a `Selector` for async
TCP in order to allow IO multiplexing using TCP sockets.

As we must not commit to actually fetching data from the socket buffer
this cannot be implemented by just racing on `recv?`. Instead we perform
a call to `uv_read_start` and pass an `alloc_cb` that allocates no
memory at all. According to the docs of
[`uv_alloc_cb`](https://docs.libuv.org/en/v1.x/handle.html#c.uv_alloc_cb)
this is guaranteed to give us a `UV_ENOBUFS` in the relevant callback.
Thus we can first run this "zero read" and then go into one of three
cases:
1. We get cancelled before the zero read completes, in this case just
cancel the zero read and give up.
2. The zero read completes and we loose the race for completing the
`select`, in this case just don't do anything anymore
3. The zero read completes and we win the race for completing the
`select`, in this case we perform the actual read on the socket. As we
know that data is available already (since the read callback of the zero
read is only triggered if data actually is available) we know that the
subsequent actual read should complete right away.

In this way we avoid any data loss if we loose the race.
2025-04-24 16:05:35 +00:00
..
uv feat: implement a Selector for async TCP (#8078) 2025-04-24 16:05:35 +00:00
alloc.cpp fix: heartbeats from realizeConst should be ignored (#7473) 2025-03-13 15:10:29 +00:00
alloc.h fix: heartbeats from realizeConst should be ignored (#7473) 2025-03-13 15:10:29 +00:00
allocprof.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
allocprof.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
apply.cpp chore: update script/apply.lean semantics 2022-11-07 19:47:04 -08:00
apply.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
array_ref.h perf: fix implementation of move constructors and move assignment ope… (#4700) 2024-08-02 17:55:03 +00:00
buffer.h chore: re-land "perf: use C23's free_sized when available" (#6844) 2025-02-04 12:43:56 +00:00
CMakeLists.txt chore: avoid mimalloc warnings (#7800) 2025-04-03 13:52:16 +00:00
compact.cpp feat: enable experimental module system in Init (#8047) 2025-04-23 17:21:33 +00:00
compact.h perf: use mimalloc in compactor hashmaps (#7929) 2025-04-14 09:11:34 +00:00
debug.cpp feat: reimplement assert without system headers 2021-11-18 09:42:35 +01:00
debug.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
exception.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
exception.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
flet.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
hash.cpp chore: replace all hashes by murmurhash 2022-12-01 20:18:14 -08:00
hash.h feat: define Int8 (#5790) 2024-10-25 06:06:40 +00:00
init_module.cpp feat: implement basic async IO with timers (#6505) 2025-01-13 18:11:04 +00:00
init_module.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
int.h feat: define ISize and basic operations on it (#5961) 2024-11-05 15:08:19 +00:00
interrupt.cpp fix: Windows build (#4628) 2024-07-02 20:32:00 +00:00
interrupt.h fix: Windows build (#4628) 2024-07-02 20:32:00 +00:00
io.cpp chore: fix spelling mistakes (#7328) 2025-04-07 01:15:48 +00:00
io.h feat: use libuv for tempfiles (#5135) 2024-10-14 13:56:56 +00:00
libuv.cpp feat: UDP socket support using LibUV (#7574) 2025-03-26 15:04:25 +00:00
libuv.h feat: UDP socket support using LibUV (#7574) 2025-03-26 15:04:25 +00:00
list_ref.h perf: fix implementation of move constructors and move assignment ope… (#4700) 2024-08-02 17:55:03 +00:00
memory.cpp chore: put throws in separate function for debugger 2023-01-23 09:27:09 -08:00
memory.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
mpn.cpp feat: add mpn module 2021-10-25 15:57:19 -07:00
mpn.h feat: add mpn module 2021-10-25 15:57:19 -07:00
mpz.cpp perf: use mimalloc for all Lean allocations (#7736) 2025-03-30 23:00:17 +00:00
mpz.h feat: add Int16/Int32/Int64 (#5885) 2024-11-04 13:18:05 +00:00
mutex.cpp feat: add Std.SharedMutex (#7770) 2025-04-03 08:30:54 +00:00
mutex.h feat: Mutex, Condvar 2022-09-05 08:52:46 -07:00
object.cpp fix: race condition in IO.getTaskState (#7945) 2025-04-14 14:08:36 +00:00
object.h feat: socket support using LibUV (#6683) 2025-03-19 13:54:51 +00:00
object_ref.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
object_ref.h perf: add lean_instantiate_level_mvars (#4910) 2024-08-04 18:31:44 +00:00
option_ref.h perf: add lean_instantiate_level_mvars (#4910) 2024-08-04 18:31:44 +00:00
optional.h perf: fix implementation of move constructors and move assignment ope… (#4700) 2024-08-02 17:55:03 +00:00
pair_ref.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
platform.cpp feat: add internal flag lean_has_llvm_backend 2023-11-02 23:21:47 +01:00
platform.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
process.cpp feat: IO.Process.SpawnArgs.inheritEnv (#6081) 2025-04-16 00:25:32 +00:00
process.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
sharecommon.cpp feat: support mpz in the shareCommon APIs (#7838) 2025-04-06 19:52:50 +00:00
sharecommon.h perf: use mimalloc with important C++ hash maps (#7868) 2025-04-11 16:23:33 +00:00
sstream.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
stack_overflow.cpp fix: Do not overwrite existing signal handlers (#5062) 2024-08-19 09:11:38 +00:00
stack_overflow.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
stackinfo.cpp fix: make the stack handling more robust to sanitizers and -O3 (#6143) 2024-11-22 15:10:20 +00:00
stackinfo.h fix: split libInit_shared out of libleanshared (#3421) 2024-02-22 19:16:32 +00:00
string_ref.h perf: fix implementation of move constructors and move assignment ope… (#4700) 2024-08-02 17:55:03 +00:00
thread.cpp chore: missing include on Windows (#4919) 2024-08-05 15:50:43 +00:00
thread.h feat: add Std.SharedMutex (#7770) 2025-04-03 08:30:54 +00:00
utf8.cpp fix: validate UTF-8 at C++ -> Lean boundary (#3963) 2024-06-19 14:05:48 +00:00
utf8.h fix: validate UTF-8 at C++ -> Lean boundary (#3963) 2024-06-19 14:05:48 +00:00