ritsu icon indicating copy to clipboard operation
ritsu copied to clipboard

buffer management and API design

Open quininer opened this issue 5 years ago • 2 comments

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 avatar Jan 08 '20 10:01 quininer

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 avatar Apr 05 '20 15:04 quininer

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

quininer avatar Apr 28 '20 06:04 quininer