Skip to content

Commit ef6e1ca

Browse files
authored
Merge pull request #552 from marmistrz/poll
Minimal viable implementation of poll_oneoff for Windows
2 parents e5af0ae + 13afbd0 commit ef6e1ca

File tree

5 files changed

+316
-14
lines changed

5 files changed

+316
-14
lines changed

crates/test-programs/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ mod wasi_tests {
176176
"dangling_symlink" => true,
177177
"symlink_loop" => true,
178178
"truncation_rights" => true,
179-
"poll_oneoff" => true,
180179
"path_link" => true,
181180
"dangling_fd" => true,
182181
_ => false,

crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ unsafe fn test_timeout() {
4545
}];
4646
let out = poll_oneoff_impl(&r#in, 1);
4747
let event = &out[0];
48-
assert_eq!(
49-
event.userdata, CLOCK_ID,
50-
"the event.userdata should contain clock_id specified by the user"
51-
);
5248
assert_eq!(
5349
event.error,
5450
wasi::ERRNO_SUCCESS,
@@ -59,6 +55,10 @@ unsafe fn test_timeout() {
5955
wasi::EVENTTYPE_CLOCK,
6056
"the event.type should equal clock"
6157
);
58+
assert_eq!(
59+
event.userdata, CLOCK_ID,
60+
"the event.userdata should contain clock_id specified by the user"
61+
);
6262
}
6363

6464
unsafe fn test_stdin_read() {
@@ -77,6 +77,7 @@ unsafe fn test_stdin_read() {
7777
r#type: wasi::EVENTTYPE_CLOCK,
7878
u: wasi::SubscriptionU { clock },
7979
},
80+
// Make sure that timeout is returned only once even if there are multiple read events
8081
wasi::Subscription {
8182
userdata: 1,
8283
r#type: wasi::EVENTTYPE_FD_READ,
@@ -85,10 +86,6 @@ unsafe fn test_stdin_read() {
8586
];
8687
let out = poll_oneoff_impl(&r#in, 1);
8788
let event = &out[0];
88-
assert_eq!(
89-
event.userdata, CLOCK_ID,
90-
"the event.userdata should contain clock_id specified by the user"
91-
);
9289
assert_eq!(
9390
event.error,
9491
wasi::ERRNO_SUCCESS,
@@ -99,6 +96,10 @@ unsafe fn test_stdin_read() {
9996
wasi::EVENTTYPE_CLOCK,
10097
"the event.type should equal clock"
10198
);
99+
assert_eq!(
100+
event.userdata, CLOCK_ID,
101+
"the event.userdata should contain clock_id specified by the user"
102+
);
102103
}
103104

104105
unsafe fn test_stdout_stderr_write() {

crates/wasi-common/src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,18 @@ impl Error {
245245
pub(crate) trait FromRawOsError {
246246
fn from_raw_os_error(code: i32) -> Self;
247247
}
248+
249+
pub(crate) type Result<T> = std::result::Result<T, Error>;
250+
251+
pub(crate) trait AsWasiError {
252+
fn as_wasi_error(&self) -> WasiError;
253+
}
254+
255+
impl<T> AsWasiError for Result<T> {
256+
fn as_wasi_error(&self) -> WasiError {
257+
self.as_ref()
258+
.err()
259+
.unwrap_or(&Error::ESUCCESS)
260+
.as_wasi_error()
261+
}
262+
}

crates/wasi-common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ pub mod hostcalls {
4242
pub use ctx::{WasiCtx, WasiCtxBuilder};
4343
pub use sys::preopen_dir;
4444

45-
pub type Error = error::Error;
46-
pub(crate) type Result<T> = std::result::Result<T, Error>;
45+
pub use error::Error;
46+
pub(crate) use error::Result;

0 commit comments

Comments
 (0)