Skip to content

Commit 7c700e3

Browse files
committed
Add FileDescriptorId type and update Runtime trait to use fd abstraction
1 parent fa3bb77 commit 7c700e3

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

java_runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod runtime;
77

88
pub use self::{
99
loader::{get_bootstrap_class_loader, get_runtime_class_proto},
10-
runtime::{File, FileSize, FileStat, FileType, IOError, IOResult, Runtime, SpawnCallback},
10+
runtime::{File, FileDescriptorId, FileSize, FileStat, FileType, IOError, IOResult, Runtime, SpawnCallback},
1111
};
1212

1313
pub type RuntimeContext = dyn runtime::Runtime;

java_runtime/src/runtime.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dyn_clone::{DynClone, clone_trait_object};
77

88
use jvm::{ClassDefinition, Jvm, Result as JvmResult};
99

10-
pub use io::{File, FileSize, FileStat, FileType, IOError, IOResult};
10+
pub use io::{File, FileDescriptorId, FileSize, FileStat, FileType, IOError, IOResult};
1111

1212
#[async_trait::async_trait]
1313
pub trait SpawnCallback: Sync + Send {
@@ -23,11 +23,13 @@ pub trait Runtime: Sync + Send + DynClone {
2323
fn now(&self) -> u64; // unix time in millis
2424
fn current_task_id(&self) -> u64;
2525

26-
fn stdin(&self) -> IOResult<Box<dyn File>>;
27-
fn stdout(&self) -> IOResult<Box<dyn File>>;
28-
fn stderr(&self) -> IOResult<Box<dyn File>>;
26+
fn stdin(&self) -> IOResult<FileDescriptorId>;
27+
fn stdout(&self) -> IOResult<FileDescriptorId>;
28+
fn stderr(&self) -> IOResult<FileDescriptorId>;
2929

30-
async fn open(&self, path: &str, write: bool) -> IOResult<Box<dyn File>>;
30+
async fn open(&self, path: &str, write: bool) -> IOResult<FileDescriptorId>;
31+
fn get_file(&self, fd: FileDescriptorId) -> IOResult<Box<dyn File>>;
32+
fn close_file(&self, fd: FileDescriptorId);
3133
async fn unlink(&self, path: &str) -> IOResult<()>;
3234
async fn metadata(&self, path: &str) -> IOResult<FileStat>;
3335

java_runtime/src/runtime/io.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ use alloc::boxed::Box;
22

33
use dyn_clone::{DynClone, clone_trait_object};
44

5+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6+
pub struct FileDescriptorId(u32);
7+
8+
impl FileDescriptorId {
9+
pub fn new(id: u32) -> Self {
10+
Self(id)
11+
}
12+
13+
pub fn id(&self) -> u32 {
14+
self.0
15+
}
16+
}
17+
518
#[derive(Debug)]
619
pub enum IOError {
720
Unsupported,

0 commit comments

Comments
 (0)