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

Support io_uring #4

Open
TheAlgorythm opened this issue Apr 3, 2022 · 0 comments
Open

Support io_uring #4

TheAlgorythm opened this issue Apr 3, 2022 · 0 comments

Comments

@TheAlgorythm
Copy link
Owner

TheAlgorythm commented Apr 3, 2022

It should be a separate GPL workspace member.
Rio can be used.

struct IoUring<S: AsRawFd> {
  ring: &Rio,
  sink: S,
  completion: Option<Completion>,
  current_buffer: Vec<u8>,
  completion_buffer: Vec<u8>,
}

impl<S: AsRawFd> Write for IoUring<S> {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
    let new_len = self.current_buffer.len() + buf.len();
    if self.current_buffer.capacity() < new_len {
        if let Some(completion) = self.completion.take() {
          completion.wait()?;
        }
        swap(self.current_buffer, self.completion_buffer);
        self.completion = Some(ring.write_at(&self.sink, &self.completion_buffer, at));
        self.current_buffer.clear();
    }
    self.current_buffer.extend_from_slice(buf);
    // maybe flush if full
    }

    fn flush(&mut self) -> io::Result<()> {
      if let Some(completion) = self.completion.take() {
        completion.wait()?;
        self.completion_buffer.clear();
      }
      if !self.current_buffer.is_empty() {
        ring.write_at(&self.sink, & self.current_buffer, at).wait()?;
        self.current_buffer.clear();
      }
    }
}
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

No branches or pull requests

1 participant