Sat 31 May 2025

🌸 Sane C++ May 25

SC

Welcome to the update post for May 2025!
This month a new object called AsyncSequence has been added to SC::Async together with a good list of smaller improvements!

DeepWiki

I've been feeding the Sane C++ Libraries repo to DeepWiki and I am actually surprised by how good it has understood the overall codebase structure! Some details are wrong and sometimes it analyzes details that are not really worth that much, but it's really amazing how much insight it provides at a glance to someone who is not aware of the internals of the project.

Make sure to check it out at:

https://deepwiki.com/Pagghiu/SaneCppLibraries

Async Sequence

AsyncSequence allows controlling requests execution order, and it's implemented as a simple linked list queue that can simplify some common use cases.

For example AsyncSequence can be used to issue an AsyncSocketConnect request and then a sequence of AsyncSocketSend or a AsyncSocketReceive immediately after. AsyncSequence avoids the need to start such additional requests in the callback of the previously finished requests.

This is a (not so small) extract of the test suite where AsyncSequence is being used to queue two writes so that they will happen in the correct order.

Async Cancellations

Lastly Async requests cancellation handling has been consolidated between all backends and it's more precise and consistent. Some async backends (Windows IOCP / Linux io_uring) post cancellations notification to the kernel queue. This is now properly handled by stepping the event loop one more time.

The remaining changes try to consistently track multiple edge cases when processing cancellations:

Honestly trying to unify these kind of behaviors between APIs that are so wildly different is really challenging!

Async Improvements

SC::Async has been receiving some additional fine tuning reducing the size of all AsyncRequest, removing some common fields like eventIndex and event loop pointer.

AsyncFileClose and AsyncSocketClose have finally seen their return code moved to completion data and AsyncSocketConnect will stop its watcher in case of errors.