Skip to content

Support io_uring #4

Description

@TheAlgorythm

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();
      }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions