1 Commits

Author SHA1 Message Date
Cutieguwu
71675d0771 Update io.rs 2026-01-01 14:40:51 -05:00

View File

@@ -1,7 +1,6 @@
use std::ffi::CString;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{self, Seek, SeekFrom}; use std::io::{self, Seek, SeekFrom};
use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd}; use std::os::unix::fs::OpenOptionsExt;
use crate::cli::CONFIG; use crate::cli::CONFIG;
@@ -24,19 +23,30 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
/* /*
* IO Error Poisoning: * IO Error Poisoning:
* *
* Attempt 2:
* *
* Attempt 1: * Return to using safe-on-the-surface Rust, but attempt to execute the reads
* via a separate thread, hoping that the observed poisoning goes away with the
* thread being closed and doesn't affect the main thread.
* *
* Wrap C calls w/ `ffi`. Most importantly, execute the `close()` through C. * May need `mpsc` to transfer data without spawning a thread on every read.
*
* I cannot seem to execute `close()`... one hopes that reassigning will drop
* calling `close()` on the old fd, but I don't know.
*/ */
pub fn load_input() -> anyhow::Result<File> { pub fn load_input() -> anyhow::Result<File> {
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned())?; OpenOptions::new()
let flags = libc::O_RDONLY | libc::O_DIRECT; .read(true)
Ok(unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) }) .custom_flags(libc::O_DIRECT)
.open(&CONFIG.input)
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display()))
/*
use std::ffi::CString;
use std::os::fd::FromRawFd;
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned()).unwrap();
let flags = libc::O_DIRECT | libc::O_RDONLY;
let f = unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) };
*/
} }
pub fn load_output() -> anyhow::Result<File> { pub fn load_output() -> anyhow::Result<File> {