Skip to content

Commit 55e51a5

Browse files
youknowoneJohnTitor
authored andcommitted
Add wasi select, FD_SET, FD_ZERO, FD_ISSET
1 parent 42446e9 commit 55e51a5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/wasi.rs

+35
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ s! {
175175
pub st_ctim: timespec,
176176
__reserved: [c_longlong; 3],
177177
}
178+
179+
pub struct fd_set {
180+
__nfds: usize,
181+
__fds: [c_int; FD_SETSIZE],
182+
}
178183
}
179184

180185
// Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash,
@@ -438,6 +443,28 @@ pub const NOEXPR: ::nl_item = 0x50001;
438443
pub const YESSTR: ::nl_item = 0x50002;
439444
pub const NOSTR: ::nl_item = 0x50003;
440445

446+
f! {
447+
pub fn FD_ISSET(fd: ::c_int, set: *const fd_set) -> bool {
448+
let set = &*set;
449+
let n = set.__nfds;
450+
return set.__fds[..n].iter().any(|p| *p == fd)
451+
}
452+
453+
pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
454+
let set = &mut *set;
455+
let n = set.__nfds;
456+
if !set.__fds[..n].iter().any(|p| *p == fd) {
457+
set.__nfds = n + 1;
458+
set.__fds[n] = fd;
459+
}
460+
}
461+
462+
pub fn FD_ZERO(set: *mut fd_set) -> () {
463+
(*set).__nfds = 0;
464+
return
465+
}
466+
}
467+
441468
#[cfg_attr(
442469
feature = "rustc-dep-of-std",
443470
link(
@@ -733,6 +760,14 @@ extern "C" {
733760
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
734761
pub fn nl_langinfo_l(item: ::nl_item, loc: ::locale_t) -> *mut ::c_char;
735762

763+
pub fn select(
764+
nfds: c_int,
765+
readfds: *mut fd_set,
766+
writefds: *mut fd_set,
767+
errorfds: *mut fd_set,
768+
timeout: *const timeval,
769+
) -> c_int;
770+
736771
pub fn __wasilibc_register_preopened_fd(fd: c_int, path: *const c_char) -> c_int;
737772
pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int;
738773
pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int;

0 commit comments

Comments
 (0)