Skip to content

Commit

Permalink
Support wasm32-wasi target
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Zak <richard@profian.com>
  • Loading branch information
rjzak committed Jun 3, 2022
1 parent c6f39d6 commit 6312041
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -72,6 +72,7 @@ rustdoc-args = ["--cfg", "docsrs"]
targets = [
"aarch64-apple-ios",
"aarch64-linux-android",
"wasm32-wasi",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-dragonfly",
Expand Down
26 changes: 19 additions & 7 deletions src/poll.rs
Expand Up @@ -2,6 +2,7 @@ use crate::{event, sys, Events, Interest, Token};
use log::trace;
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::Arc;
use std::time::Duration;
use std::{fmt, io};

Expand Down Expand Up @@ -230,7 +231,7 @@ pub struct Poll {

/// Registers I/O resources.
pub struct Registry {
selector: sys::Selector,
selector: Arc<sys::Selector>,
}

impl Poll {
Expand Down Expand Up @@ -270,13 +271,12 @@ impl Poll {
/// ```
pub fn new() -> io::Result<Poll> {
sys::Selector::new().map(|selector| Poll {
registry: Registry { selector },
registry: Registry { selector: Arc::new(selector) },
})
}
}

/// Create a separate `Registry` which can be used to register
/// `event::Source`s.
/// Get access to the `Registry`, which can be used to register `event::Source`s.
pub fn registry(&self) -> &Registry {
&self.registry
}
Expand Down Expand Up @@ -637,9 +637,9 @@ impl Registry {
/// the original `Registry` and `Poll` instance.
#[cfg(not(target_os = "wasi"))]
pub fn try_clone(&self) -> io::Result<Registry> {
self.selector
.try_clone()
.map(|selector| Registry { selector })
self.selector.try_clone().map(|selector| Registry {
selector: Arc::new(selector),
})
}

/// Internal check to ensure only a single `Waker` is active per [`Poll`]
Expand All @@ -659,6 +659,18 @@ impl Registry {
}
}

impl Clone for Registry {
/// Creates a new independently owned `Registry`.
///
/// Event sources registered with this `Registry` will be registered with
/// the original `Registry` and `Poll` instance.
fn clone(&self) -> Self {
Registry {
selector: self.selector.clone(),
}
}
}

impl fmt::Debug for Registry {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Registry").finish()
Expand Down

0 comments on commit 6312041

Please sign in to comment.