mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 10:08:20 +00:00

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.
46 lines
1 KiB
Rust
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(())
|
|
}
|
|
}
|