quininer / ritsu

An experimental asynchronous runtime based on `io-uring`.
MIT License
76 stars 4 forks source link

buffer management and API design #2

Open quininer opened 4 years ago

quininer commented 4 years ago

Designing an ergonomic API for proactor has always been a challenge.

I think that transferring ownership is the only way, whether the future holds ownership of buffer, or the scope holds ownership of buffer.

quininer commented 4 years ago

I tried the new AsyncRead/AsyncWrite API (from @carllerche). I think this is right way.

pub trait AsyncRead {
    fn poll_read(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Option<BytesMut>>>;
}

pub trait AsyncWrite {
    fn submit(&mut self, buf: Bytes) -> io::Result<()>;

    fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Bytes>>;
}

This API is designed to work with buffer allocator. but allocator's design is a challenge, it should be general enough, and can take advantage from buffer select.

quininer commented 4 years ago

I decided not to implement the AsyncRead/AsyncWrite trait in 0.1.