Skip to content

Commit

Permalink
Port to the new polling
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Jul 11, 2023
1 parent eb98b47 commit 56549d7
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 163 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ socket2 = { version = "0.5.3", features = ["all"] }
tracing = { version = "0.1.37", default-features = false }
waker-fn = "1.1.0"

[build-dependencies]
autocfg = "1"

[dev-dependencies]
async-channel = "1"
async-net = "1"
Expand All @@ -54,3 +51,7 @@ timerfd = "1"

[target.'cfg(windows)'.dev-dependencies]
uds_windows = "1"

[patch.crates-io]
polling = { git = "https://github.com/smol-rs/polling.git", branch = "notgull/unsafe2" }
async-io = { path = "." }
16 changes: 0 additions & 16 deletions build.rs

This file was deleted.

14 changes: 9 additions & 5 deletions examples/linux-inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ fn main() -> std::io::Result<()> {
future::block_on(async {
// Watch events in the current directory.
let mut inotify = Async::new(Inotify::init()?)?;
inotify
.get_mut()
.watches()
.add(".", WatchMask::ALL_EVENTS)?;

// SAFETY: We do not move the inner file descriptor out.
unsafe {
inotify
.get_mut()
.watches()
.add(".", WatchMask::ALL_EVENTS)?;
}
println!("Watching for filesystem events in the current directory...");
println!("Try opening a file to trigger some events.");
println!();

// Wait for events in a loop and print them on the screen.
loop {
for event in inotify.read_with_mut(read_op).await? {
for event in unsafe { inotify.read_with_mut(read_op).await? } {
println!("{:?}", event);
}
}
Expand Down
50 changes: 1 addition & 49 deletions examples/windows-uds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,6 @@
//! cargo run --example windows-uds
//! ```
#[cfg(windows)]
fn main() -> std::io::Result<()> {
use std::path::PathBuf;

use async_io::Async;
use blocking::Unblock;
use futures_lite::{future, io, prelude::*};
use tempfile::tempdir;
use uds_windows::{UnixListener, UnixStream};

async fn client(addr: PathBuf) -> io::Result<()> {
// Connect to the address.
let stream = Async::new(UnixStream::connect(addr)?)?;
println!("Connected to {:?}", stream.get_ref().peer_addr()?);

// Pipe the stream to stdout.
let mut stdout = Unblock::new(std::io::stdout());
io::copy(&stream, &mut stdout).await?;
Ok(())
}

let dir = tempdir()?;
let path = dir.path().join("socket");

future::block_on(async {
// Create a listener.
let listener = Async::new(UnixListener::bind(&path)?)?;
println!("Listening on {:?}", listener.get_ref().local_addr()?);

future::try_zip(
async {
// Accept the client.
let (stream, _) = listener.read_with(|l| l.accept()).await?;
println!("Accepted a client");

// Send a message, drop the stream, and wait for the client.
Async::new(stream)?.write_all(b"Hello!\n").await?;
Ok(())
},
client(path),
)
.await?;

Ok(())
})
}

#[cfg(not(windows))]
fn main() {
println!("This example works only on Windows!");
println!("TODO: Restore this example from git once uds_windows implements I/O safety");
}
Loading

0 comments on commit 56549d7

Please sign in to comment.