Refactor syscall modules to use async/await patterns

- Updated `DisplaySyscall` to use `tokio::io::AsyncWriteExt` for asynchronous text output.
- Refactored `FsSyscall` to read files asynchronously with offset and length handling.
- Modified `MemorySyscall` to use `tokio::task::spawn_blocking` for database operations, allowing async access to SQLite.
- Enhanced `NetworkSyscall` to utilize `reqwest` for HTTP requests, replacing the previous `curl` command execution.
- Improved `ProcessSyscall` to manage subprocesses with async tasks for stdin, stdout, and stderr handling.
- Updated `TimerSyscall` to simplify timer management.
- Adjusted plugin implementations for better async support and error handling.
- Added `tokio-stream` and `tracing-subscriber` dependencies to `Cargo.toml` for enhanced async stream handling and logging.
This commit is contained in:
2026-06-10 01:26:46 +08:00
parent f7919eca40
commit d533d0a30e
21 changed files with 1950 additions and 436 deletions

View File

@@ -304,7 +304,7 @@ impl CheckRunner {
.into_inner();
let names: Vec<&str> = list.entries.iter().map(|e| e.name.as_str()).collect();
ensure!(
list.ok && names.iter().any(|name| *name == "sample.txt"),
list.ok && names.contains(&"sample.txt"),
"list mismatch ok={} names={:?} error={:?}",
list.ok,
names,
@@ -341,12 +341,13 @@ impl CheckRunner {
async fn process_roundtrip(&mut self) -> Result<String> {
let mut process = ProcessClient::new(self.channel.clone());
let (cmd, args) = process_command();
let resp = process
.spawn(request_with_plugin(
PLUGIN_ID,
SpawnRequest {
cmd: "cmd".to_string(),
args: vec!["/C".to_string(), format!("echo {PROCESS_OK}")],
cmd,
args,
env: HashMap::new(),
cwd: executable_dir()
.map(|path| path_string(&path))
@@ -504,6 +505,20 @@ fn executable_data_dir() -> PathBuf {
.join("data")
}
fn process_command() -> (String, Vec<String>) {
if cfg!(windows) {
(
"cmd".to_string(),
vec!["/C".to_string(), format!("echo {PROCESS_OK}")],
)
} else {
(
"sh".to_string(),
vec!["-c".to_string(), format!("printf %s {PROCESS_OK}")],
)
}
}
fn path_string(path: &std::path::Path) -> String {
path.to_string_lossy().to_string()
}