compio-rs / compio

A thread-per-core Rust runtime with IOCP/io_uring/polling.
MIT License
420 stars 37 forks source link

Refactor `compio-buf` #93

Closed Berrysoft closed 1 year ago

Berrysoft commented 1 year ago

This is a refactor for vectored buffers. With this PR, we can implement a default read_vectored like:

async fn read_vectored<T: IoVectoredBufMut>(&mut self, bufs: T) -> BufResult<usize, T> {
    let mut res = bufs.owned_iter();
    loop {
        match res {
            Err(bufs) => return BufResult(Ok(0), bufs),
            Ok(mut buf) => {
                if !buf.as_uninit_slice().is_empty() {
                    return self.read(buf).await.into_inner();
                } else {
                    res = buf.next()
                }
            }
        }
    }
}
Berrysoft commented 1 year ago

I'm a bit hesitate of the impl of OwnedBufIter, because it limits the users to implement a much efficient one themselves.

George-Miao commented 1 year ago

We do need to wait for RPITIT to stable before merging this PR is that correct?

Berrysoft commented 1 year ago

I'm afraid so. I hope RPITIT will become stable, but if there's sth. changes and the stablize PR is closed, I think we should find some other ways to implement it.

George-Miao commented 1 year ago

@Berrysoft I think we also need a owned_iter_mut returning Result<OwnedBufIterator<impl OwnedBufIteratorInnerMut<Inner = Self>>, Self> in IoVectoredBuf

George-Miao commented 1 year ago

Also can we rename OwnedBufIteratorInner to something like OwnedIterator and OwnedBufIterator can be renamed as BufIter. Current naming is too tedious.

George-Miao commented 1 year ago

Closing. #71 has rebased onto this PR and will keep working on it.