Skip to content
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

A sans-io API for ninep #97

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open

A sans-io API for ninep #97

wants to merge 9 commits into from

Conversation

sminez
Copy link
Owner

@sminez sminez commented Feb 25, 2025

An example of the read state machine side of this in action can be run in this playground link (also available here as a gist under my account).

The core idea is to abuse make use of the fact that Rust's async/await syntax desugars into a state machine that implements Future to instead implement the simple state machines required for a sans I/O API. To achieve this I'm stashing some shared state in the Waker used by I/O loop implementations that NineP impls can access using a request_bytes macro. Under the hood this macro is just awaiting a custom future that pulls the waker out of its poll context and stashes the requested number of bytes before returning Poll::Pending. In the I/O loop this value is read, I/O is performed and then the requested data is stored back in the shared state before polling again. When the RequestBytes future is polled again it takes the bytes out of the shared state and returns it as its result to the NineP::read impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant