limbo/core/io/windows.rs
Pekka Enberg 84a5115d77 core: Add Windows I/O module
It's a copy of the synchronous I/O module that we use on Darwin. In the
future, let's switch to Windows IOCP API.
2024-03-03 11:34:53 +02:00

46 lines
1 KiB
Rust

use super::{Completion, File, IO};
use anyhow::{Ok, Result};
use std::sync::Arc;
use std::cell::RefCell;
use std::io::{Read, Seek};
use log::trace;
pub struct WindowsIO {}
impl WindowsIO {
pub fn new() -> Result<Self> {
Ok(Self {})
}
}
impl IO for WindowsIO {
fn open_file(&self, path: &str) -> Result<Box<dyn File>> {
trace!("open_file(path = {})", path);
let file = std::fs::File::open(path)?;
Ok(Box::new(WindowsFile {
file: RefCell::new(file),
}))
}
fn run_once(&self) -> Result<()> {
Ok(())
}
}
pub struct WindowsFile {
file: RefCell<std::fs::File>,
}
impl File for WindowsFile {
fn pread(&self, pos: usize, c: Arc<Completion>) -> Result<()> {
let mut file = self.file.borrow_mut();
file.seek(std::io::SeekFrom::Start(pos as u64))?;
{
let mut buf = c.buf_mut();
let buf = buf.as_mut_slice();
file.read_exact(buf)?;
}
c.complete();
Ok(())
}
}